From a134a2e95299cbf51dcd60d2c9654e14a9d37977 Mon Sep 17 00:00:00 2001 From: Nomango Date: Thu, 23 Jul 2020 17:21:44 +0800 Subject: [PATCH] remove ObjectPool --- projects/kiwano/kiwano.vcxproj | 2 - projects/kiwano/kiwano.vcxproj.filters | 6 --- src/kiwano/2d/Actor.cpp | 16 +++--- src/kiwano/2d/action/ActionDelay.cpp | 2 +- src/kiwano/2d/action/ActionGroup.cpp | 4 +- src/kiwano/2d/action/ActionTween.cpp | 28 +++++------ src/kiwano/2d/action/ActionWalk.cpp | 4 +- src/kiwano/2d/action/Animation.cpp | 4 +- src/kiwano/base/ObjectPool.cpp | 60 ---------------------- src/kiwano/base/ObjectPool.h | 70 -------------------------- src/kiwano/base/RefObject.cpp | 53 +++++++++++++------ src/kiwano/base/RefObject.h | 32 ++++-------- src/kiwano/base/RefPtr.h | 7 +-- src/kiwano/core/Allocator.cpp | 2 +- src/kiwano/core/Allocator.h | 15 ++---- src/kiwano/core/Common.h | 43 +++++++++------- src/kiwano/platform/Application.cpp | 7 --- src/kiwano/platform/Input.h | 2 +- src/kiwano/render/Color.h | 1 - src/kiwano/render/TextureCache.h | 2 +- src/kiwano/utils/Logger.h | 2 +- src/kiwano/utils/ResourceCache.h | 2 +- src/kiwano/utils/TaskScheduler.h | 2 +- src/kiwano/utils/UserData.h | 2 +- 24 files changed, 113 insertions(+), 255 deletions(-) delete mode 100644 src/kiwano/base/ObjectPool.cpp delete mode 100644 src/kiwano/base/ObjectPool.h diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index a8e1dbe0..fb5ae081 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -16,7 +16,6 @@ - @@ -134,7 +133,6 @@ - diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index fd77980d..b8ecfc9d 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -339,9 +339,6 @@ utils - - base - core @@ -575,9 +572,6 @@ utils - - base - 2d\action diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index faee8709..70e31ca4 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -258,18 +258,18 @@ bool Actor::HandleEvent(Event* evt) { hover_ = true; - auto hover = new (autogc) MouseHoverEvent; + MouseHoverEventPtr hover = new MouseHoverEvent; hover->pos = mouse_evt->pos; - HandleEvent(hover); + HandleEvent(hover.Get()); } else if (hover_ && !contains) { hover_ = false; pressed_ = false; - auto out = new (autogc) MouseOutEvent; + MouseOutEventPtr out = new MouseOutEvent; out->pos = mouse_evt->pos; - HandleEvent(out); + HandleEvent(out.Get()); } } @@ -284,10 +284,10 @@ bool Actor::HandleEvent(Event* evt) auto mouse_up_evt = dynamic_cast(evt); - auto click = new (autogc) MouseClickEvent; - click->pos = mouse_up_evt->pos; - click->button = mouse_up_evt->button; - HandleEvent(click); + MouseClickEventPtr click = new MouseClickEvent; + click->pos = mouse_up_evt->pos; + click->button = mouse_up_evt->button; + HandleEvent(click.Get()); } } return true; diff --git a/src/kiwano/2d/action/ActionDelay.cpp b/src/kiwano/2d/action/ActionDelay.cpp index d4fefd27..1a9017e8 100644 --- a/src/kiwano/2d/action/ActionDelay.cpp +++ b/src/kiwano/2d/action/ActionDelay.cpp @@ -35,7 +35,7 @@ ActionDelayEntity::ActionDelayEntity(Duration delay) ActionDelayEntity* ActionDelayEntity::Clone() const { - auto ptr = new (autogc) ActionDelayEntity(GetDelay()); + ActionDelayEntity* ptr = new ActionDelayEntity(GetDelay()); DoClone(ptr); return ptr; } diff --git a/src/kiwano/2d/action/ActionGroup.cpp b/src/kiwano/2d/action/ActionGroup.cpp index e1841b03..7dd6292f 100644 --- a/src/kiwano/2d/action/ActionGroup.cpp +++ b/src/kiwano/2d/action/ActionGroup.cpp @@ -123,7 +123,7 @@ ActionGroupEntity* ActionGroupEntity::Clone() const actions.push_back(action->Clone()); } } - auto ptr = new (autogc) ActionGroupEntity(actions, parallel_); + ActionGroupEntity* ptr = new ActionGroupEntity(actions, parallel_); DoClone(ptr); return ptr; } @@ -138,7 +138,7 @@ ActionGroupEntity* ActionGroupEntity::Reverse() const actions.push_back(action->Reverse()); } } - auto ptr = new (autogc) ActionGroupEntity(actions, parallel_); + ActionGroupEntity* ptr = new ActionGroupEntity(actions, parallel_); DoClone(ptr); return ptr; } diff --git a/src/kiwano/2d/action/ActionTween.cpp b/src/kiwano/2d/action/ActionTween.cpp index 14d40da5..421ff940 100644 --- a/src/kiwano/2d/action/ActionTween.cpp +++ b/src/kiwano/2d/action/ActionTween.cpp @@ -170,14 +170,14 @@ void ActionMoveByEntity::UpdateTween(Actor* target, float percent) ActionMoveByEntity* ActionMoveByEntity::Clone() const { - auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), displacement_); + ActionMoveByEntity* ptr = new ActionMoveByEntity(GetDuration(), displacement_); DoClone(ptr); return ptr; } ActionMoveByEntity* ActionMoveByEntity::Reverse() const { - auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), -displacement_); + ActionMoveByEntity* ptr = new ActionMoveByEntity(GetDuration(), -displacement_); DoClone(ptr); return ptr; } @@ -190,7 +190,7 @@ ActionMoveToEntity::ActionMoveToEntity(Duration duration, const Point& distinati ActionMoveToEntity* ActionMoveToEntity::Clone() const { - auto ptr = new (autogc) ActionMoveToEntity(GetDuration(), distination_); + ActionMoveToEntity* ptr = new ActionMoveToEntity(GetDuration(), distination_); DoClone(ptr); return ptr; } @@ -215,14 +215,14 @@ ActionJumpByEntity::ActionJumpByEntity(Duration duration, const Vec2& displaceme ActionJumpByEntity* ActionJumpByEntity::Clone() const { - auto ptr = new (autogc) ActionJumpByEntity(GetDuration(), displacement_, height_, jump_count_); + ActionJumpByEntity* ptr = new ActionJumpByEntity(GetDuration(), displacement_, height_, jump_count_); DoClone(ptr); return ptr; } ActionJumpByEntity* ActionJumpByEntity::Reverse() const { - auto ptr = new (autogc) ActionJumpByEntity(GetDuration(), -displacement_, height_, jump_count_); + ActionJumpByEntity* ptr = new ActionJumpByEntity(GetDuration(), -displacement_, height_, jump_count_); DoClone(ptr); return ptr; } @@ -259,7 +259,7 @@ ActionJumpToEntity::ActionJumpToEntity(Duration duration, const Point& distinati ActionJumpToEntity* ActionJumpToEntity::Clone() const { - auto ptr = new (autogc) ActionJumpToEntity(GetDuration(), distination_, height_, jump_count_); + ActionJumpToEntity* ptr = new ActionJumpToEntity(GetDuration(), distination_, height_, jump_count_); DoClone(ptr); return ptr; } @@ -299,14 +299,14 @@ void ActionScaleByEntity::UpdateTween(Actor* target, float percent) ActionScaleByEntity* ActionScaleByEntity::Clone() const { - auto ptr = new (autogc) ActionScaleByEntity(GetDuration(), delta_x_, delta_y_); + ActionScaleByEntity* ptr = new ActionScaleByEntity(GetDuration(), delta_x_, delta_y_); DoClone(ptr); return ptr; } ActionScaleByEntity* ActionScaleByEntity::Reverse() const { - auto ptr = new (autogc) ActionScaleByEntity(GetDuration(), -delta_x_, -delta_y_); + ActionScaleByEntity* ptr = new ActionScaleByEntity(GetDuration(), -delta_x_, -delta_y_); DoClone(ptr); return ptr; } @@ -320,7 +320,7 @@ ActionScaleToEntity::ActionScaleToEntity(Duration duration, float scale_x, float ActionScaleToEntity* ActionScaleToEntity::Clone() const { - auto ptr = new (autogc) ActionScaleToEntity(GetDuration(), end_scale_x_, end_scale_y_); + ActionScaleToEntity* ptr = new ActionScaleToEntity(GetDuration(), end_scale_x_, end_scale_y_); DoClone(ptr); return ptr; } @@ -360,7 +360,7 @@ void ActionFadeToEntity::UpdateTween(Actor* target, float percent) ActionFadeToEntity* ActionFadeToEntity::Clone() const { - auto ptr = new (autogc) ActionFadeToEntity(GetDuration(), end_val_); + ActionFadeToEntity* ptr = new ActionFadeToEntity(GetDuration(), end_val_); DoClone(ptr); return ptr; } @@ -395,14 +395,14 @@ void ActionRotateByEntity::UpdateTween(Actor* target, float percent) ActionRotateByEntity* ActionRotateByEntity::Clone() const { - auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), delta_val_); + ActionRotateByEntity* ptr = new ActionRotateByEntity(GetDuration(), delta_val_); DoClone(ptr); return ptr; } ActionRotateByEntity* ActionRotateByEntity::Reverse() const { - auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), -delta_val_); + ActionRotateByEntity* ptr = new ActionRotateByEntity(GetDuration(), -delta_val_); DoClone(ptr); return ptr; } @@ -415,7 +415,7 @@ ActionRotateToEntity::ActionRotateToEntity(Duration duration, float rotation) ActionRotateToEntity* ActionRotateToEntity::Clone() const { - auto ptr = new (autogc) ActionRotateToEntity(GetDuration(), end_val_); + ActionRotateToEntity* ptr = new ActionRotateToEntity(GetDuration(), end_val_); DoClone(ptr); return ptr; } @@ -438,7 +438,7 @@ ActionCustomEntity::ActionCustomEntity(Duration duration, ActionCustom::TweenFun ActionCustomEntity* ActionCustomEntity::Clone() const { - auto ptr = new (autogc) ActionCustomEntity(GetDuration(), tween_func_); + ActionCustomEntity* ptr = new ActionCustomEntity(GetDuration(), tween_func_); DoClone(ptr); return ptr; } diff --git a/src/kiwano/2d/action/ActionWalk.cpp b/src/kiwano/2d/action/ActionWalk.cpp index 8b0be7cd..71d1c3d7 100644 --- a/src/kiwano/2d/action/ActionWalk.cpp +++ b/src/kiwano/2d/action/ActionWalk.cpp @@ -41,14 +41,14 @@ ActionWalkEntity::ActionWalkEntity(Duration duration, ShapePtr path, bool rotati ActionWalkEntity* ActionWalkEntity::Clone() const { - auto ptr = new (autogc) ActionWalkEntity(GetDuration(), path_, rotating_, start_, end_); + ActionWalkEntity* ptr = new ActionWalkEntity(GetDuration(), path_, rotating_, start_, end_); DoClone(ptr); return ptr; } ActionWalkEntity* ActionWalkEntity::Reverse() const { - auto ptr = new (autogc) ActionWalkEntity(GetDuration(), path_, rotating_, end_, start_); + ActionWalkEntity* ptr = new ActionWalkEntity(GetDuration(), path_, rotating_, end_, start_); DoClone(ptr); return ptr; } diff --git a/src/kiwano/2d/action/Animation.cpp b/src/kiwano/2d/action/Animation.cpp index 3afd55ff..2ac98c25 100644 --- a/src/kiwano/2d/action/Animation.cpp +++ b/src/kiwano/2d/action/Animation.cpp @@ -87,14 +87,14 @@ void AnimationEntity::UpdateTween(Actor* target, float percent) AnimationEntity* AnimationEntity::Clone() const { - auto ptr = new (autogc) AnimationEntity(GetDuration(), frame_seq_); + AnimationEntity* ptr = new AnimationEntity(GetDuration(), frame_seq_); DoClone(ptr); return ptr; } AnimationEntity* AnimationEntity::Reverse() const { - auto ptr = new (autogc) AnimationEntity(GetDuration(), nullptr); + AnimationEntity* ptr = new AnimationEntity(GetDuration(), nullptr); DoClone(ptr); if (frame_seq_) diff --git a/src/kiwano/base/ObjectPool.cpp b/src/kiwano/base/ObjectPool.cpp deleted file mode 100644 index 478cd48b..00000000 --- a/src/kiwano/base/ObjectPool.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2016-2018 Kiwano - Nomango -// -// 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 - -namespace kiwano -{ - -ObjectPool::ObjectPool() -{ -} - -void ObjectPool::AddObject(RefObject* obj) -{ - if (obj) - { - std::lock_guard lock(mutex_); - if (!Contains(obj)) - { - objects_.push_back(obj); - } - } -} - -bool ObjectPool::Contains(RefObject* obj) const -{ - return std::find(objects_.begin(), objects_.end(), obj) != objects_.end(); -} - -void ObjectPool::Clear() -{ - Vector copied; - - { - std::lock_guard lock(mutex_); - copied = std::move(objects_); - } - - for (auto obj : copied) - obj->Release(); -} - -} // namespace kiwano diff --git a/src/kiwano/base/ObjectPool.h b/src/kiwano/base/ObjectPool.h deleted file mode 100644 index a45a3375..00000000 --- a/src/kiwano/base/ObjectPool.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2016-2018 Kiwano - Nomango -// -// 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. - -#pragma once -#include -#include -#include - -namespace kiwano -{ - -/** - * \~chinese - * @brief 对象池 - */ -class KGE_API ObjectPool : public Singleton -{ - friend Singleton; - -public: - ObjectPool(); - - /** - * \~chinese - * @brief 添加对象到内存池 - * @param[in] obj 引用计数对象 - */ - void AddObject(RefObject* obj); - - /** - * \~chinese - * @brief 判断对象是否在对象池中 - * @param[in] obj 引用计数对象 - */ - bool Contains(RefObject* obj) const; - - /** - * \~chinese - * @brief 清空所有对象 - */ - void Clear(); - -private: - ObjectPool(const ObjectPool&) = delete; - - ObjectPool& operator=(const ObjectPool&) = delete; - -private: - std::mutex mutex_; - Vector objects_; -}; - -} // namespace kiwano diff --git a/src/kiwano/base/RefObject.cpp b/src/kiwano/base/RefObject.cpp index 04464071..f4eb7971 100644 --- a/src/kiwano/base/RefObject.cpp +++ b/src/kiwano/base/RefObject.cpp @@ -19,15 +19,12 @@ // THE SOFTWARE. #include -#include namespace kiwano { -autogc_t const autogc; - RefObject::RefObject() - : ref_count_(1) + : ref_count_(0) { } @@ -47,22 +44,17 @@ void RefObject::Release() } } -void RefObject::AutoRelease() +uint32_t RefObject::GetRefCount() const { - ObjectPool::GetInstance().AddObject(this); + return ref_count_.load(); } -void* RefObject::operator new(std::size_t size) -{ - return memory::Alloc(size); -} - -void* RefObject::operator new(std::size_t size, autogc_t const&) +void* RefObject::operator new(size_t size) { void* ptr = memory::Alloc(size); - if (ptr) + if (!ptr) { - ObjectPool::GetInstance().AddObject((ObjectBase*)ptr); + throw std::bad_alloc(); } return ptr; } @@ -72,9 +64,38 @@ void RefObject::operator delete(void* ptr) memory::Free(ptr); } -void RefObject::operator delete(void* ptr, autogc_t const&) +void* RefObject::operator new(size_t size, std::nothrow_t const&) { - memory::Free(ptr); + try + { + void* ptr = memory::Alloc(size); + return ptr; + } + catch (...) + { + } + return nullptr; +} + +void RefObject::operator delete(void* ptr, std::nothrow_t const&) +{ + try + { + memory::Free(ptr); + } + catch (...) + { + } +} + +void* RefObject::operator new(size_t size, void* ptr) +{ + return ::operator new(size, ptr); +} + +void RefObject::operator delete(void* ptr, void* place) noexcept +{ + ::operator delete(ptr, place); } } // namespace kiwano diff --git a/src/kiwano/base/RefObject.h b/src/kiwano/base/RefObject.h index ede57076..a5975fc6 100644 --- a/src/kiwano/base/RefObject.h +++ b/src/kiwano/base/RefObject.h @@ -25,13 +25,6 @@ namespace kiwano { -struct autogc_t -{ - autogc_t() = default; -}; - -extern autogc_t const autogc; - /** * \~chinese * @brief 引用计数器 @@ -47,34 +40,29 @@ public: /// @brief 减少引用计数 void Release(); - /// \~chinese - /// @brief 自动释放 - void AutoRelease(); - /// \~chinese /// @brief 获取引用计数 uint32_t GetRefCount() const; - void* operator new(std::size_t size); + static void* operator new(size_t size); - void* operator new(std::size_t size, autogc_t const&); + static void operator delete(void* ptr); - void operator delete(void* ptr); + static void* operator new(size_t size, std::nothrow_t const&) noexcept; - void operator delete(void* ptr, autogc_t const&); + static void operator delete(void* ptr, std::nothrow_t const&) noexcept; + + static void* operator new(size_t size, void* ptr) noexcept; + + static void operator delete(void* ptr, void* place) noexcept; + + virtual ~RefObject(); protected: RefObject(); - virtual ~RefObject(); - private: std::atomic ref_count_; }; -inline uint32_t RefObject::GetRefCount() const -{ - return ref_count_.load(); -} - } // namespace kiwano diff --git a/src/kiwano/base/RefPtr.h b/src/kiwano/base/RefPtr.h index 4cfff9c2..e684d05e 100644 --- a/src/kiwano/base/RefPtr.h +++ b/src/kiwano/base/RefPtr.h @@ -53,12 +53,7 @@ template inline RefPtr<_Ty> MakePtr(_Args&&... args) { static_assert(std::is_base_of::value, "_Ty must be derived from RefObject"); - - RefPtr<_Ty> ptr; - - _Ty** pptr = ptr.GetAddressOfAndRelease(); - (*pptr) = new _Ty(std::forward<_Args>(args)...); - return ptr; + return RefPtr<_Ty>(new _Ty(std::forward<_Args>(args)...)); } /// \~chinese diff --git a/src/kiwano/core/Allocator.cpp b/src/kiwano/core/Allocator.cpp index d903f52f..2215c75f 100644 --- a/src/kiwano/core/Allocator.cpp +++ b/src/kiwano/core/Allocator.cpp @@ -37,7 +37,7 @@ MemoryAllocator* GetGlobalAllocator() return ::operator new(size); } - virtual void Free(void* ptr, size_t) override + virtual void Free(void* ptr) override { ::operator delete(ptr); } diff --git a/src/kiwano/core/Allocator.h b/src/kiwano/core/Allocator.h index e84d3592..ce59d8fe 100644 --- a/src/kiwano/core/Allocator.h +++ b/src/kiwano/core/Allocator.h @@ -40,7 +40,7 @@ public: /// \~chinese /// @brief 释放内存 - virtual void Free(void* ptr, size_t size = 0) = 0; + virtual void Free(void* ptr) = 0; }; /// \~chinese @@ -65,13 +65,6 @@ inline void Free(void* ptr) memory::GetAllocator()->Free(ptr); } -/// \~chinese -/// @brief 使用当前内存分配器释放内存 -inline void Free(void* ptr, size_t size) -{ - memory::GetAllocator()->Free(ptr, size); -} - } // namespace memory /// \~chinese @@ -120,13 +113,13 @@ public: inline void deallocate(void* ptr, size_t count) { - memory::Free(ptr, sizeof(_Ty) * count); + memory::Free(ptr /*, sizeof(_Ty) * count */); } template - inline void construct(_UTy* ptr, _Args&&... args) + inline void construct(_UTy* const ptr, _Args&&... args) { - ::new (ptr) _Ty(std::forward<_Args>(args)...); + ::new (const_cast(static_cast(ptr))) _Ty(std::forward<_Args>(args)...); } template diff --git a/src/kiwano/core/Common.h b/src/kiwano/core/Common.h index af768354..5a1eaf00 100644 --- a/src/kiwano/core/Common.h +++ b/src/kiwano/core/Common.h @@ -56,23 +56,28 @@ using WideStringStream = std::wstringstream; /// \~chinese /// @brief 线性数组容器 -template -using Vector = std::vector<_Ty, _Args...>; +template > +using Vector = std::vector<_Ty, _Alloc>; /// \~chinese /// @brief 链表容器 -template -using List = std::list<_Ty, _Args...>; +template > +using List = std::list<_Ty, _Alloc>; + +/// \~chinese +/// @brief 双端队列容器 +template > +using Deque = std::deque<_Ty, _Alloc>; /// \~chinese /// @brief 队列容器 -template -using Queue = std::queue<_Ty, _Args...>; +template > +using Queue = std::queue<_Ty, _Container>; /// \~chinese /// @brief 集合容器 -template -using Set = std::set<_Ty, _Args...>; +template , typename _Alloc = std::allocator<_Kty>> +using Set = std::set<_Kty, _Compare, _Alloc>; /// \~chinese /// @brief 对容器 @@ -81,23 +86,25 @@ using Pair = std::pair<_Ty1, _Ty2>; /// \~chinese /// @brief 无序集合容器 -template -using UnorderedSet = std::unordered_set<_Ty, _Args...>; +template , typename _Keq = std::equal_to<_Kty>, + typename _Alloc = std::allocator<_Kty>> +using UnorderedSet = std::unordered_set<_Kty, _Hash, _Keq, _Alloc>; /// \~chinese /// @brief 栈容器 -template -using Stack = std::stack<_Ty, _Args...>; +template > +using Stack = std::stack<_Ty, _Container>; /// \~chinese -/// @brief 字符串容器 -template -using Map = std::map<_Kty, _Ty, _Args...>; +/// @brief 排序关联容器 +template , typename _Alloc = std::allocator>> +using Map = std::map<_Kty, _Ty, _Compare, _Alloc>; /// \~chinese -/// @brief 字符串容器 -template -using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>; +/// @brief 非排序关联容器 +template , typename _Keq = std::equal_to<_Kty>, + typename _Alloc = std::allocator>> +using UnorderedMap = std::unordered_map<_Kty, _Ty, _Hash, _Keq, _Alloc>; /// \~chinese /// @brief 不可拷贝对象 diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index d0a64ca3..9e643004 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -83,9 +82,6 @@ void Application::Run(RunnerPtr runner) // Execute main loop if (!runner->MainLoop(timer_->GetDeltaTime())) running_ = false; - - // Clear objects - ObjectPool::GetInstance().Clear(); } } @@ -137,9 +133,6 @@ void Application::Destroy() // Clear device resources TextureCache::GetInstance().Clear(); Renderer::GetInstance().Destroy(); - - // Clear objects - ObjectPool::GetInstance().Clear(); } void Application::Use(Module& module) diff --git a/src/kiwano/platform/Input.h b/src/kiwano/platform/Input.h index b731e0a5..1b63d734 100644 --- a/src/kiwano/platform/Input.h +++ b/src/kiwano/platform/Input.h @@ -33,7 +33,7 @@ namespace kiwano * \~chinese * @brief 输入设备实例,可获取鼠标和键盘的按键状态 */ -class KGE_API Input +class KGE_API Input final : public Singleton , public Module { diff --git a/src/kiwano/render/Color.h b/src/kiwano/render/Color.h index b16484a8..d25d7cf8 100644 --- a/src/kiwano/render/Color.h +++ b/src/kiwano/render/Color.h @@ -20,7 +20,6 @@ #pragma once #include -#include namespace kiwano { diff --git a/src/kiwano/render/TextureCache.h b/src/kiwano/render/TextureCache.h index 4f82832c..391755ab 100644 --- a/src/kiwano/render/TextureCache.h +++ b/src/kiwano/render/TextureCache.h @@ -33,7 +33,7 @@ namespace kiwano * \~chinese * @brief 纹理缓存 */ -class KGE_API TextureCache : public Singleton +class KGE_API TextureCache final : public Singleton { friend Singleton; diff --git a/src/kiwano/utils/Logger.h b/src/kiwano/utils/Logger.h index 4e666064..7e363831 100644 --- a/src/kiwano/utils/Logger.h +++ b/src/kiwano/utils/Logger.h @@ -218,7 +218,7 @@ private: * \~chinese * @brief 日志记录器 */ -class KGE_API Logger : public Singleton +class KGE_API Logger final : public Singleton { friend Singleton; diff --git a/src/kiwano/utils/ResourceCache.h b/src/kiwano/utils/ResourceCache.h index 5b1aee58..feed7bbc 100644 --- a/src/kiwano/utils/ResourceCache.h +++ b/src/kiwano/utils/ResourceCache.h @@ -32,7 +32,7 @@ namespace kiwano /// \~chinese /// @brief 资源缓存 /// @details 资源缓存 -class KGE_API ResourceCache : public Singleton +class KGE_API ResourceCache final : public Singleton { friend Singleton; diff --git a/src/kiwano/utils/TaskScheduler.h b/src/kiwano/utils/TaskScheduler.h index ac091491..cfe9148b 100644 --- a/src/kiwano/utils/TaskScheduler.h +++ b/src/kiwano/utils/TaskScheduler.h @@ -32,7 +32,7 @@ typedef IntrusiveList TaskList; * \~chinese * @brief 任务调度器 */ -class KGE_API TaskScheduler +class KGE_API TaskScheduler : Noncopyable { public: /// \~chinese diff --git a/src/kiwano/utils/UserData.h b/src/kiwano/utils/UserData.h index b8029222..c52f3c7f 100644 --- a/src/kiwano/utils/UserData.h +++ b/src/kiwano/utils/UserData.h @@ -27,7 +27,7 @@ namespace kiwano /// @brief 用户数据 /// @details /// UserData是一个简易的运行时数据库,存放(字符串-值)的键值对,无持久化 -class KGE_API UserData : public Singleton +class KGE_API UserData final : public Singleton { friend Singleton;