diff --git a/core/2d/AnimationCache.cpp b/core/2d/AnimationCache.cpp index 9bc4ea31a0..a57bd40ede 100644 --- a/core/2d/AnimationCache.cpp +++ b/core/2d/AnimationCache.cpp @@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -48,7 +49,7 @@ AnimationCache* AnimationCache::getInstance() void AnimationCache::destroyInstance() { - AX_SAFE_RELEASE_NULL(s_sharedAnimationCache); + AX_SAFE_DELETE(s_sharedAnimationCache); } bool AnimationCache::init() diff --git a/core/2d/AnimationCache.h b/core/2d/AnimationCache.h index 60702ae343..f0ee9ee77e 100644 --- a/core/2d/AnimationCache.h +++ b/core/2d/AnimationCache.h @@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -52,7 +53,7 @@ Before v0.99.5, the recommend way was to save them on the Sprite. Since v0.99.5, @since v0.99.5 @js cc.animationCache */ -class AX_DLL AnimationCache : public Ref +class AX_DLL AnimationCache { public: /** diff --git a/core/2d/ParticleSystem.h b/core/2d/ParticleSystem.h index 0aaa905eb5..0c0d3c59c8 100644 --- a/core/2d/ParticleSystem.h +++ b/core/2d/ParticleSystem.h @@ -239,7 +239,7 @@ public: * Particle emission mask cache. * @since axmol-1.0.0b8 */ -class AX_DLL ParticleEmissionMaskCache : public ax::Ref +class AX_DLL ParticleEmissionMaskCache { public: static ParticleEmissionMaskCache* getInstance(); diff --git a/core/2d/SpriteFrameCache.cpp b/core/2d/SpriteFrameCache.cpp index a0e22547a8..7b3f4e50d9 100644 --- a/core/2d/SpriteFrameCache.cpp +++ b/core/2d/SpriteFrameCache.cpp @@ -6,6 +6,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -60,7 +61,7 @@ SpriteFrameCache* SpriteFrameCache::getInstance() void SpriteFrameCache::destroyInstance() { - AX_SAFE_RELEASE_NULL(_sharedSpriteFrameCache); + AX_SAFE_DELETE(_sharedSpriteFrameCache); } bool SpriteFrameCache::init() diff --git a/core/2d/SpriteFrameCache.h b/core/2d/SpriteFrameCache.h index 13cdcd895d..b9c88ff0d3 100644 --- a/core/2d/SpriteFrameCache.h +++ b/core/2d/SpriteFrameCache.h @@ -6,6 +6,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -88,7 +89,7 @@ class PolygonInfo; @since v0.9 @js cc.spriteFrameCache */ -class AX_DLL SpriteFrameCache : public Ref +class AX_DLL SpriteFrameCache { public: /** Returns the shared instance of the Sprite Frame cache. diff --git a/core/base/Configuration.cpp b/core/base/Configuration.cpp index da46c55d23..1543523e7c 100644 --- a/core/base/Configuration.cpp +++ b/core/base/Configuration.cpp @@ -181,7 +181,7 @@ Configuration* Configuration::getInstance() void Configuration::destroyInstance() { - AX_SAFE_RELEASE_NULL(s_sharedConfiguration); + AX_SAFE_DELETE(s_sharedConfiguration); } // diff --git a/core/base/Configuration.h b/core/base/Configuration.h index a24dcfde5d..f457959b2f 100644 --- a/core/base/Configuration.h +++ b/core/base/Configuration.h @@ -3,6 +3,7 @@ Copyright (c) 2010 Ricardo Quesada Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -47,7 +48,7 @@ class EventCustom; * @since v0.99.0 * @js NA */ -class AX_DLL Configuration : public Ref +class AX_DLL Configuration { public: /** Returns a shared instance of Configuration. diff --git a/core/base/Director.cpp b/core/base/Director.cpp index ea1d21cd73..4469a893f5 100644 --- a/core/base/Director.cpp +++ b/core/base/Director.cpp @@ -90,7 +90,7 @@ Director* Director::getInstance() { if (!s_SharedDirector) { - s_SharedDirector = new Director; + s_SharedDirector = new Director(); AXASSERT(s_SharedDirector, "FATAL: Not enough memory"); s_SharedDirector->init(); } @@ -98,6 +98,11 @@ Director* Director::getInstance() return s_SharedDirector; } +void Director::destroyInstance() +{ + AX_SAFE_DELETE(s_SharedDirector); +} + Director::Director() {} bool Director::init() @@ -193,9 +198,15 @@ Director::~Director() s_SharedDirector = nullptr; + backend::DriverBase::destroyInstance(); + QuadCommand::destroyIsolatedIndices(); + #if AX_ENABLE_SCRIPT_BINDING ScriptEngineManager::destroyInstance(); #endif + + /** clean auto release pool. */ + PoolManager::destroyInstance(); } void Director::setDefaultValues() @@ -953,7 +964,7 @@ void Director::popToSceneStackLevel(int level) void Director::end() { - _purgeDirectorInNextLoop = true; + _cleanupDirectorInNextLoop = true; } void Director::restart() @@ -1044,6 +1055,7 @@ void Director::reset() SpriteFrameCache::destroyInstance(); FileUtils::destroyInstance(); AsyncTaskPool::destroyInstance(); + backend::ProgramStateRegistry::destroyInstance(); backend::ProgramManager::destroyInstance(); // axmol specific data structures @@ -1053,7 +1065,7 @@ void Director::reset() destroyTextureCache(); } -void Director::purgeDirector() +void Director::cleanupDirector() { reset(); @@ -1066,9 +1078,6 @@ void Director::purgeDirector() _glView = nullptr; } - // delete Director - release(); - #if AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID utils::killCurrentProcess(); #endif @@ -1523,10 +1532,10 @@ void Director::mainLoop() processOperations(); #endif - if (_purgeDirectorInNextLoop) + if (_cleanupDirectorInNextLoop) { - _purgeDirectorInNextLoop = false; - purgeDirector(); + _cleanupDirectorInNextLoop = false; + cleanupDirector(); } else if (_restartDirectorInNextLoop) { diff --git a/core/base/Director.h b/core/base/Director.h index 46abe50b1d..5286c5ef0f 100644 --- a/core/base/Director.h +++ b/core/base/Director.h @@ -77,7 +77,7 @@ class Console; Since the Director is a singleton, the standard way to use it is by calling: _ Director::getInstance()->methodName(); */ -class AX_DLL Director : public Ref +class AX_DLL Director { public: /** Director will trigger an event before set next scene. */ @@ -123,6 +123,7 @@ public: * @js _getInstance */ static Director* getInstance(); + static void destroyInstance(); /** * @js ctor @@ -531,8 +532,8 @@ protected: virtual void startAnimation(SetIntervalReason reason); virtual void setAnimationInterval(float interval, SetIntervalReason reason); - void purgeDirector(); - bool _purgeDirectorInNextLoop = false; // this flag will be set to true in end() + void cleanupDirector(); + bool _cleanupDirectorInNextLoop = false; // this flag will be set to true in end() void restartDirector(); bool _restartDirectorInNextLoop = false; // this flag will be set to true in restart() diff --git a/core/base/Profiling.h b/core/base/Profiling.h index 3a77882c46..38b87f66aa 100644 --- a/core/base/Profiling.h +++ b/core/base/Profiling.h @@ -3,6 +3,7 @@ Copyright (c) 2010 Stuart Carnie Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -50,7 +51,7 @@ class ProfilingTimer; To use it, enable set the AX_ENABLE_PROFILERS=1 in the ccConfig.h file */ -class AX_DLL Profiler : public Ref +class AX_DLL Profiler { public: /** diff --git a/core/platform/ApplicationBase.cpp b/core/platform/ApplicationBase.cpp new file mode 100644 index 0000000000..5a11f8949e --- /dev/null +++ b/core/platform/ApplicationBase.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** +Copyright (c) 2010-2012 cocos2d-x.org +Copyright (c) 2013-2016 Chukong Technologies Inc. +Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + +https://axmolengine.github.io/ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "ApplicationBase.h" +#include "base/Director.h" + +NS_AX_BEGIN + +ApplicationBase::~ApplicationBase() +{ + Director::destroyInstance(); +} + +NS_AX_END diff --git a/core/platform/ApplicationProtocol.h b/core/platform/ApplicationBase.h similarity index 94% rename from core/platform/ApplicationProtocol.h rename to core/platform/ApplicationBase.h index ff1ce7c1a3..31fdd1281c 100644 --- a/core/platform/ApplicationProtocol.h +++ b/core/platform/ApplicationBase.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -24,8 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#ifndef __AX_APPLICATION_PROTOCOL_H__ -#define __AX_APPLICATION_PROTOCOL_H__ +#ifndef __AX_APPLICATION_BASE_H__ +#define __AX_APPLICATION_BASE_H__ #include "platform/PlatformMacros.h" #include "base/AutoreleasePool.h" @@ -38,7 +39,7 @@ NS_AX_BEGIN * @{ */ -class AX_DLL ApplicationProtocol +class AX_DLL ApplicationBase { public: /** Since WINDOWS and ANDROID are defined as macros, we could not just use these keywords in enumeration(Platform). @@ -65,11 +66,7 @@ public: * @js NA * @lua NA */ - virtual ~ApplicationProtocol() - { - /** clean auto release pool. */ - PoolManager::destroyInstance(); - } + virtual ~ApplicationBase(); /** * @brief Implement Director and Scene init code here. @@ -152,6 +149,8 @@ public: virtual bool openURL(std::string_view url) = 0; }; +using ApplicationProtocol = ApplicationBase; + // end of platform group /** @} */ diff --git a/core/platform/CMakeLists.txt b/core/platform/CMakeLists.txt index 2249d816d9..82ef79cd51 100644 --- a/core/platform/CMakeLists.txt +++ b/core/platform/CMakeLists.txt @@ -171,7 +171,7 @@ endif() set(_AX_PLATFORM_HEADER ${_AX_PLATFORM_SPECIFIC_HEADER} platform/Application.h - platform/ApplicationProtocol.h + platform/ApplicationBase.h platform/Common.h platform/Device.h platform/FileUtils.h @@ -194,4 +194,5 @@ set(_AX_PLATFORM_SRC platform/FileUtils.cpp platform/Image.cpp platform/FileStream.cpp + platform/ApplicationBase.cpp ) diff --git a/core/platform/android/Application-android.h b/core/platform/android/Application-android.h index fdb1c5b5af..ff80fa3272 100644 --- a/core/platform/android/Application-android.h +++ b/core/platform/android/Application-android.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -26,11 +27,11 @@ THE SOFTWARE. #pragma once #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" NS_AX_BEGIN -class AX_DLL Application : public ApplicationProtocol +class AX_DLL Application : public ApplicationBase { public: /** diff --git a/core/platform/android/EnhanceAPI-android.h b/core/platform/android/EnhanceAPI-android.h index ec8586d80a..b157f392fe 100644 --- a/core/platform/android/EnhanceAPI-android.h +++ b/core/platform/android/EnhanceAPI-android.h @@ -3,8 +3,9 @@ * Developed by Game Engine part * * Copyright 2015 by Mobile Solution Lab, MSG, SRC-NJ. - * Wang Ying - * All rights reserved. + * Wang Ying, All rights reserved. + * Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + * * * This software is the confidential and proprietary information of * Samsung Electronics, Inc. ("Confidential Information"). You @@ -15,7 +16,7 @@ #pragma once #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" NS_AX_BEGIN diff --git a/core/platform/ios/Application-ios.h b/core/platform/ios/Application-ios.h index 6fdef1a1c5..2b636f152f 100644 --- a/core/platform/ios/Application-ios.h +++ b/core/platform/ios/Application-ios.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -26,11 +27,11 @@ THE SOFTWARE. #pragma once #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" NS_AX_BEGIN -class AX_DLL Application : public ApplicationProtocol +class AX_DLL Application : public ApplicationBase { public: /** diff --git a/core/platform/linux/Application-linux.h b/core/platform/linux/Application-linux.h index bbb8a52b0f..0d36814c43 100644 --- a/core/platform/linux/Application-linux.h +++ b/core/platform/linux/Application-linux.h @@ -2,6 +2,7 @@ Copyright (c) 2011 Laschweinski Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -26,14 +27,14 @@ THE SOFTWARE. #pragma once #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" #include #include NS_AX_BEGIN class Rect; -class Application : public ApplicationProtocol +class Application : public ApplicationBase { public: /** diff --git a/core/platform/mac/Application-mac.h b/core/platform/mac/Application-mac.h index 93c39a46c5..073236dacf 100644 --- a/core/platform/mac/Application-mac.h +++ b/core/platform/mac/Application-mac.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -26,13 +27,13 @@ THE SOFTWARE. #pragma once #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" #include #include NS_AX_BEGIN -class AX_DLL Application : public ApplicationProtocol +class AX_DLL Application : public ApplicationBase { public: /** diff --git a/core/platform/wasm/Application-wasm.h b/core/platform/wasm/Application-wasm.h index 61b3667007..c7962e028b 100644 --- a/core/platform/wasm/Application-wasm.h +++ b/core/platform/wasm/Application-wasm.h @@ -2,6 +2,7 @@ Copyright (c) 2011 Laschweinski Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). http://www.cocos2d-x.org @@ -31,13 +32,13 @@ THE SOFTWARE. #if AX_TARGET_PLATFORM == AX_PLATFORM_WASM #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" #include NS_AX_BEGIN class Rect; -class Application : public ApplicationProtocol +class Application : public ApplicationBase { public: /** diff --git a/core/platform/win32/Application-win32.cpp b/core/platform/win32/Application-win32.cpp index 733f0ad361..af5a1d7c61 100644 --- a/core/platform/win32/Application-win32.cpp +++ b/core/platform/win32/Application-win32.cpp @@ -128,6 +128,7 @@ int Application::run() } glView->release(); + return 0; } diff --git a/core/platform/win32/Application-win32.h b/core/platform/win32/Application-win32.h index 6738ecc4e7..39b8c3fcfc 100644 --- a/core/platform/win32/Application-win32.h +++ b/core/platform/win32/Application-win32.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -27,12 +28,12 @@ THE SOFTWARE. #include "platform/StdC.h" #include "platform/Common.h" -#include "platform/ApplicationProtocol.h" +#include "platform/ApplicationBase.h" #include NS_AX_BEGIN -class AX_DLL Application : public ApplicationProtocol +class AX_DLL Application : public ApplicationBase { public: /** diff --git a/core/platform/winrt/Application-winrt.cpp b/core/platform/winrt/Application-winrt.cpp index d37e3c7105..4a706a70f7 100644 --- a/core/platform/winrt/Application-winrt.cpp +++ b/core/platform/winrt/Application-winrt.cpp @@ -2,6 +2,7 @@ Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) Microsoft Open Technologies, Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ diff --git a/core/platform/winrt/Application-winrt.h b/core/platform/winrt/Application-winrt.h index 97c465002c..ca0a04955e 100644 --- a/core/platform/winrt/Application-winrt.h +++ b/core/platform/winrt/Application-winrt.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) Microsoft Open Technologies, Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -31,14 +32,14 @@ THE SOFTWARE. # include "platform/StdC.h" # include "platform/Common.h" -# include "platform/ApplicationProtocol.h" +# include "platform/ApplicationBase.h" # include "platform/winrt/InputEvent.h" # include # include NS_AX_BEGIN -class AX_DLL Application : public ApplicationProtocol +class AX_DLL Application : public ApplicationBase { public: Application(); diff --git a/core/renderer/QuadCommand.cpp b/core/renderer/QuadCommand.cpp index c6df46c774..aaa2339f5e 100644 --- a/core/renderer/QuadCommand.cpp +++ b/core/renderer/QuadCommand.cpp @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -37,6 +38,12 @@ NS_AX_BEGIN int QuadCommand::__indexCapacity = -1; uint16_t* QuadCommand::__indices = nullptr; +void QuadCommand::destroyIsolatedIndices() +{ + AX_SAFE_DELETE_ARRAY(__indices); + __indexCapacity = -1; +} + QuadCommand::QuadCommand() : _indexSize(-1), _ownedIndices() {} QuadCommand::~QuadCommand() diff --git a/core/renderer/QuadCommand.h b/core/renderer/QuadCommand.h index 4094a99c7f..087c8299bd 100644 --- a/core/renderer/QuadCommand.h +++ b/core/renderer/QuadCommand.h @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -67,6 +68,8 @@ public: const Mat4& mv, uint32_t flags); + static void destroyIsolatedIndices(); + protected: void reIndex(int indices); diff --git a/core/renderer/backend/DriverBase.h b/core/renderer/backend/DriverBase.h index 64d3fc9fb9..ca389d91d3 100644 --- a/core/renderer/backend/DriverBase.h +++ b/core/renderer/backend/DriverBase.h @@ -72,7 +72,7 @@ enum class FeatureType : uint32_t /** * New or create resources from DriverBase. */ -class AX_DLL DriverBase : public ax::Ref +class AX_DLL DriverBase { public: friend class ProgramManager; @@ -82,6 +82,7 @@ public: * Returns a shared instance of the DriverBase. */ static DriverBase* getInstance(); + static void destroyInstance(); virtual ~DriverBase() = default; diff --git a/core/renderer/backend/ProgramManager.cpp b/core/renderer/backend/ProgramManager.cpp index 1147e56716..ac3d01afdc 100644 --- a/core/renderer/backend/ProgramManager.cpp +++ b/core/renderer/backend/ProgramManager.cpp @@ -52,7 +52,7 @@ ProgramManager* ProgramManager::getInstance() void ProgramManager::destroyInstance() { - AX_SAFE_RELEASE_NULL(_sharedProgramManager); + AX_SAFE_DELETE(_sharedProgramManager); } ProgramManager::ProgramManager() @@ -69,7 +69,7 @@ ProgramManager::~ProgramManager() AX_SAFE_RELEASE(program.second); } AXLOGINFO("deallocing ProgramManager: %p", this); - backend::ShaderCache::getInstance()->purge(); + backend::ShaderCache::destroyInstance(); } // ### end of vertex layout setup functions diff --git a/core/renderer/backend/ProgramManager.h b/core/renderer/backend/ProgramManager.h index a3a668c839..e477e75aae 100644 --- a/core/renderer/backend/ProgramManager.h +++ b/core/renderer/backend/ProgramManager.h @@ -46,7 +46,7 @@ NS_AX_BACKEND_BEGIN /** * Cache and reuse program object. */ -class AX_DLL ProgramManager : public Ref +class AX_DLL ProgramManager { public: /** returns the shared instance */ diff --git a/core/renderer/backend/ProgramStateRegistry.cpp b/core/renderer/backend/ProgramStateRegistry.cpp index c6b679860f..809137f1bc 100644 --- a/core/renderer/backend/ProgramStateRegistry.cpp +++ b/core/renderer/backend/ProgramStateRegistry.cpp @@ -21,7 +21,7 @@ ProgramStateRegistry* ProgramStateRegistry::getInstance() /** purges the cache. It releases the retained instance. */ void ProgramStateRegistry::destroyInstance() { - AX_SAFE_RELEASE_NULL(_sharedStateRegistry); + AX_SAFE_DELETE(_sharedStateRegistry); } bool ProgramStateRegistry::init() diff --git a/core/renderer/backend/ProgramStateRegistry.h b/core/renderer/backend/ProgramStateRegistry.h index 20281f1a44..a9a0a63f7d 100644 --- a/core/renderer/backend/ProgramStateRegistry.h +++ b/core/renderer/backend/ProgramStateRegistry.h @@ -15,7 +15,7 @@ NS_AX_BACKEND_BEGIN * @{ * #todo: Rename to ProgramStateRegistry */ -class AX_DLL ProgramStateRegistry : public Ref +class AX_DLL ProgramStateRegistry { public: /** returns the shared instance */ diff --git a/core/renderer/backend/ShaderCache.cpp b/core/renderer/backend/ShaderCache.cpp index 4aa1646f6e..adb620b6b9 100644 --- a/core/renderer/backend/ShaderCache.cpp +++ b/core/renderer/backend/ShaderCache.cpp @@ -1,5 +1,6 @@ /**************************************************************************** Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -27,10 +28,23 @@ NS_AX_BACKEND_BEGIN +static ShaderCache* s_instance; + ShaderCache* ShaderCache::getInstance() { - static ShaderCache instance; - return &instance; + if (s_instance) + return s_instance; + return (s_instance = new ShaderCache()); +} + +void ShaderCache::destroyInstance() +{ + AX_SAFE_DELETE(s_instance); +} + +ShaderCache::~ShaderCache() +{ + purge(); } void ShaderCache::purge() @@ -55,7 +69,7 @@ backend::ShaderModule* ShaderCache::newFragmentShaderModule(std::string_view sha backend::ShaderModule* ShaderCache::newShaderModule(backend::ShaderStage stage, std::string_view shaderSource) { const std::size_t key = std::hash{}(shaderSource); - const auto iter = _cachedShaders.find(key); + const auto iter = _cachedShaders.find(key); if (_cachedShaders.end() != iter) return iter->second; diff --git a/core/renderer/backend/ShaderCache.h b/core/renderer/backend/ShaderCache.h index d187916bce..8c8194df28 100644 --- a/core/renderer/backend/ShaderCache.h +++ b/core/renderer/backend/ShaderCache.h @@ -1,5 +1,6 @@ /**************************************************************************** Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmolengine.github.io/ @@ -40,10 +41,13 @@ NS_AX_BACKEND_BEGIN /** * Create and reuse shader module. */ -class AX_DLL ShaderCache : public Ref +class AX_DLL ShaderCache { public: static ShaderCache* getInstance(); + static void destroyInstance(); + + ~ShaderCache(); /** purges the cache. It releases the retained instance. */ void purge(); diff --git a/core/renderer/backend/metal/DriverMTL.mm b/core/renderer/backend/metal/DriverMTL.mm index 3f084c89bb..9c147b693b 100644 --- a/core/renderer/backend/metal/DriverMTL.mm +++ b/core/renderer/backend/metal/DriverMTL.mm @@ -391,10 +391,15 @@ id DriverMTL::_currentDrawable = nil; DriverBase* DriverBase::getInstance() { - if (!DriverBase::_instance) - DriverBase::_instance = new DriverMTL(); + if (!_instance) + _instance = new DriverMTL(); - return DriverBase::_instance; + return _instance; +} + +void DriverBase::destroyInstance() +{ + AX_SAFE_DELETE(_instance); } void DriverMTL::setCAMetalLayer(CAMetalLayer* metalLayer) diff --git a/core/renderer/backend/opengl/DriverGL.cpp b/core/renderer/backend/opengl/DriverGL.cpp index b67074f803..2accc31e9c 100644 --- a/core/renderer/backend/opengl/DriverGL.cpp +++ b/core/renderer/backend/opengl/DriverGL.cpp @@ -94,6 +94,10 @@ DriverBase* DriverBase::getInstance() return _instance; } +void DriverBase::destroyInstance() { + AX_SAFE_DELETE(_instance); +} + DriverGL::DriverGL() { /// driver info diff --git a/extensions/scripting/lua-bindings/script/core/Constants.lua b/extensions/scripting/lua-bindings/script/core/Constants.lua index a7400f1ea2..cd41cd37a2 100644 --- a/extensions/scripting/lua-bindings/script/core/Constants.lua +++ b/extensions/scripting/lua-bindings/script/core/Constants.lua @@ -190,7 +190,7 @@ cc.UNIFORM_SAMPLER_S = 'AX_Texture0' cc.UNIFORM_SIN_TIME_S = 'AX_SinTime' cc.UNIFORM_TIME_S = 'AX_Time' --- refer to: ApplicationProtocol.h: enum class Platform +-- refer to: ApplicationBase.h: enum class Platform cc.PLATFORM_UNKNOWN = 0 cc.PLATFORM_WIN32 = 1 cc.PLATFORM_WINUWP = 2