From 29f7d35844569400527c6783471c0befe21d5b0a Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Sat, 19 May 2018 01:10:37 +0800 Subject: [PATCH] =?UTF-8?q?ObjectManager=E6=94=B9=E4=B8=BAGC=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/Animate.cpp | 14 +-- core/{Common => Action}/Animation.cpp | 14 +-- core/Action/CallFunc.cpp | 6 +- core/Action/Delay.cpp | 6 +- core/Action/JumpBy.cpp | 6 +- core/Action/JumpTo.cpp | 4 +- core/Action/Loop.cpp | 8 +- core/Action/MoveBy.cpp | 6 +- core/Action/MoveTo.cpp | 4 +- core/Action/OpacityBy.cpp | 6 +- core/Action/OpacityTo.cpp | 4 +- core/Action/RotateBy.cpp | 6 +- core/Action/RotateTo.cpp | 4 +- core/Action/ScaleBy.cpp | 8 +- core/Action/ScaleTo.cpp | 6 +- core/Action/Sequence.cpp | 10 +- core/Action/Spawn.cpp | 10 +- .../ObjectManager.cpp => Base/GC.cpp} | 21 ++-- core/Base/Game.cpp | 4 +- core/Collider/ColliderCircle.cpp | 6 +- core/Collider/ColliderEllipse.cpp | 6 +- core/Collider/ColliderRect.cpp | 6 +- core/Common/Image.cpp | 10 +- core/Common/Object.cpp | 4 +- core/Common/Scene.cpp | 4 +- core/Manager/ActionManager.cpp | 4 +- core/Manager/ColliderManager.cpp | 2 +- core/Manager/SceneManager.cpp | 10 +- core/Node/Button.cpp | 10 +- core/Node/ButtonToggle.cpp | 10 +- core/Node/Menu.cpp | 4 +- core/Node/Node.cpp | 12 +-- core/Node/Shape/Circle.cpp | 6 +- core/Node/Shape/Ellipse.cpp | 6 +- core/Node/Shape/Rect.cpp | 6 +- core/Node/Shape/RoundRect.cpp | 6 +- core/Node/Sprite.cpp | 20 ++-- core/Node/Text.cpp | 4 +- core/Tool/Music.cpp | 6 +- core/Transition/Transition.cpp | 4 +- core/Transition/TransitionEmerge.cpp | 2 +- core/Transition/TransitionFade.cpp | 4 +- core/Transition/TransitionMove.cpp | 2 +- core/e2daction.h | 74 +++++++++++++ core/e2dbase.h | 61 +++++++++++ core/e2dcollider.h | 4 +- core/e2dcommon.h | 101 ------------------ core/e2dmanager.h | 23 ---- project/vs2017/Easy2D.vcxproj | 4 +- project/vs2017/Easy2D.vcxproj.filters | 12 +-- 50 files changed, 298 insertions(+), 282 deletions(-) rename core/{Common => Action}/Animation.cpp (83%) rename core/{Manager/ObjectManager.cpp => Base/GC.cpp} (66%) diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp index 6fa85f00..64eae462 100644 --- a/core/Action/Animate.cpp +++ b/core/Action/Animate.cpp @@ -15,12 +15,12 @@ e2d::Animate::Animate(Animation * animation) e2d::Animate * e2d::Animate::create() { - return Create(); + return GC::create(); } e2d::Animate * e2d::Animate::create(Animation * animation) { - return Create(animation); + return GC::create(animation); } e2d::Animate::~Animate() @@ -36,7 +36,7 @@ void e2d::Animate::setAnimation(Animation * animation) { if (animation && animation != _animation) { - SafeRelease(_animation); + GC::release(_animation); _animation = animation; _animation->retain(); } @@ -100,14 +100,14 @@ void e2d::Animate::reset() void e2d::Animate::onDestroy() { Action::onDestroy(); - SafeRelease(_animation); + GC::release(_animation); } e2d::Animate * e2d::Animate::clone() const { if (_animation) { - return Create(_animation); + return GC::create(_animation); } return nullptr; } @@ -131,10 +131,10 @@ e2d::Animate * e2d::Animate::reverse() const } } - auto animation = Create(_animation->getInterval(), frames); + auto animation = GC::create(_animation->getInterval(), frames); if (animation) { - return Create(animation); + return GC::create(animation); } } return nullptr; diff --git a/core/Common/Animation.cpp b/core/Action/Animation.cpp similarity index 83% rename from core/Common/Animation.cpp rename to core/Action/Animation.cpp index 32d88125..c5521979 100644 --- a/core/Common/Animation.cpp +++ b/core/Action/Animation.cpp @@ -1,4 +1,4 @@ -#include "..\e2dcommon.h" +#include "..\e2daction.h" e2d::Animation::Animation() : _interval(1) @@ -24,22 +24,22 @@ e2d::Animation::Animation(double interval, const std::vector& frames) e2d::Animation * e2d::Animation::create() { - return Create(); + return GC::create(); } e2d::Animation * e2d::Animation::create(const std::vector& frames) { - return Create(frames); + return GC::create(frames); } e2d::Animation * e2d::Animation::create(double interval) { - return Create(interval); + return GC::create(interval); } e2d::Animation * e2d::Animation::create(double interval, const std::vector& frames) { - return Create(interval, frames); + return GC::create(interval, frames); } e2d::Animation::~Animation() @@ -55,7 +55,7 @@ void e2d::Animation::onDestroy() { for (auto frame : _frames) { - SafeRelease(frame); + GC::release(frame); } } @@ -88,7 +88,7 @@ const std::vector& e2d::Animation::getFrames() const e2d::Animation * e2d::Animation::clone() const { - auto animation = Create(_interval); + auto animation = GC::create(_interval); for (auto frame : _frames) { animation->add(frame); diff --git a/core/Action/CallFunc.cpp b/core/Action/CallFunc.cpp index 814b85ba..54686c8a 100644 --- a/core/Action/CallFunc.cpp +++ b/core/Action/CallFunc.cpp @@ -7,17 +7,17 @@ e2d::CallFunc::CallFunc(const Function& func) : e2d::CallFunc * e2d::CallFunc::create(const Function & func) { - return Create(func); + return GC::create(func); } e2d::CallFunc * e2d::CallFunc::clone() const { - return Create(_func); + return GC::create(_func); } e2d::CallFunc * e2d::CallFunc::reverse() const { - return Create(_func); + return GC::create(_func); } void e2d::CallFunc::_init() diff --git a/core/Action/Delay.cpp b/core/Action/Delay.cpp index ae393644..af3d6991 100644 --- a/core/Action/Delay.cpp +++ b/core/Action/Delay.cpp @@ -8,17 +8,17 @@ e2d::Delay::Delay(double duration) e2d::Delay * e2d::Delay::create(double duration) { - return Create(duration); + return GC::create(duration); } e2d::Delay * e2d::Delay::clone() const { - return Create(_delay); + return GC::create(_delay); } e2d::Delay * e2d::Delay::reverse() const { - return Create(_delay); + return GC::create(_delay); } void e2d::Delay::reset() diff --git a/core/Action/JumpBy.cpp b/core/Action/JumpBy.cpp index 3abc1b52..9f9e8f70 100644 --- a/core/Action/JumpBy.cpp +++ b/core/Action/JumpBy.cpp @@ -10,17 +10,17 @@ e2d::JumpBy::JumpBy(double duration, const Vector & vec, double height, int jump e2d::JumpBy * e2d::JumpBy::create(double duration, const Vector & vec, double height, int jumps) { - return Create(duration, vec, height, jumps); + return GC::create(duration, vec, height, jumps); } e2d::JumpBy * e2d::JumpBy::clone() const { - return Create(_duration, _deltaPos, _height, _jumps); + return GC::create(_duration, _deltaPos, _height, _jumps); } e2d::JumpBy * e2d::JumpBy::reverse() const { - return Create(_duration, -_deltaPos, _height, _jumps); + return GC::create(_duration, -_deltaPos, _height, _jumps); } void e2d::JumpBy::_init() diff --git a/core/Action/JumpTo.cpp b/core/Action/JumpTo.cpp index c9d76cba..4f4d8bed 100644 --- a/core/Action/JumpTo.cpp +++ b/core/Action/JumpTo.cpp @@ -8,12 +8,12 @@ e2d::JumpTo::JumpTo(double duration, const Point & pos, double height, int jumps e2d::JumpTo * e2d::JumpTo::create(double duration, const Point & pos, double height, int jumps) { - return Create(duration, pos, height, jumps); + return GC::create(duration, pos, height, jumps); } e2d::JumpTo * e2d::JumpTo::clone() const { - return Create(_duration, _endPos, _height, _jumps); + return GC::create(_duration, _endPos, _height, _jumps); } void e2d::JumpTo::_init() diff --git a/core/Action/Loop.cpp b/core/Action/Loop.cpp index cd0f3f9e..9f9bde4e 100644 --- a/core/Action/Loop.cpp +++ b/core/Action/Loop.cpp @@ -17,7 +17,7 @@ e2d::Loop::Loop(Action * action, int times /* = -1 */) e2d::Loop * e2d::Loop::create(Action * action, int times) { - return Create(action, times); + return GC::create(action, times); } e2d::Loop::~Loop() @@ -28,7 +28,7 @@ e2d::Loop * e2d::Loop::clone() const { if (_action) { - return Create(_action->clone()); + return GC::create(_action->clone()); } else { @@ -38,7 +38,7 @@ e2d::Loop * e2d::Loop::clone() const e2d::Loop * e2d::Loop::reverse() const { - return Create(_action); + return GC::create(_action); } void e2d::Loop::_init() @@ -91,7 +91,7 @@ void e2d::Loop::reset() void e2d::Loop::onDestroy() { Action::onDestroy(); - SafeRelease(_action); + GC::release(_action); } void e2d::Loop::_resetTime() diff --git a/core/Action/MoveBy.cpp b/core/Action/MoveBy.cpp index c1c710ac..cd13cbb5 100644 --- a/core/Action/MoveBy.cpp +++ b/core/Action/MoveBy.cpp @@ -9,7 +9,7 @@ e2d::MoveBy::MoveBy(double duration, Vector vector) e2d::MoveBy * e2d::MoveBy::create(double duration, Vector vector) { - return Create(duration, vector); + return GC::create(duration, vector); } void e2d::MoveBy::_init() @@ -34,10 +34,10 @@ void e2d::MoveBy::_update() e2d::MoveBy * e2d::MoveBy::clone() const { - return Create(_duration, _deltaPos); + return GC::create(_duration, _deltaPos); } e2d::MoveBy * e2d::MoveBy::reverse() const { - return Create(_duration, -_deltaPos); + return GC::create(_duration, -_deltaPos); } \ No newline at end of file diff --git a/core/Action/MoveTo.cpp b/core/Action/MoveTo.cpp index b9b27538..e4896249 100644 --- a/core/Action/MoveTo.cpp +++ b/core/Action/MoveTo.cpp @@ -8,12 +8,12 @@ e2d::MoveTo::MoveTo(double duration, Point pos) e2d::MoveTo * e2d::MoveTo::create(double duration, Point pos) { - return Create(duration, pos); + return GC::create(duration, pos); } e2d::MoveTo * e2d::MoveTo::clone() const { - return Create(_duration, _endPos); + return GC::create(_duration, _endPos); } void e2d::MoveTo::_init() diff --git a/core/Action/OpacityBy.cpp b/core/Action/OpacityBy.cpp index 9e754765..39c0e8e8 100644 --- a/core/Action/OpacityBy.cpp +++ b/core/Action/OpacityBy.cpp @@ -9,7 +9,7 @@ e2d::OpacityBy::OpacityBy(double duration, double opacity) e2d::OpacityBy * e2d::OpacityBy::create(double duration, double opacity) { - return Create(duration, opacity); + return GC::create(duration, opacity); } void e2d::OpacityBy::_init() @@ -34,10 +34,10 @@ void e2d::OpacityBy::_update() e2d::OpacityBy * e2d::OpacityBy::clone() const { - return Create(_duration, _deltaVal); + return GC::create(_duration, _deltaVal); } e2d::OpacityBy * e2d::OpacityBy::reverse() const { - return Create(_duration, -_deltaVal); + return GC::create(_duration, -_deltaVal); } \ No newline at end of file diff --git a/core/Action/OpacityTo.cpp b/core/Action/OpacityTo.cpp index 56c5d973..24b1fcc9 100644 --- a/core/Action/OpacityTo.cpp +++ b/core/Action/OpacityTo.cpp @@ -9,12 +9,12 @@ e2d::OpacityTo::OpacityTo(double duration, double opacity) e2d::OpacityTo * e2d::OpacityTo::create(double duration, double opacity) { - return Create(duration, opacity); + return GC::create(duration, opacity); } e2d::OpacityTo * e2d::OpacityTo::clone() const { - return Create(_duration, _endVal); + return GC::create(_duration, _endVal); } void e2d::OpacityTo::_init() diff --git a/core/Action/RotateBy.cpp b/core/Action/RotateBy.cpp index c839e2ad..8d058413 100644 --- a/core/Action/RotateBy.cpp +++ b/core/Action/RotateBy.cpp @@ -9,7 +9,7 @@ e2d::RotateBy::RotateBy(double duration, double rotation) e2d::RotateBy * e2d::RotateBy::create(double duration, double rotation) { - return Create(duration, rotation); + return GC::create(duration, rotation); } void e2d::RotateBy::_init() @@ -34,10 +34,10 @@ void e2d::RotateBy::_update() e2d::RotateBy * e2d::RotateBy::clone() const { - return Create(_duration, _deltaVal); + return GC::create(_duration, _deltaVal); } e2d::RotateBy * e2d::RotateBy::reverse() const { - return Create(_duration, -_deltaVal); + return GC::create(_duration, -_deltaVal); } \ No newline at end of file diff --git a/core/Action/RotateTo.cpp b/core/Action/RotateTo.cpp index e4846423..9cb394b6 100644 --- a/core/Action/RotateTo.cpp +++ b/core/Action/RotateTo.cpp @@ -9,12 +9,12 @@ e2d::RotateTo::RotateTo(double duration, double rotation) e2d::RotateTo * e2d::RotateTo::create(double duration, double rotation) { - return Create(duration, rotation); + return GC::create(duration, rotation); } e2d::RotateTo * e2d::RotateTo::clone() const { - return Create(_duration, _endVal); + return GC::create(_duration, _endVal); } void e2d::RotateTo::_init() diff --git a/core/Action/ScaleBy.cpp b/core/Action/ScaleBy.cpp index afb764ab..9a1b11b1 100644 --- a/core/Action/ScaleBy.cpp +++ b/core/Action/ScaleBy.cpp @@ -17,12 +17,12 @@ e2d::ScaleBy::ScaleBy(double duration, double scaleX, double scaleY) e2d::ScaleBy * e2d::ScaleBy::create(double duration, double scale) { - return Create(duration, scale); + return GC::create(duration, scale); } e2d::ScaleBy * e2d::ScaleBy::create(double duration, double scaleX, double scaleY) { - return Create(duration, scaleX, scaleY); + return GC::create(duration, scaleX, scaleY); } void e2d::ScaleBy::_init() @@ -48,10 +48,10 @@ void e2d::ScaleBy::_update() e2d::ScaleBy * e2d::ScaleBy::clone() const { - return Create(_duration, _deltaX, _deltaY); + return GC::create(_duration, _deltaX, _deltaY); } e2d::ScaleBy * e2d::ScaleBy::reverse() const { - return Create(_duration, -_deltaX, -_deltaY); + return GC::create(_duration, -_deltaX, -_deltaY); } \ No newline at end of file diff --git a/core/Action/ScaleTo.cpp b/core/Action/ScaleTo.cpp index c64f9e74..cf1283f2 100644 --- a/core/Action/ScaleTo.cpp +++ b/core/Action/ScaleTo.cpp @@ -16,17 +16,17 @@ e2d::ScaleTo::ScaleTo(double duration, double scaleX, double scaleY) e2d::ScaleTo * e2d::ScaleTo::create(double duration, double scale) { - return Create(duration, scale); + return GC::create(duration, scale); } e2d::ScaleTo * e2d::ScaleTo::create(double duration, double scaleX, double scaleY) { - return Create(duration, scaleX, scaleY); + return GC::create(duration, scaleX, scaleY); } e2d::ScaleTo * e2d::ScaleTo::clone() const { - return Create(_duration, _endScaleX, _endScaleY); + return GC::create(_duration, _endScaleX, _endScaleY); } void e2d::ScaleTo::_init() diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index eeece5cb..c28404a9 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -13,12 +13,12 @@ e2d::Sequence::Sequence(const std::vector& actions) e2d::Sequence * e2d::Sequence::create() { - return Create(); + return GC::create(); } e2d::Sequence * e2d::Sequence::create(const std::vector& actions) { - return Create(actions); + return GC::create(actions); } e2d::Sequence::~Sequence() @@ -45,7 +45,7 @@ void e2d::Sequence::onDestroy() Action::onDestroy(); for (auto action : _actions) { - SafeRelease(action); + GC::release(action); } } @@ -107,7 +107,7 @@ void e2d::Sequence::add(const std::vector& actions) e2d::Sequence * e2d::Sequence::clone() const { - auto sequence = Create(); + auto sequence = GC::create(); for (const auto& action : _actions) { if (action) @@ -120,7 +120,7 @@ e2d::Sequence * e2d::Sequence::clone() const e2d::Sequence * e2d::Sequence::reverse() const { - auto sequence = Create(); + auto sequence = GC::create(); if (!_actions.empty()) { std::vector newActions(_actions.size()); diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index 8da2847b..600fcc50 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -11,12 +11,12 @@ e2d::Spawn::Spawn(const std::vector& actions) e2d::Spawn * e2d::Spawn::create() { - return Create(); + return GC::create(); } e2d::Spawn * e2d::Spawn::create(const std::vector& actions) { - return Create(actions); + return GC::create(actions); } e2d::Spawn::~Spawn() @@ -42,7 +42,7 @@ void e2d::Spawn::onDestroy() Action::onDestroy(); for (auto action : _actions) { - SafeRelease(action); + GC::release(action); } } @@ -105,7 +105,7 @@ void e2d::Spawn::add(const std::vector& actions) e2d::Spawn * e2d::Spawn::clone() const { - auto spawn = Create(); + auto spawn = GC::create(); for (const auto& action : _actions) { if (action) @@ -118,7 +118,7 @@ e2d::Spawn * e2d::Spawn::clone() const e2d::Spawn * e2d::Spawn::reverse() const { - auto spawn = Create(); + auto spawn = GC::create(); if (!_actions.empty()) { std::vector newActions(_actions.size()); diff --git a/core/Manager/ObjectManager.cpp b/core/Base/GC.cpp similarity index 66% rename from core/Manager/ObjectManager.cpp rename to core/Base/GC.cpp index 0836d6b0..34878da4 100644 --- a/core/Manager/ObjectManager.cpp +++ b/core/Base/GC.cpp @@ -1,9 +1,8 @@ -#include "..\e2dmanager.h" #include "..\e2dbase.h" -// ObjectManager 释放池的实现机制: -// Object 类中的引用计数(_nRefCount)在一定程度上保证了指针的使用安全 -// 它记录了对象被使用的次数,当计数为 0 时,ObjectManager 会自动释放这个对象 +// GC 释放池的实现机制: +// Object 类中的引用计数(_refCount)在一定程度上防止了内存泄漏 +// 它记录了对象被使用的次数,当计数为 0 时,GC 会自动释放这个对象 // 所有的 Object 对象都应在被使用时(例如 Text 添加到了场景中) // 调用 retain 函数保证该对象不被删除,并在不再使用时调用 release 函数 @@ -12,7 +11,7 @@ static std::set s_vObjectPool; // 标志释放池执行状态 static bool s_bNotifyed = false; -void e2d::ObjectManager::__update() +void e2d::GC::__update() { if (!s_bNotifyed) return; @@ -32,7 +31,7 @@ void e2d::ObjectManager::__update() } } -void e2d::ObjectManager::__clear() +void e2d::GC::__clear() { for (auto pObj : s_vObjectPool) { @@ -41,7 +40,7 @@ void e2d::ObjectManager::__clear() s_vObjectPool.clear(); } -void e2d::ObjectManager::__add(e2d::Object * pObject) +void e2d::GC::__add(e2d::Object * pObject) { if (pObject) { @@ -49,7 +48,13 @@ void e2d::ObjectManager::__add(e2d::Object * pObject) } } -void e2d::ObjectManager::flush() +void e2d::GC::notify() { s_bNotifyed = true; } + +void e2d::GC::flush() +{ + GC::notify(); + GC::__update(); +} diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index 343811eb..1632cc33 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -145,7 +145,7 @@ int e2d::Game::start(bool autoRelease/* true */) Time::__updateLast(); // 刷新时间信息 } Renderer::__render(); // 渲染游戏画面 - ObjectManager::__update(); // 刷新内存池 + GC::__update(); // 刷新内存池 } else { @@ -206,7 +206,7 @@ void e2d::Game::destroy() // 回收音乐播放器资源 Player::__uninit(); // 删除所有对象 - ObjectManager::__clear(); + GC::__clear(); // 清空图片缓存 Image::clearCache(); // 回收音乐相关资源 diff --git a/core/Collider/ColliderCircle.cpp b/core/Collider/ColliderCircle.cpp index b3440c00..baeb1c4a 100644 --- a/core/Collider/ColliderCircle.cpp +++ b/core/Collider/ColliderCircle.cpp @@ -28,17 +28,17 @@ e2d::ColliderCircle::ColliderCircle(Node * node) e2d::ColliderCircle * e2d::ColliderCircle::create() { - return Create(); + return GC::create(); } e2d::ColliderCircle * e2d::ColliderCircle::create(Point center, double radius) { - return Create(center, radius); + return GC::create(center, radius); } e2d::ColliderCircle * e2d::ColliderCircle::create(Node * node) { - return Create(node); + return GC::create(node); } e2d::ColliderCircle::~ColliderCircle() diff --git a/core/Collider/ColliderEllipse.cpp b/core/Collider/ColliderEllipse.cpp index b4649316..156f0baf 100644 --- a/core/Collider/ColliderEllipse.cpp +++ b/core/Collider/ColliderEllipse.cpp @@ -28,17 +28,17 @@ e2d::ColliderEllipse::ColliderEllipse(Node * node) e2d::ColliderEllipse * e2d::ColliderEllipse::create() { - return Create(); + return GC::create(); } e2d::ColliderEllipse * e2d::ColliderEllipse::create(Point center, double radiusX, double radiusY) { - return Create(center, radiusX, radiusY); + return GC::create(center, radiusX, radiusY); } e2d::ColliderEllipse * e2d::ColliderEllipse::create(Node * node) { - return Create(node); + return GC::create(node); } e2d::ColliderEllipse::~ColliderEllipse() diff --git a/core/Collider/ColliderRect.cpp b/core/Collider/ColliderRect.cpp index 4e6c9cda..285384a1 100644 --- a/core/Collider/ColliderRect.cpp +++ b/core/Collider/ColliderRect.cpp @@ -21,17 +21,17 @@ e2d::ColliderRect::ColliderRect(Node * node) e2d::ColliderRect * e2d::ColliderRect::create() { - return Create(); + return GC::create(); } e2d::ColliderRect * e2d::ColliderRect::create(double x, double y, double width, double height) { - return Create(x, y, width, height); + return GC::create(x, y, width, height); } e2d::ColliderRect * e2d::ColliderRect::create(Node * node) { - return Create(node); + return GC::create(node); } e2d::ColliderRect::~ColliderRect() diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 18a5e60d..e06a4412 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -44,27 +44,27 @@ e2d::Image::Image(int resNameId, const String& resType, double cropX, double cro e2d::Image * e2d::Image::create() { - return Create(); + return GC::create(); } e2d::Image * e2d::Image::create(const String & filePath) { - return Create(filePath); + return GC::create(filePath); } e2d::Image * e2d::Image::create(int resNameId, const String & resType) { - return Create(resNameId, resType); + return GC::create(resNameId, resType); } e2d::Image * e2d::Image::create(const String & filePath, double cropX, double cropY, double cropWidth, double cropHeight) { - return Create(filePath, cropX, cropY, cropWidth, cropHeight); + return GC::create(filePath, cropX, cropY, cropWidth, cropHeight); } e2d::Image * e2d::Image::create(int resNameId, const String & resType, double cropX, double cropY, double cropWidth, double cropHeight) { - return Create(resNameId, resType, cropX, cropY, cropWidth, cropHeight); + return GC::create(resNameId, resType, cropX, cropY, cropWidth, cropHeight); } e2d::Image::~Image() diff --git a/core/Common/Object.cpp b/core/Common/Object.cpp index da8d5c29..a3ea7a41 100644 --- a/core/Common/Object.cpp +++ b/core/Common/Object.cpp @@ -13,7 +13,7 @@ e2d::Object::~Object() void e2d::Object::autorelease() { - ObjectManager::__add(this); + GC::__add(this); } void e2d::Object::retain() @@ -24,7 +24,7 @@ void e2d::Object::retain() void e2d::Object::release() { _refCount--; - ObjectManager::flush(); + GC::notify(); } int e2d::Object::getRefCount() const diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 162555b1..39507a65 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -21,7 +21,7 @@ e2d::Scene::Scene() e2d::Scene * e2d::Scene::create() { - return Create(); + return GC::create(); } e2d::Scene::~Scene() @@ -102,5 +102,5 @@ void e2d::Scene::showCollider(bool visiable) void e2d::Scene::onDestroy() { - SafeRelease(_root); + GC::release(_root); } diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index b379952e..677470ea 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -166,7 +166,7 @@ void e2d::ActionManager::__clearAllBindedWith(Node * target) auto a = s_vRunningActions[i]; if (a->getTarget() == target) { - SafeRelease(a); + GC::release(a); s_vRunningActions.erase(s_vRunningActions.begin() + i); } else @@ -181,7 +181,7 @@ void e2d::ActionManager::__uninit() { for (auto action : s_vRunningActions) { - SafeRelease(action); + GC::release(action); } s_vActions.clear(); s_vRunningActions.clear(); diff --git a/core/Manager/ColliderManager.cpp b/core/Manager/ColliderManager.cpp index 7548fcbb..547bc8e6 100644 --- a/core/Manager/ColliderManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -212,7 +212,7 @@ void e2d::ColliderManager::__removeCollider(Collider * pCollider) { if (s_vColliders[i] == pCollider) { - SafeRelease(pCollider); + GC::release(pCollider); s_vColliders.erase(s_vColliders.begin() + i); return; } diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index 5092e83e..2a2c2e02 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -68,7 +68,7 @@ void e2d::SceneManager::clear() while (s_SceneStack.size()) { auto temp = s_SceneStack.top(); - SafeRelease(temp); + GC::release(temp); s_SceneStack.pop(); } } @@ -127,7 +127,7 @@ void e2d::SceneManager::__update() } else { - SafeRelease(s_pCurrScene); + GC::release(s_pCurrScene); } // 执行下一场景的 onEnter 函数 @@ -172,8 +172,8 @@ bool e2d::SceneManager::__init() void e2d::SceneManager::__uninit() { - SafeRelease(s_pCurrScene); - SafeRelease(s_pNextScene); - SafeRelease(s_pTransition); + GC::release(s_pCurrScene); + GC::release(s_pNextScene); + GC::release(s_pTransition); SceneManager::clear(); } diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index b06f0eb1..24bc52c5 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -80,27 +80,27 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis e2d::Button * e2d::Button::create() { - return Create