further phase 1
This commit is contained in:
@@ -30,6 +30,42 @@ bool MatchesControlKey(const std::string& candidate, const std::string& key)
|
||||
{
|
||||
return candidate == key || SimplifyControlKey(candidate) == SimplifyControlKey(key);
|
||||
}
|
||||
|
||||
bool TextureAssetsEqual(const std::vector<ShaderTextureAsset>& left, const std::vector<ShaderTextureAsset>& right)
|
||||
{
|
||||
if (left.size() != right.size())
|
||||
return false;
|
||||
|
||||
for (std::size_t index = 0; index < left.size(); ++index)
|
||||
{
|
||||
if (left[index].id != right[index].id ||
|
||||
left[index].path != right[index].path ||
|
||||
left[index].writeTime != right[index].writeTime)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontAssetsEqual(const std::vector<ShaderFontAsset>& left, const std::vector<ShaderFontAsset>& right)
|
||||
{
|
||||
if (left.size() != right.size())
|
||||
return false;
|
||||
|
||||
for (std::size_t index = 0; index < left.size(); ++index)
|
||||
{
|
||||
if (left[index].id != right[index].id ||
|
||||
left[index].path != right[index].path ||
|
||||
left[index].writeTime != right[index].writeTime)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeStore::RuntimeStore(RuntimeHost& runtimeHost) :
|
||||
@@ -94,6 +130,107 @@ std::string RuntimeStore::BuildPersistentStateJson() const
|
||||
return SerializeJson(BuildRuntimeStateValue(), true);
|
||||
}
|
||||
|
||||
bool RuntimeStore::PollStoredFileChanges(bool& registryChanged, bool& reloadRequested, std::string& error)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
registryChanged = false;
|
||||
reloadRequested = false;
|
||||
|
||||
if (!mRuntimeHost.mAutoReloadEnabled)
|
||||
{
|
||||
reloadRequested = mRuntimeHost.mReloadRequested;
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (mRuntimeHost.mLastScanTime != std::chrono::steady_clock::time_point::min() &&
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - mRuntimeHost.mLastScanTime).count() < 250)
|
||||
{
|
||||
reloadRequested = mRuntimeHost.mReloadRequested;
|
||||
return true;
|
||||
}
|
||||
|
||||
mRuntimeHost.mLastScanTime = now;
|
||||
|
||||
std::string scanError;
|
||||
std::map<std::string, ShaderPackage> previousPackages = mRuntimeHost.mPackagesById;
|
||||
std::vector<std::string> previousOrder = mRuntimeHost.mPackageOrder;
|
||||
std::map<std::string, std::pair<std::filesystem::file_time_type, std::filesystem::file_time_type>> previousLayerShaderTimes;
|
||||
for (const RuntimeHost::LayerPersistentState& layer : mRuntimeHost.mPersistentState.layers)
|
||||
{
|
||||
auto previous = previousPackages.find(layer.shaderId);
|
||||
if (previous != previousPackages.end())
|
||||
previousLayerShaderTimes[layer.id] = std::make_pair(previous->second.shaderWriteTime, previous->second.manifestWriteTime);
|
||||
}
|
||||
|
||||
if (!mRuntimeHost.ScanShaderPackages(scanError))
|
||||
{
|
||||
error = scanError;
|
||||
return false;
|
||||
}
|
||||
|
||||
registryChanged = previousOrder != mRuntimeHost.mPackageOrder;
|
||||
if (!registryChanged && previousPackages.size() == mRuntimeHost.mPackagesById.size())
|
||||
{
|
||||
for (const auto& item : mRuntimeHost.mPackagesById)
|
||||
{
|
||||
auto previous = previousPackages.find(item.first);
|
||||
if (previous == previousPackages.end())
|
||||
{
|
||||
registryChanged = true;
|
||||
break;
|
||||
}
|
||||
if (previous->second.shaderWriteTime != item.second.shaderWriteTime ||
|
||||
previous->second.manifestWriteTime != item.second.manifestWriteTime ||
|
||||
!TextureAssetsEqual(previous->second.textureAssets, item.second.textureAssets) ||
|
||||
!FontAssetsEqual(previous->second.fontAssets, item.second.fontAssets))
|
||||
{
|
||||
registryChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (RuntimeHost::LayerPersistentState& layer : mRuntimeHost.mPersistentState.layers)
|
||||
{
|
||||
auto active = mRuntimeHost.mPackagesById.find(layer.shaderId);
|
||||
auto previous = previousLayerShaderTimes.find(layer.id);
|
||||
if (active == mRuntimeHost.mPackagesById.end())
|
||||
continue;
|
||||
mRuntimeHost.EnsureLayerDefaultsLocked(layer, active->second);
|
||||
if (previous != previousLayerShaderTimes.end())
|
||||
{
|
||||
auto previousPackage = previousPackages.find(layer.shaderId);
|
||||
if (previous->second.first != active->second.shaderWriteTime ||
|
||||
previous->second.second != active->second.manifestWriteTime ||
|
||||
(previousPackage != previousPackages.end() &&
|
||||
(!TextureAssetsEqual(previousPackage->second.textureAssets, active->second.textureAssets) ||
|
||||
!FontAssetsEqual(previousPackage->second.fontAssets, active->second.fontAssets))))
|
||||
{
|
||||
mRuntimeHost.mReloadRequested = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reloadRequested = mRuntimeHost.mReloadRequested;
|
||||
if (registryChanged || reloadRequested)
|
||||
mRuntimeHost.MarkRenderStateDirtyLocked();
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& exception)
|
||||
{
|
||||
error = std::string("RuntimeStore::PollStoredFileChanges exception: ") + exception.what();
|
||||
return false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
error = "RuntimeStore::PollStoredFileChanges threw a non-standard exception.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool RuntimeStore::CreateStoredLayer(const std::string& shaderId, std::string& error)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
@@ -465,12 +602,15 @@ const std::string& RuntimeStore::GetConfiguredOutputFrameRate() const
|
||||
|
||||
void RuntimeStore::SetCompileStatus(bool succeeded, const std::string& message)
|
||||
{
|
||||
mRuntimeHost.SetCompileStatus(succeeded, message);
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
mRuntimeHost.mCompileSucceeded = succeeded;
|
||||
mRuntimeHost.mCompileMessage = message;
|
||||
}
|
||||
|
||||
void RuntimeStore::ClearReloadRequest()
|
||||
{
|
||||
mRuntimeHost.ClearReloadRequest();
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
mRuntimeHost.mReloadRequested = false;
|
||||
}
|
||||
|
||||
JsonValue RuntimeStore::BuildRuntimeStateValue() const
|
||||
|
||||
Reference in New Issue
Block a user