remove ObjectPool

This commit is contained in:
Nomango 2020-07-23 17:21:44 +08:00
parent 5a877ccf7b
commit a134a2e952
24 changed files with 113 additions and 255 deletions

View File

@ -16,7 +16,6 @@
<ClInclude Include="..\..\src\kiwano\base\Director.h" /> <ClInclude Include="..\..\src\kiwano\base\Director.h" />
<ClInclude Include="..\..\src\kiwano\base\Module.h" /> <ClInclude Include="..\..\src\kiwano\base\Module.h" />
<ClInclude Include="..\..\src\kiwano\base\ObjectBase.h" /> <ClInclude Include="..\..\src\kiwano\base\ObjectBase.h" />
<ClInclude Include="..\..\src\kiwano\base\ObjectPool.h" />
<ClInclude Include="..\..\src\kiwano\base\RefObject.h" /> <ClInclude Include="..\..\src\kiwano\base\RefObject.h" />
<ClInclude Include="..\..\src\kiwano\base\RefPtr.h" /> <ClInclude Include="..\..\src\kiwano\base\RefPtr.h" />
<ClInclude Include="..\..\src\kiwano\core\Allocator.h" /> <ClInclude Include="..\..\src\kiwano\core\Allocator.h" />
@ -134,7 +133,6 @@
<ClCompile Include="..\..\src\kiwano\base\Director.cpp" /> <ClCompile Include="..\..\src\kiwano\base\Director.cpp" />
<ClCompile Include="..\..\src\kiwano\base\Module.cpp" /> <ClCompile Include="..\..\src\kiwano\base\Module.cpp" />
<ClCompile Include="..\..\src\kiwano\base\ObjectBase.cpp" /> <ClCompile Include="..\..\src\kiwano\base\ObjectBase.cpp" />
<ClCompile Include="..\..\src\kiwano\base\ObjectPool.cpp" />
<ClCompile Include="..\..\src\kiwano\base\RefObject.cpp" /> <ClCompile Include="..\..\src\kiwano\base\RefObject.cpp" />
<ClCompile Include="..\..\src\kiwano\core\Allocator.cpp" /> <ClCompile Include="..\..\src\kiwano\core\Allocator.cpp" />
<ClCompile Include="..\..\src\kiwano\core\Exception.cpp" /> <ClCompile Include="..\..\src\kiwano\core\Exception.cpp" />

View File

@ -339,9 +339,6 @@
<ClInclude Include="..\..\src\kiwano\utils\ConfigIni.h"> <ClInclude Include="..\..\src\kiwano\utils\ConfigIni.h">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\kiwano\base\ObjectPool.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\core\Defer.h"> <ClInclude Include="..\..\src\kiwano\core\Defer.h">
<Filter>core</Filter> <Filter>core</Filter>
</ClInclude> </ClInclude>
@ -575,9 +572,6 @@
<ClCompile Include="..\..\src\kiwano\utils\ConfigIni.cpp"> <ClCompile Include="..\..\src\kiwano\utils\ConfigIni.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\kiwano\base\ObjectPool.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\action\Action.cpp"> <ClCompile Include="..\..\src\kiwano\2d\action\Action.cpp">
<Filter>2d\action</Filter> <Filter>2d\action</Filter>
</ClCompile> </ClCompile>

View File

@ -258,18 +258,18 @@ bool Actor::HandleEvent(Event* evt)
{ {
hover_ = true; hover_ = true;
auto hover = new (autogc) MouseHoverEvent; MouseHoverEventPtr hover = new MouseHoverEvent;
hover->pos = mouse_evt->pos; hover->pos = mouse_evt->pos;
HandleEvent(hover); HandleEvent(hover.Get());
} }
else if (hover_ && !contains) else if (hover_ && !contains)
{ {
hover_ = false; hover_ = false;
pressed_ = false; pressed_ = false;
auto out = new (autogc) MouseOutEvent; MouseOutEventPtr out = new MouseOutEvent;
out->pos = mouse_evt->pos; 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<MouseUpEvent*>(evt); auto mouse_up_evt = dynamic_cast<MouseUpEvent*>(evt);
auto click = new (autogc) MouseClickEvent; MouseClickEventPtr click = new MouseClickEvent;
click->pos = mouse_up_evt->pos; click->pos = mouse_up_evt->pos;
click->button = mouse_up_evt->button; click->button = mouse_up_evt->button;
HandleEvent(click); HandleEvent(click.Get());
} }
} }
return true; return true;

View File

@ -35,7 +35,7 @@ ActionDelayEntity::ActionDelayEntity(Duration delay)
ActionDelayEntity* ActionDelayEntity::Clone() const ActionDelayEntity* ActionDelayEntity::Clone() const
{ {
auto ptr = new (autogc) ActionDelayEntity(GetDelay()); ActionDelayEntity* ptr = new ActionDelayEntity(GetDelay());
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }

View File

@ -123,7 +123,7 @@ ActionGroupEntity* ActionGroupEntity::Clone() const
actions.push_back(action->Clone()); actions.push_back(action->Clone());
} }
} }
auto ptr = new (autogc) ActionGroupEntity(actions, parallel_); ActionGroupEntity* ptr = new ActionGroupEntity(actions, parallel_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
@ -138,7 +138,7 @@ ActionGroupEntity* ActionGroupEntity::Reverse() const
actions.push_back(action->Reverse()); actions.push_back(action->Reverse());
} }
} }
auto ptr = new (autogc) ActionGroupEntity(actions, parallel_); ActionGroupEntity* ptr = new ActionGroupEntity(actions, parallel_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }

View File

@ -170,14 +170,14 @@ void ActionMoveByEntity::UpdateTween(Actor* target, float percent)
ActionMoveByEntity* ActionMoveByEntity::Clone() const ActionMoveByEntity* ActionMoveByEntity::Clone() const
{ {
auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), displacement_); ActionMoveByEntity* ptr = new ActionMoveByEntity(GetDuration(), displacement_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
ActionMoveByEntity* ActionMoveByEntity::Reverse() const ActionMoveByEntity* ActionMoveByEntity::Reverse() const
{ {
auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), -displacement_); ActionMoveByEntity* ptr = new ActionMoveByEntity(GetDuration(), -displacement_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
@ -190,7 +190,7 @@ ActionMoveToEntity::ActionMoveToEntity(Duration duration, const Point& distinati
ActionMoveToEntity* ActionMoveToEntity::Clone() const ActionMoveToEntity* ActionMoveToEntity::Clone() const
{ {
auto ptr = new (autogc) ActionMoveToEntity(GetDuration(), distination_); ActionMoveToEntity* ptr = new ActionMoveToEntity(GetDuration(), distination_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
@ -215,14 +215,14 @@ ActionJumpByEntity::ActionJumpByEntity(Duration duration, const Vec2& displaceme
ActionJumpByEntity* ActionJumpByEntity::Clone() const 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); DoClone(ptr);
return ptr; return ptr;
} }
ActionJumpByEntity* ActionJumpByEntity::Reverse() const 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); DoClone(ptr);
return ptr; return ptr;
} }
@ -259,7 +259,7 @@ ActionJumpToEntity::ActionJumpToEntity(Duration duration, const Point& distinati
ActionJumpToEntity* ActionJumpToEntity::Clone() const 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); DoClone(ptr);
return ptr; return ptr;
} }
@ -299,14 +299,14 @@ void ActionScaleByEntity::UpdateTween(Actor* target, float percent)
ActionScaleByEntity* ActionScaleByEntity::Clone() const 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); DoClone(ptr);
return ptr; return ptr;
} }
ActionScaleByEntity* ActionScaleByEntity::Reverse() const 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); DoClone(ptr);
return ptr; return ptr;
} }
@ -320,7 +320,7 @@ ActionScaleToEntity::ActionScaleToEntity(Duration duration, float scale_x, float
ActionScaleToEntity* ActionScaleToEntity::Clone() const 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); DoClone(ptr);
return ptr; return ptr;
} }
@ -360,7 +360,7 @@ void ActionFadeToEntity::UpdateTween(Actor* target, float percent)
ActionFadeToEntity* ActionFadeToEntity::Clone() const ActionFadeToEntity* ActionFadeToEntity::Clone() const
{ {
auto ptr = new (autogc) ActionFadeToEntity(GetDuration(), end_val_); ActionFadeToEntity* ptr = new ActionFadeToEntity(GetDuration(), end_val_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
@ -395,14 +395,14 @@ void ActionRotateByEntity::UpdateTween(Actor* target, float percent)
ActionRotateByEntity* ActionRotateByEntity::Clone() const ActionRotateByEntity* ActionRotateByEntity::Clone() const
{ {
auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), delta_val_); ActionRotateByEntity* ptr = new ActionRotateByEntity(GetDuration(), delta_val_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
ActionRotateByEntity* ActionRotateByEntity::Reverse() const ActionRotateByEntity* ActionRotateByEntity::Reverse() const
{ {
auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), -delta_val_); ActionRotateByEntity* ptr = new ActionRotateByEntity(GetDuration(), -delta_val_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
@ -415,7 +415,7 @@ ActionRotateToEntity::ActionRotateToEntity(Duration duration, float rotation)
ActionRotateToEntity* ActionRotateToEntity::Clone() const ActionRotateToEntity* ActionRotateToEntity::Clone() const
{ {
auto ptr = new (autogc) ActionRotateToEntity(GetDuration(), end_val_); ActionRotateToEntity* ptr = new ActionRotateToEntity(GetDuration(), end_val_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
@ -438,7 +438,7 @@ ActionCustomEntity::ActionCustomEntity(Duration duration, ActionCustom::TweenFun
ActionCustomEntity* ActionCustomEntity::Clone() const ActionCustomEntity* ActionCustomEntity::Clone() const
{ {
auto ptr = new (autogc) ActionCustomEntity(GetDuration(), tween_func_); ActionCustomEntity* ptr = new ActionCustomEntity(GetDuration(), tween_func_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }

View File

@ -41,14 +41,14 @@ ActionWalkEntity::ActionWalkEntity(Duration duration, ShapePtr path, bool rotati
ActionWalkEntity* ActionWalkEntity::Clone() const 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); DoClone(ptr);
return ptr; return ptr;
} }
ActionWalkEntity* ActionWalkEntity::Reverse() const 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); DoClone(ptr);
return ptr; return ptr;
} }

View File

@ -87,14 +87,14 @@ void AnimationEntity::UpdateTween(Actor* target, float percent)
AnimationEntity* AnimationEntity::Clone() const AnimationEntity* AnimationEntity::Clone() const
{ {
auto ptr = new (autogc) AnimationEntity(GetDuration(), frame_seq_); AnimationEntity* ptr = new AnimationEntity(GetDuration(), frame_seq_);
DoClone(ptr); DoClone(ptr);
return ptr; return ptr;
} }
AnimationEntity* AnimationEntity::Reverse() const AnimationEntity* AnimationEntity::Reverse() const
{ {
auto ptr = new (autogc) AnimationEntity(GetDuration(), nullptr); AnimationEntity* ptr = new AnimationEntity(GetDuration(), nullptr);
DoClone(ptr); DoClone(ptr);
if (frame_seq_) if (frame_seq_)

View File

@ -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 <kiwano/base/ObjectPool.h>
namespace kiwano
{
ObjectPool::ObjectPool()
{
}
void ObjectPool::AddObject(RefObject* obj)
{
if (obj)
{
std::lock_guard<std::mutex> 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<RefObject*> copied;
{
std::lock_guard<std::mutex> lock(mutex_);
copied = std::move(objects_);
}
for (auto obj : copied)
obj->Release();
}
} // namespace kiwano

View File

@ -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 <kiwano/core/Singleton.h>
#include <kiwano/base/ObjectBase.h>
#include <mutex>
namespace kiwano
{
/**
* \~chinese
* @brief
*/
class KGE_API ObjectPool : public Singleton<ObjectPool>
{
friend Singleton<ObjectPool>;
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<RefObject*> objects_;
};
} // namespace kiwano

View File

@ -19,15 +19,12 @@
// THE SOFTWARE. // THE SOFTWARE.
#include <kiwano/base/RefObject.h> #include <kiwano/base/RefObject.h>
#include <kiwano/base/ObjectPool.h>
namespace kiwano namespace kiwano
{ {
autogc_t const autogc;
RefObject::RefObject() 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) void* RefObject::operator new(size_t size)
{
return memory::Alloc(size);
}
void* RefObject::operator new(std::size_t size, autogc_t const&)
{ {
void* ptr = memory::Alloc(size); void* ptr = memory::Alloc(size);
if (ptr) if (!ptr)
{ {
ObjectPool::GetInstance().AddObject((ObjectBase*)ptr); throw std::bad_alloc();
} }
return ptr; return ptr;
} }
@ -72,9 +64,38 @@ void RefObject::operator delete(void* ptr)
memory::Free(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 } // namespace kiwano

View File

@ -25,13 +25,6 @@
namespace kiwano namespace kiwano
{ {
struct autogc_t
{
autogc_t() = default;
};
extern autogc_t const autogc;
/** /**
* \~chinese * \~chinese
* @brief * @brief
@ -47,34 +40,29 @@ public:
/// @brief 减少引用计数 /// @brief 减少引用计数
void Release(); void Release();
/// \~chinese
/// @brief ×Ô¶¯ÊÍ·Å
void AutoRelease();
/// \~chinese /// \~chinese
/// @brief 获取引用计数 /// @brief 获取引用计数
uint32_t GetRefCount() const; 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: protected:
RefObject(); RefObject();
virtual ~RefObject();
private: private:
std::atomic<uint32_t> ref_count_; std::atomic<uint32_t> ref_count_;
}; };
inline uint32_t RefObject::GetRefCount() const
{
return ref_count_.load();
}
} // namespace kiwano } // namespace kiwano

View File

@ -53,12 +53,7 @@ template <typename _Ty, typename... _Args>
inline RefPtr<_Ty> MakePtr(_Args&&... args) inline RefPtr<_Ty> MakePtr(_Args&&... args)
{ {
static_assert(std::is_base_of<RefObject, _Ty>::value, "_Ty must be derived from RefObject"); static_assert(std::is_base_of<RefObject, _Ty>::value, "_Ty must be derived from RefObject");
return RefPtr<_Ty>(new _Ty(std::forward<_Args>(args)...));
RefPtr<_Ty> ptr;
_Ty** pptr = ptr.GetAddressOfAndRelease();
(*pptr) = new _Ty(std::forward<_Args>(args)...);
return ptr;
} }
/// \~chinese /// \~chinese

View File

@ -37,7 +37,7 @@ MemoryAllocator* GetGlobalAllocator()
return ::operator new(size); return ::operator new(size);
} }
virtual void Free(void* ptr, size_t) override virtual void Free(void* ptr) override
{ {
::operator delete(ptr); ::operator delete(ptr);
} }

View File

@ -40,7 +40,7 @@ public:
/// \~chinese /// \~chinese
/// @brief ÊÍ·ÅÄÚ´æ /// @brief ÊÍ·ÅÄÚ´æ
virtual void Free(void* ptr, size_t size = 0) = 0; virtual void Free(void* ptr) = 0;
}; };
/// \~chinese /// \~chinese
@ -65,13 +65,6 @@ inline void Free(void* ptr)
memory::GetAllocator()->Free(ptr); memory::GetAllocator()->Free(ptr);
} }
/// \~chinese
/// @brief 使用当前内存分配器释放内存
inline void Free(void* ptr, size_t size)
{
memory::GetAllocator()->Free(ptr, size);
}
} // namespace memory } // namespace memory
/// \~chinese /// \~chinese
@ -120,13 +113,13 @@ public:
inline void deallocate(void* ptr, size_t count) inline void deallocate(void* ptr, size_t count)
{ {
memory::Free(ptr, sizeof(_Ty) * count); memory::Free(ptr /*, sizeof(_Ty) * count */);
} }
template <typename _UTy, typename... _Args> template <typename _UTy, typename... _Args>
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<void*>(static_cast<const volatile void*>(ptr))) _Ty(std::forward<_Args>(args)...);
} }
template <typename _UTy> template <typename _UTy>

View File

@ -56,23 +56,28 @@ using WideStringStream = std::wstringstream;
/// \~chinese /// \~chinese
/// @brief 线性数组容器 /// @brief 线性数组容器
template <typename _Ty, typename... _Args> template <typename _Ty, typename _Alloc = std::allocator<_Ty>>
using Vector = std::vector<_Ty, _Args...>; using Vector = std::vector<_Ty, _Alloc>;
/// \~chinese /// \~chinese
/// @brief 链表容器 /// @brief 链表容器
template <typename _Ty, typename... _Args> template <typename _Ty, typename _Alloc = std::allocator<_Ty>>
using List = std::list<_Ty, _Args...>; using List = std::list<_Ty, _Alloc>;
/// \~chinese
/// @brief 双端队列容器
template <typename _Ty, typename _Alloc = std::allocator<_Ty>>
using Deque = std::deque<_Ty, _Alloc>;
/// \~chinese /// \~chinese
/// @brief 队列容器 /// @brief 队列容器
template <typename _Ty, typename... _Args> template <typename _Ty, typename _Container = Deque<_Ty>>
using Queue = std::queue<_Ty, _Args...>; using Queue = std::queue<_Ty, _Container>;
/// \~chinese /// \~chinese
/// @brief 集合容器 /// @brief 集合容器
template <typename _Ty, typename... _Args> template <typename _Kty, typename _Compare = std::less<_Kty>, typename _Alloc = std::allocator<_Kty>>
using Set = std::set<_Ty, _Args...>; using Set = std::set<_Kty, _Compare, _Alloc>;
/// \~chinese /// \~chinese
/// @brief 对容器 /// @brief 对容器
@ -81,23 +86,25 @@ using Pair = std::pair<_Ty1, _Ty2>;
/// \~chinese /// \~chinese
/// @brief 无序集合容器 /// @brief 无序集合容器
template <typename _Ty, typename... _Args> template <typename _Kty, typename _Hash = std::hash<_Kty>, typename _Keq = std::equal_to<_Kty>,
using UnorderedSet = std::unordered_set<_Ty, _Args...>; typename _Alloc = std::allocator<_Kty>>
using UnorderedSet = std::unordered_set<_Kty, _Hash, _Keq, _Alloc>;
/// \~chinese /// \~chinese
/// @brief 栈容器 /// @brief 栈容器
template <typename _Ty, typename... _Args> template <typename _Ty, typename _Container = Deque<_Ty>>
using Stack = std::stack<_Ty, _Args...>; using Stack = std::stack<_Ty, _Container>;
/// \~chinese /// \~chinese
/// @brief ×Ö·û´®ÈÝÆ÷ /// @brief 排序关联容器
template <typename _Kty, typename _Ty, typename... _Args> template <typename _Kty, typename _Ty, typename _Compare = std::less<_Kty>, typename _Alloc = std::allocator<Pair<const _Kty, _Ty>>>
using Map = std::map<_Kty, _Ty, _Args...>; using Map = std::map<_Kty, _Ty, _Compare, _Alloc>;
/// \~chinese /// \~chinese
/// @brief ×Ö·û´®ÈÝÆ÷ /// @brief 非排序关联容器
template <typename _Kty, typename _Ty, typename... _Args> template <typename _Kty, typename _Ty, typename _Hash = std::hash<_Kty>, typename _Keq = std::equal_to<_Kty>,
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>; typename _Alloc = std::allocator<Pair<const _Kty, _Ty>>>
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Hash, _Keq, _Alloc>;
/// \~chinese /// \~chinese
/// @brief 不可拷贝对象 /// @brief 不可拷贝对象

View File

@ -21,7 +21,6 @@
#include <kiwano/platform/Application.h> #include <kiwano/platform/Application.h>
#include <kiwano/core/Defer.h> #include <kiwano/core/Defer.h>
#include <kiwano/base/Director.h> #include <kiwano/base/Director.h>
#include <kiwano/base/ObjectPool.h>
#include <kiwano/render/Renderer.h> #include <kiwano/render/Renderer.h>
#include <kiwano/render/TextureCache.h> #include <kiwano/render/TextureCache.h>
#include <kiwano/utils/ResourceCache.h> #include <kiwano/utils/ResourceCache.h>
@ -83,9 +82,6 @@ void Application::Run(RunnerPtr runner)
// Execute main loop // Execute main loop
if (!runner->MainLoop(timer_->GetDeltaTime())) if (!runner->MainLoop(timer_->GetDeltaTime()))
running_ = false; running_ = false;
// Clear objects
ObjectPool::GetInstance().Clear();
} }
} }
@ -137,9 +133,6 @@ void Application::Destroy()
// Clear device resources // Clear device resources
TextureCache::GetInstance().Clear(); TextureCache::GetInstance().Clear();
Renderer::GetInstance().Destroy(); Renderer::GetInstance().Destroy();
// Clear objects
ObjectPool::GetInstance().Clear();
} }
void Application::Use(Module& module) void Application::Use(Module& module)

View File

@ -33,7 +33,7 @@ namespace kiwano
* \~chinese * \~chinese
* @brief * @brief
*/ */
class KGE_API Input class KGE_API Input final
: public Singleton<Input> : public Singleton<Input>
, public Module , public Module
{ {

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/macros.h>
namespace kiwano namespace kiwano
{ {

View File

@ -33,7 +33,7 @@ namespace kiwano
* \~chinese * \~chinese
* @brief * @brief
*/ */
class KGE_API TextureCache : public Singleton<TextureCache> class KGE_API TextureCache final : public Singleton<TextureCache>
{ {
friend Singleton<TextureCache>; friend Singleton<TextureCache>;

View File

@ -218,7 +218,7 @@ private:
* \~chinese * \~chinese
* @brief * @brief
*/ */
class KGE_API Logger : public Singleton<Logger> class KGE_API Logger final : public Singleton<Logger>
{ {
friend Singleton<Logger>; friend Singleton<Logger>;

View File

@ -32,7 +32,7 @@ namespace kiwano
/// \~chinese /// \~chinese
/// @brief ×ÊÔ´»º´æ /// @brief ×ÊÔ´»º´æ
/// @details ×ÊÔ´»º´æ /// @details ×ÊÔ´»º´æ
class KGE_API ResourceCache : public Singleton<ResourceCache> class KGE_API ResourceCache final : public Singleton<ResourceCache>
{ {
friend Singleton<ResourceCache>; friend Singleton<ResourceCache>;

View File

@ -32,7 +32,7 @@ typedef IntrusiveList<TaskPtr> TaskList;
* \~chinese * \~chinese
* @brief * @brief
*/ */
class KGE_API TaskScheduler class KGE_API TaskScheduler : Noncopyable
{ {
public: public:
/// \~chinese /// \~chinese

View File

@ -27,7 +27,7 @@ namespace kiwano
/// @brief 用户数据 /// @brief 用户数据
/// @details /// @details
/// UserData是一个简易的运行时数据库存放字符串-值)的键值对,无持久化 /// UserData是一个简易的运行时数据库存放字符串-值)的键值对,无持久化
class KGE_API UserData : public Singleton<UserData> class KGE_API UserData final : public Singleton<UserData>
{ {
friend Singleton<UserData>; friend Singleton<UserData>;