From 6f1cfe6fbe7953a3c5c75c465519c3cedf4d36e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=BE=E6=99=93=E7=9A=8E?= Date: Fri, 22 Mar 2024 14:21:23 +0800 Subject: [PATCH 1/4] Limit frame rate on wasm --- core/platform/wasm/Application-wasm.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/platform/wasm/Application-wasm.cpp b/core/platform/wasm/Application-wasm.cpp index 3b65a178eac3..6f20467b73ee 100644 --- a/core/platform/wasm/Application-wasm.cpp +++ b/core/platform/wasm/Application-wasm.cpp @@ -53,7 +53,7 @@ static long getCurrentMillSecond() { } Application::Application() -: _animationInterval(1.0f/60.0f*1000.0f) +: _animationInterval(60.0f) { AX_ASSERT(! sm_pSharedApplication); sm_pSharedApplication = this; @@ -89,7 +89,8 @@ int Application::run() // Retain glview to avoid glview being released in the while loop glview->retain(); - emscripten_set_main_loop(&mainLoopIter, 0, 1); + //emscripten_set_main_loop(&mainLoopIter, 0, 1); + emscripten_set_main_loop(&mainLoopIter, _animationInterval, 1); // TODO: ? does these cleanup really run? /* Only work on Desktop * Director::mainLoop is really one frame logic @@ -108,7 +109,7 @@ int Application::run() void Application::setAnimationInterval(float interval) { - _animationInterval = interval*1000.0f; + _animationInterval = 1.0f / interval; } void Application::setResourceRootPath(const std::string& rootResDir) From 55cf2aacd7d065a91bfbb8768d734649bfe52267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=BE=E6=99=93=E7=9A=8E?= Date: Fri, 22 Mar 2024 16:21:11 +0800 Subject: [PATCH 2/4] Limit frame rate on wasm --- core/platform/wasm/Application-wasm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/platform/wasm/Application-wasm.cpp b/core/platform/wasm/Application-wasm.cpp index 6f20467b73ee..e0f04d341db9 100644 --- a/core/platform/wasm/Application-wasm.cpp +++ b/core/platform/wasm/Application-wasm.cpp @@ -53,7 +53,7 @@ static long getCurrentMillSecond() { } Application::Application() -: _animationInterval(60.0f) +: _animationInterval(1 / 60.0f * 1000.0f) { AX_ASSERT(! sm_pSharedApplication); sm_pSharedApplication = this; @@ -90,7 +90,7 @@ int Application::run() glview->retain(); //emscripten_set_main_loop(&mainLoopIter, 0, 1); - emscripten_set_main_loop(&mainLoopIter, _animationInterval, 1); + emscripten_set_main_loop(&mainLoopIter, 1.0f / (_animationInterval / 1000.0f), 1); // TODO: ? does these cleanup really run? /* Only work on Desktop * Director::mainLoop is really one frame logic @@ -109,7 +109,7 @@ int Application::run() void Application::setAnimationInterval(float interval) { - _animationInterval = 1.0f / interval; + _animationInterval = interval * 1000.0f; } void Application::setResourceRootPath(const std::string& rootResDir) From 24a41e7044d09669276b36d654513b3cba33677d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=BE=E6=99=93=E7=9A=8E?= Date: Fri, 22 Mar 2024 16:27:37 +0800 Subject: [PATCH 3/4] Edit frame rate on wasm --- core/platform/wasm/Application-wasm.cpp | 6 +++--- core/platform/wasm/Application-wasm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/platform/wasm/Application-wasm.cpp b/core/platform/wasm/Application-wasm.cpp index e0f04d341db9..c158e5bb7ad6 100644 --- a/core/platform/wasm/Application-wasm.cpp +++ b/core/platform/wasm/Application-wasm.cpp @@ -53,7 +53,7 @@ static long getCurrentMillSecond() { } Application::Application() -: _animationInterval(1 / 60.0f * 1000.0f) +: _animationSpeed(60) { AX_ASSERT(! sm_pSharedApplication); sm_pSharedApplication = this; @@ -90,7 +90,7 @@ int Application::run() glview->retain(); //emscripten_set_main_loop(&mainLoopIter, 0, 1); - emscripten_set_main_loop(&mainLoopIter, 1.0f / (_animationInterval / 1000.0f), 1); + emscripten_set_main_loop(&mainLoopIter, _animationSpeed, 1); // TODO: ? does these cleanup really run? /* Only work on Desktop * Director::mainLoop is really one frame logic @@ -109,7 +109,7 @@ int Application::run() void Application::setAnimationInterval(float interval) { - _animationInterval = interval * 1000.0f; + _animationSpeed = 1.0f / interval; } void Application::setResourceRootPath(const std::string& rootResDir) diff --git a/core/platform/wasm/Application-wasm.h b/core/platform/wasm/Application-wasm.h index 0dafbd0657f1..a7f01366f14f 100644 --- a/core/platform/wasm/Application-wasm.h +++ b/core/platform/wasm/Application-wasm.h @@ -111,7 +111,7 @@ class Application : public ApplicationBase */ virtual Platform getTargetPlatform() override; protected: - long _animationInterval; //micro second + long _animationSpeed; // micro second std::string _resourceRootPath; static Application * sm_pSharedApplication; From de34e566b87333036a7e1c0ef478aa086c4c516f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=BE=E6=99=93=E7=9A=8E?= Date: Thu, 27 Jun 2024 22:06:19 +0800 Subject: [PATCH 4/4] Add interfaces for easy expansion --- core/3d/Mesh.h | 4 ++++ core/base/Properties.cpp | 32 ++++++++++++++++++++++++++++++++ core/base/Properties.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/core/3d/Mesh.h b/core/3d/Mesh.h index 678afdf195a2..f855737cd79e 100644 --- a/core/3d/Mesh.h +++ b/core/3d/Mesh.h @@ -322,6 +322,10 @@ class AX_DLL Mesh : public Object std::vector _spotLightUniformRangeInverseValues; std::string _texFile; + + // add by binxiaojiao +public: + std::function& GetVisibleChanged() { return _visibleChanged; } }; // end of 3d group diff --git a/core/base/Properties.cpp b/core/base/Properties.cpp index 91dbd7f3bf55..c1b48552ade7 100644 --- a/core/base/Properties.cpp +++ b/core/base/Properties.cpp @@ -141,6 +141,38 @@ Properties* Properties::createNonRefCounted(std::string_view url) return p; } +Properties* Properties::createNonRefCounted(Data* data, ssize_t* dataIdx) +{ + std::vector namespacePath; + + // data will be released automatically when 'data' goes out of scope + // so we pass data as weak pointer + Properties* properties = new Properties(data, dataIdx); + properties->resolveInheritance(); + + // Get the specified properties object. + Properties* p = getPropertiesFromNamespacePath(properties, namespacePath); + if (!p) + { + AXLOGWARN("Failed to load properties from mem."); + AX_SAFE_DELETE(properties); + return nullptr; + } + + // If the loaded properties object is not the root namespace, + // then we have to clone it and delete the root namespace + // so that we don't leak memory. + if (p != properties) + { + p = p->clone(); + AX_SAFE_DELETE(properties); + } + // XXX + // p->setDirectoryPath(FileSystem::getDirectoryName(fileString)); + p->setDirectoryPath(""); + return p; +} + static bool isVariable(const char* str, char* outName, size_t outSize) { size_t len = strlen(str); diff --git a/core/base/Properties.h b/core/base/Properties.h index 67a3d1f49b58..7f6a4e4653a1 100644 --- a/core/base/Properties.h +++ b/core/base/Properties.h @@ -184,6 +184,8 @@ class AX_DLL Properties * @script{create} */ static Properties* createNonRefCounted(std::string_view url); + // add by binxiaojiao + static Properties* createNonRefCounted(Data* data, ssize_t* dataIdx); /** * Destructor.