From 6253a5cf2e0e66f268b6bd843c2aaa75c0928ecc Mon Sep 17 00:00:00 2001 From: GPayne Date: Sun, 22 Mar 2020 20:59:15 -0600 Subject: [PATCH] First pass on tracking changed properties/assets since initialization --- include/openspace/engine/openspaceengine.h | 1 + include/openspace/properties/property.h | 8 ++++++++ include/openspace/properties/templateproperty.inl | 2 ++ include/openspace/scene/assetloader.h | 3 +++ src/engine/openspaceengine.cpp | 14 ++++++++++++++ src/properties/property.cpp | 4 ++++ src/scene/assetloader.cpp | 2 ++ 7 files changed, 34 insertions(+) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 539530cad0..b150d594d1 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -76,6 +76,7 @@ public: const glm::mat4& projectionMatrix); void drawOverlays(); void postDraw(); + void resetPropertyChangeFlags(); void keyboardCallback(Key key, KeyModifier mod, KeyAction action); void charCallback(unsigned int codepoint, KeyModifier modifier); void mouseButtonCallback(MouseButton button, MouseAction action, KeyModifier mods); diff --git a/include/openspace/properties/property.h b/include/openspace/properties/property.h index 1e5dd5c8b3..0cfbbc9be0 100644 --- a/include/openspace/properties/property.h +++ b/include/openspace/properties/property.h @@ -495,6 +495,11 @@ public: */ virtual std::string generateAdditionalJsonDescription() const; + /** + * Reset the valChanged flag to an unchanged state, as if value has not been changed. + */ + void resetToUnchanged(); + protected: static const char* IdentifierKey; static const char* NameKey; @@ -531,6 +536,9 @@ protected: /// The callback function sthat will be invoked whenever the value changes std::vector>> _onDeleteCallbacks; + /// Flag indicating that this property value has been changed after initialization + bool valChanged = false; + private: void notifyDeleteListeners(); diff --git a/include/openspace/properties/templateproperty.inl b/include/openspace/properties/templateproperty.inl index 56fdca6a1a..78af3f6039 100644 --- a/include/openspace/properties/templateproperty.inl +++ b/include/openspace/properties/templateproperty.inl @@ -176,6 +176,7 @@ void openspace::properties::TemplateProperty::setValue(T val) { if (val != _value) { _value = std::move(val); notifyChangeListeners(); + valChanged = true; } } @@ -196,6 +197,7 @@ void TemplateProperty::set(std::any value) { if (v != _value) { _value = std::move(v); notifyChangeListeners(); + valChanged = true; } } diff --git a/include/openspace/scene/assetloader.h b/include/openspace/scene/assetloader.h index ea32931835..6b3dac5369 100644 --- a/include/openspace/scene/assetloader.h +++ b/include/openspace/scene/assetloader.h @@ -226,6 +226,9 @@ private: std::unordered_map>> _onDependencyDeinitializationFunctionRefs; int _assetsTableRef; + + std::vector profileAssetsAdded; + std::vector profileAssetsRemoved; }; } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 2ed17ecb9a..0d0a8f4ad0 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1299,12 +1299,26 @@ void OpenSpaceEngine::postDraw() { if (_isFirstRenderingFirstFrame) { global::windowDelegate.setSynchronization(true); + resetPropertyChangeFlags(); _isFirstRenderingFirstFrame = false; } LTRACE("OpenSpaceEngine::postDraw(end)"); } +void OpenSpaceEngine::resetPropertyChangeFlags() { + ZoneScoped + + std::vector nodes = + global::renderEngine.scene()->allSceneGraphNodes(); + for (auto n : nodes) { + std::vector props = n->properties(); + for (auto p : props) { + p->resetToUnchanged(); + } + } +} + void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) { ZoneScoped diff --git a/src/properties/property.cpp b/src/properties/property.cpp index 22812fda89..5a00032616 100644 --- a/src/properties/property.cpp +++ b/src/properties/property.cpp @@ -312,6 +312,10 @@ void Property::notifyDeleteListeners() { } } +void Property::resetToUnchanged() { + valChanged = false; +} + std::string Property::generateBaseJsonDescription() const { std::string cName = className(); std::string cNameSan = sanitizeString(cName); diff --git a/src/scene/assetloader.cpp b/src/scene/assetloader.cpp index 6d4b7c95c0..888ee4fc3f 100644 --- a/src/scene/assetloader.cpp +++ b/src/scene/assetloader.cpp @@ -473,6 +473,7 @@ ghoul::filesystem::Directory AssetLoader::currentDirectory() const { std::shared_ptr AssetLoader::add(const std::string& identifier) { setCurrentAsset(_rootAsset); + profileAssetsAdded.push_back(identifier); return request(identifier); } @@ -480,6 +481,7 @@ std::shared_ptr AssetLoader::add(const std::string& identifier) { void AssetLoader::remove(const std::string& identifier) { setCurrentAsset(_rootAsset); unrequest(identifier); + profileAssetsRemoved.push_back(identifier); } std::shared_ptr AssetLoader::has(const std::string& identifier) const {