ObjectManager改为GC类
This commit is contained in:
		
							parent
							
								
									ec1cbaec13
								
							
						
					
					
						commit
						29f7d35844
					
				|  | @ -15,12 +15,12 @@ e2d::Animate::Animate(Animation * animation) | |||
| 
 | ||||
| e2d::Animate * e2d::Animate::create() | ||||
| { | ||||
| 	return Create<Animate>(); | ||||
| 	return GC::create<Animate>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Animate * e2d::Animate::create(Animation * animation) | ||||
| { | ||||
| 	return Create<Animate>(animation); | ||||
| 	return GC::create<Animate>(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<Animate>(_animation); | ||||
| 		return GC::create<Animate>(_animation); | ||||
| 	} | ||||
| 	return nullptr; | ||||
| } | ||||
|  | @ -131,10 +131,10 @@ e2d::Animate * e2d::Animate::reverse() const | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		auto animation = Create<Animation>(_animation->getInterval(), frames); | ||||
| 		auto animation = GC::create<Animation>(_animation->getInterval(), frames); | ||||
| 		if (animation) | ||||
| 		{ | ||||
| 			return Create<Animate>(animation); | ||||
| 			return GC::create<Animate>(animation); | ||||
| 		} | ||||
| 	} | ||||
| 	return nullptr; | ||||
|  |  | |||
|  | @ -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<Image*>& frames) | |||
| 
 | ||||
| e2d::Animation * e2d::Animation::create() | ||||
| { | ||||
| 	return Create<Animation>(); | ||||
| 	return GC::create<Animation>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Animation * e2d::Animation::create(const std::vector<Image*>& frames) | ||||
| { | ||||
| 	return Create<Animation>(frames); | ||||
| 	return GC::create<Animation>(frames); | ||||
| } | ||||
| 
 | ||||
| e2d::Animation * e2d::Animation::create(double interval) | ||||
| { | ||||
| 	return Create<Animation>(interval); | ||||
| 	return GC::create<Animation>(interval); | ||||
| } | ||||
| 
 | ||||
| e2d::Animation * e2d::Animation::create(double interval, const std::vector<Image*>& frames) | ||||
| { | ||||
| 	return Create<Animation>(interval, frames); | ||||
| 	return GC::create<Animation>(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::Image*>& e2d::Animation::getFrames() const | |||
| 
 | ||||
| e2d::Animation * e2d::Animation::clone() const | ||||
| { | ||||
| 	auto animation = Create<Animation>(_interval); | ||||
| 	auto animation = GC::create<Animation>(_interval); | ||||
| 	for (auto frame : _frames) | ||||
| 	{ | ||||
| 		animation->add(frame); | ||||
|  | @ -7,17 +7,17 @@ e2d::CallFunc::CallFunc(const Function& func) : | |||
| 
 | ||||
| e2d::CallFunc * e2d::CallFunc::create(const Function & func) | ||||
| { | ||||
| 	return Create<CallFunc>(func); | ||||
| 	return GC::create<CallFunc>(func); | ||||
| } | ||||
| 
 | ||||
| e2d::CallFunc * e2d::CallFunc::clone() const | ||||
| { | ||||
| 	return Create<CallFunc>(_func); | ||||
| 	return GC::create<CallFunc>(_func); | ||||
| } | ||||
| 
 | ||||
| e2d::CallFunc * e2d::CallFunc::reverse() const | ||||
| { | ||||
| 	return Create<CallFunc>(_func); | ||||
| 	return GC::create<CallFunc>(_func); | ||||
| } | ||||
| 
 | ||||
| void e2d::CallFunc::_init() | ||||
|  |  | |||
|  | @ -8,17 +8,17 @@ e2d::Delay::Delay(double duration) | |||
| 
 | ||||
| e2d::Delay * e2d::Delay::create(double duration) | ||||
| { | ||||
| 	return Create<Delay>(duration); | ||||
| 	return GC::create<Delay>(duration); | ||||
| } | ||||
| 
 | ||||
| e2d::Delay * e2d::Delay::clone() const | ||||
| { | ||||
| 	return Create<Delay>(_delay); | ||||
| 	return GC::create<Delay>(_delay); | ||||
| } | ||||
| 
 | ||||
| e2d::Delay * e2d::Delay::reverse() const | ||||
| { | ||||
| 	return Create<Delay>(_delay); | ||||
| 	return GC::create<Delay>(_delay); | ||||
| } | ||||
| 
 | ||||
| void e2d::Delay::reset() | ||||
|  |  | |||
|  | @ -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<JumpBy>(duration, vec, height, jumps); | ||||
| 	return GC::create<JumpBy>(duration, vec, height, jumps); | ||||
| } | ||||
| 
 | ||||
| e2d::JumpBy * e2d::JumpBy::clone() const | ||||
| { | ||||
| 	return Create<JumpBy>(_duration, _deltaPos, _height, _jumps); | ||||
| 	return GC::create<JumpBy>(_duration, _deltaPos, _height, _jumps); | ||||
| } | ||||
| 
 | ||||
| e2d::JumpBy * e2d::JumpBy::reverse() const | ||||
| { | ||||
| 	return Create<JumpBy>(_duration, -_deltaPos, _height, _jumps); | ||||
| 	return GC::create<JumpBy>(_duration, -_deltaPos, _height, _jumps); | ||||
| } | ||||
| 
 | ||||
| void e2d::JumpBy::_init() | ||||
|  |  | |||
|  | @ -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<JumpTo>(duration, pos, height, jumps); | ||||
| 	return GC::create<JumpTo>(duration, pos, height, jumps); | ||||
| } | ||||
| 
 | ||||
| e2d::JumpTo * e2d::JumpTo::clone() const | ||||
| { | ||||
| 	return Create<JumpTo>(_duration, _endPos, _height, _jumps); | ||||
| 	return GC::create<JumpTo>(_duration, _endPos, _height, _jumps); | ||||
| } | ||||
| 
 | ||||
| void e2d::JumpTo::_init() | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ e2d::Loop::Loop(Action * action, int times /* = -1 */) | |||
| 
 | ||||
| e2d::Loop * e2d::Loop::create(Action * action, int times) | ||||
| { | ||||
| 	return Create<Loop>(action, times); | ||||
| 	return GC::create<Loop>(action, times); | ||||
| } | ||||
| 
 | ||||
| e2d::Loop::~Loop() | ||||
|  | @ -28,7 +28,7 @@ e2d::Loop * e2d::Loop::clone() const | |||
| { | ||||
| 	if (_action) | ||||
| 	{ | ||||
| 		return Create<Loop>(_action->clone()); | ||||
| 		return GC::create<Loop>(_action->clone()); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
|  | @ -38,7 +38,7 @@ e2d::Loop * e2d::Loop::clone() const | |||
| 
 | ||||
| e2d::Loop * e2d::Loop::reverse() const | ||||
| { | ||||
| 	return Create<Loop>(_action); | ||||
| 	return GC::create<Loop>(_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() | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ e2d::MoveBy::MoveBy(double duration, Vector vector) | |||
| 
 | ||||
| e2d::MoveBy * e2d::MoveBy::create(double duration, Vector vector) | ||||
| { | ||||
| 	return Create<MoveBy>(duration, vector); | ||||
| 	return GC::create<MoveBy>(duration, vector); | ||||
| } | ||||
| 
 | ||||
| void e2d::MoveBy::_init() | ||||
|  | @ -34,10 +34,10 @@ void e2d::MoveBy::_update() | |||
| 
 | ||||
| e2d::MoveBy * e2d::MoveBy::clone() const | ||||
| { | ||||
| 	return Create<MoveBy>(_duration, _deltaPos); | ||||
| 	return GC::create<MoveBy>(_duration, _deltaPos); | ||||
| } | ||||
| 
 | ||||
| e2d::MoveBy * e2d::MoveBy::reverse() const | ||||
| { | ||||
| 	return Create<MoveBy>(_duration, -_deltaPos); | ||||
| 	return GC::create<MoveBy>(_duration, -_deltaPos); | ||||
| } | ||||
|  | @ -8,12 +8,12 @@ e2d::MoveTo::MoveTo(double duration, Point pos) | |||
| 
 | ||||
| e2d::MoveTo * e2d::MoveTo::create(double duration, Point pos) | ||||
| { | ||||
| 	return Create<MoveTo>(duration, pos); | ||||
| 	return GC::create<MoveTo>(duration, pos); | ||||
| } | ||||
| 
 | ||||
| e2d::MoveTo * e2d::MoveTo::clone() const | ||||
| { | ||||
| 	return Create<MoveTo>(_duration, _endPos); | ||||
| 	return GC::create<MoveTo>(_duration, _endPos); | ||||
| } | ||||
| 
 | ||||
| void e2d::MoveTo::_init() | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ e2d::OpacityBy::OpacityBy(double duration, double opacity) | |||
| 
 | ||||
| e2d::OpacityBy * e2d::OpacityBy::create(double duration, double opacity) | ||||
| { | ||||
| 	return Create<OpacityBy>(duration, opacity); | ||||
| 	return GC::create<OpacityBy>(duration, opacity); | ||||
| } | ||||
| 
 | ||||
| void e2d::OpacityBy::_init() | ||||
|  | @ -34,10 +34,10 @@ void e2d::OpacityBy::_update() | |||
| 
 | ||||
| e2d::OpacityBy * e2d::OpacityBy::clone() const | ||||
| { | ||||
| 	return Create<OpacityBy>(_duration, _deltaVal); | ||||
| 	return GC::create<OpacityBy>(_duration, _deltaVal); | ||||
| } | ||||
| 
 | ||||
| e2d::OpacityBy * e2d::OpacityBy::reverse() const | ||||
| { | ||||
| 	return Create<OpacityBy>(_duration, -_deltaVal); | ||||
| 	return GC::create<OpacityBy>(_duration, -_deltaVal); | ||||
| } | ||||
|  | @ -9,12 +9,12 @@ e2d::OpacityTo::OpacityTo(double duration, double opacity) | |||
| 
 | ||||
| e2d::OpacityTo * e2d::OpacityTo::create(double duration, double opacity) | ||||
| { | ||||
| 	return Create<OpacityTo>(duration, opacity); | ||||
| 	return GC::create<OpacityTo>(duration, opacity); | ||||
| } | ||||
| 
 | ||||
| e2d::OpacityTo * e2d::OpacityTo::clone() const | ||||
| { | ||||
| 	return Create<OpacityTo>(_duration, _endVal); | ||||
| 	return GC::create<OpacityTo>(_duration, _endVal); | ||||
| } | ||||
| 
 | ||||
| void e2d::OpacityTo::_init() | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ e2d::RotateBy::RotateBy(double duration, double rotation) | |||
| 
 | ||||
| e2d::RotateBy * e2d::RotateBy::create(double duration, double rotation) | ||||
| { | ||||
| 	return Create<RotateBy>(duration, rotation); | ||||
| 	return GC::create<RotateBy>(duration, rotation); | ||||
| } | ||||
| 
 | ||||
| void e2d::RotateBy::_init() | ||||
|  | @ -34,10 +34,10 @@ void e2d::RotateBy::_update() | |||
| 
 | ||||
| e2d::RotateBy * e2d::RotateBy::clone() const | ||||
| { | ||||
| 	return Create<RotateBy>(_duration, _deltaVal); | ||||
| 	return GC::create<RotateBy>(_duration, _deltaVal); | ||||
| } | ||||
| 
 | ||||
| e2d::RotateBy * e2d::RotateBy::reverse() const | ||||
| { | ||||
| 	return Create<RotateBy>(_duration, -_deltaVal); | ||||
| 	return GC::create<RotateBy>(_duration, -_deltaVal); | ||||
| } | ||||
|  | @ -9,12 +9,12 @@ e2d::RotateTo::RotateTo(double duration, double rotation) | |||
| 
 | ||||
| e2d::RotateTo * e2d::RotateTo::create(double duration, double rotation) | ||||
| { | ||||
| 	return Create<RotateTo>(duration, rotation); | ||||
| 	return GC::create<RotateTo>(duration, rotation); | ||||
| } | ||||
| 
 | ||||
| e2d::RotateTo * e2d::RotateTo::clone() const | ||||
| { | ||||
| 	return Create<RotateTo>(_duration, _endVal); | ||||
| 	return GC::create<RotateTo>(_duration, _endVal); | ||||
| } | ||||
| 
 | ||||
| void e2d::RotateTo::_init() | ||||
|  |  | |||
|  | @ -17,12 +17,12 @@ e2d::ScaleBy::ScaleBy(double duration, double scaleX, double scaleY) | |||
| 
 | ||||
| e2d::ScaleBy * e2d::ScaleBy::create(double duration, double scale) | ||||
| { | ||||
| 	return Create<ScaleBy>(duration, scale); | ||||
| 	return GC::create<ScaleBy>(duration, scale); | ||||
| } | ||||
| 
 | ||||
| e2d::ScaleBy * e2d::ScaleBy::create(double duration, double scaleX, double scaleY) | ||||
| { | ||||
| 	return Create<ScaleBy>(duration, scaleX, scaleY); | ||||
| 	return GC::create<ScaleBy>(duration, scaleX, scaleY); | ||||
| } | ||||
| 
 | ||||
| void e2d::ScaleBy::_init() | ||||
|  | @ -48,10 +48,10 @@ void e2d::ScaleBy::_update() | |||
| 
 | ||||
| e2d::ScaleBy * e2d::ScaleBy::clone() const | ||||
| { | ||||
| 	return Create<ScaleBy>(_duration, _deltaX, _deltaY); | ||||
| 	return GC::create<ScaleBy>(_duration, _deltaX, _deltaY); | ||||
| } | ||||
| 
 | ||||
| e2d::ScaleBy * e2d::ScaleBy::reverse() const | ||||
| { | ||||
| 	return Create<ScaleBy>(_duration, -_deltaX, -_deltaY); | ||||
| 	return GC::create<ScaleBy>(_duration, -_deltaX, -_deltaY); | ||||
| } | ||||
|  | @ -16,17 +16,17 @@ e2d::ScaleTo::ScaleTo(double duration, double scaleX, double scaleY) | |||
| 
 | ||||
| e2d::ScaleTo * e2d::ScaleTo::create(double duration, double scale) | ||||
| { | ||||
| 	return Create<ScaleTo>(duration, scale); | ||||
| 	return GC::create<ScaleTo>(duration, scale); | ||||
| } | ||||
| 
 | ||||
| e2d::ScaleTo * e2d::ScaleTo::create(double duration, double scaleX, double scaleY) | ||||
| { | ||||
| 	return Create<ScaleTo>(duration, scaleX, scaleY); | ||||
| 	return GC::create<ScaleTo>(duration, scaleX, scaleY); | ||||
| } | ||||
| 
 | ||||
| e2d::ScaleTo * e2d::ScaleTo::clone() const | ||||
| { | ||||
| 	return Create<ScaleTo>(_duration, _endScaleX, _endScaleY); | ||||
| 	return GC::create<ScaleTo>(_duration, _endScaleX, _endScaleY); | ||||
| } | ||||
| 
 | ||||
| void e2d::ScaleTo::_init() | ||||
|  |  | |||
|  | @ -13,12 +13,12 @@ e2d::Sequence::Sequence(const std::vector<Action*>& actions) | |||
| 
 | ||||
| e2d::Sequence * e2d::Sequence::create() | ||||
| { | ||||
| 	return Create<Sequence>(); | ||||
| 	return GC::create<Sequence>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Sequence * e2d::Sequence::create(const std::vector<Action*>& actions) | ||||
| { | ||||
| 	return Create<Sequence>(actions); | ||||
| 	return GC::create<Sequence>(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<Action*>& actions) | |||
| 
 | ||||
| e2d::Sequence * e2d::Sequence::clone() const | ||||
| { | ||||
| 	auto sequence = Create<Sequence>(); | ||||
| 	auto sequence = GC::create<Sequence>(); | ||||
| 	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<Sequence>(); | ||||
| 	auto sequence = GC::create<Sequence>(); | ||||
| 	if (!_actions.empty()) | ||||
| 	{ | ||||
| 		std::vector<Action*> newActions(_actions.size()); | ||||
|  |  | |||
|  | @ -11,12 +11,12 @@ e2d::Spawn::Spawn(const std::vector<Action*>& actions) | |||
| 
 | ||||
| e2d::Spawn * e2d::Spawn::create() | ||||
| { | ||||
| 	return Create<Spawn>(); | ||||
| 	return GC::create<Spawn>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Spawn * e2d::Spawn::create(const std::vector<Action*>& actions) | ||||
| { | ||||
| 	return Create<Spawn>(actions); | ||||
| 	return GC::create<Spawn>(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<Action*>& actions) | |||
| 
 | ||||
| e2d::Spawn * e2d::Spawn::clone() const | ||||
| { | ||||
| 	auto spawn = Create<Spawn>(); | ||||
| 	auto spawn = GC::create<Spawn>(); | ||||
| 	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<Spawn>(); | ||||
| 	auto spawn = GC::create<Spawn>(); | ||||
| 	if (!_actions.empty()) | ||||
| 	{ | ||||
| 		std::vector<Action*> newActions(_actions.size()); | ||||
|  |  | |||
|  | @ -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<e2d::Object*> 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(); | ||||
| } | ||||
|  | @ -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(); | ||||
| 	// 回收音乐相关资源
 | ||||
|  |  | |||
|  | @ -28,17 +28,17 @@ e2d::ColliderCircle::ColliderCircle(Node * node) | |||
| 
 | ||||
| e2d::ColliderCircle * e2d::ColliderCircle::create() | ||||
| { | ||||
| 	return Create<ColliderCircle>(); | ||||
| 	return GC::create<ColliderCircle>(); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderCircle * e2d::ColliderCircle::create(Point center, double radius) | ||||
| { | ||||
| 	return Create<ColliderCircle>(center, radius); | ||||
| 	return GC::create<ColliderCircle>(center, radius); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderCircle * e2d::ColliderCircle::create(Node * node) | ||||
| { | ||||
| 	return Create<ColliderCircle>(node); | ||||
| 	return GC::create<ColliderCircle>(node); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderCircle::~ColliderCircle() | ||||
|  |  | |||
|  | @ -28,17 +28,17 @@ e2d::ColliderEllipse::ColliderEllipse(Node * node) | |||
| 
 | ||||
| e2d::ColliderEllipse * e2d::ColliderEllipse::create() | ||||
| { | ||||
| 	return Create<ColliderEllipse>(); | ||||
| 	return GC::create<ColliderEllipse>(); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderEllipse * e2d::ColliderEllipse::create(Point center, double radiusX, double radiusY) | ||||
| { | ||||
| 	return Create<ColliderEllipse>(center, radiusX, radiusY); | ||||
| 	return GC::create<ColliderEllipse>(center, radiusX, radiusY); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderEllipse * e2d::ColliderEllipse::create(Node * node) | ||||
| { | ||||
| 	return Create<ColliderEllipse>(node); | ||||
| 	return GC::create<ColliderEllipse>(node); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderEllipse::~ColliderEllipse() | ||||
|  |  | |||
|  | @ -21,17 +21,17 @@ e2d::ColliderRect::ColliderRect(Node * node) | |||
| 
 | ||||
| e2d::ColliderRect * e2d::ColliderRect::create() | ||||
| { | ||||
| 	return Create<ColliderRect>(); | ||||
| 	return GC::create<ColliderRect>(); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderRect * e2d::ColliderRect::create(double x, double y, double width, double height) | ||||
| { | ||||
| 	return Create<ColliderRect>(x, y, width, height); | ||||
| 	return GC::create<ColliderRect>(x, y, width, height); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderRect * e2d::ColliderRect::create(Node * node) | ||||
| { | ||||
| 	return Create<ColliderRect>(node); | ||||
| 	return GC::create<ColliderRect>(node); | ||||
| } | ||||
| 
 | ||||
| e2d::ColliderRect::~ColliderRect() | ||||
|  |  | |||
|  | @ -44,27 +44,27 @@ e2d::Image::Image(int resNameId, const String& resType, double cropX, double cro | |||
| 
 | ||||
| e2d::Image * e2d::Image::create() | ||||
| { | ||||
| 	return Create<Image>(); | ||||
| 	return GC::create<Image>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Image * e2d::Image::create(const String & filePath) | ||||
| { | ||||
| 	return Create<Image>(filePath); | ||||
| 	return GC::create<Image>(filePath); | ||||
| } | ||||
| 
 | ||||
| e2d::Image * e2d::Image::create(int resNameId, const String & resType) | ||||
| { | ||||
| 	return Create<Image>(resNameId, resType); | ||||
| 	return GC::create<Image>(resNameId, resType); | ||||
| } | ||||
| 
 | ||||
| e2d::Image * e2d::Image::create(const String & filePath, double cropX, double cropY, double cropWidth, double cropHeight) | ||||
| { | ||||
| 	return Create<Image>(filePath, cropX, cropY, cropWidth, cropHeight); | ||||
| 	return GC::create<Image>(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<Image>(resNameId, resType, cropX, cropY, cropWidth, cropHeight); | ||||
| 	return GC::create<Image>(resNameId, resType, cropX, cropY, cropWidth, cropHeight); | ||||
| } | ||||
| 
 | ||||
| e2d::Image::~Image() | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -21,7 +21,7 @@ e2d::Scene::Scene() | |||
| 
 | ||||
| e2d::Scene * e2d::Scene::create() | ||||
| { | ||||
| 	return Create<Scene>(); | ||||
| 	return GC::create<Scene>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Scene::~Scene() | ||||
|  | @ -102,5 +102,5 @@ void e2d::Scene::showCollider(bool visiable) | |||
| 
 | ||||
| void e2d::Scene::onDestroy() | ||||
| { | ||||
| 	SafeRelease(_root); | ||||
| 	GC::release(_root); | ||||
| } | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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; | ||||
| 			} | ||||
|  |  | |||
|  | @ -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(); | ||||
| } | ||||
|  |  | |||
|  | @ -80,27 +80,27 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis | |||
| 
 | ||||
| e2d::Button * e2d::Button::create() | ||||
| { | ||||
| 	return Create<Button>(); | ||||
| 	return GC::create<Button>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Button * e2d::Button::create(Node * normal, const Function & func) | ||||
| { | ||||
| 	return Create<Button>(normal, func); | ||||
| 	return GC::create<Button>(normal, func); | ||||
| } | ||||
| 
 | ||||
| e2d::Button * e2d::Button::create(Node * normal, Node * selected, const Function & func) | ||||
| { | ||||
| 	return Create<Button>(normal, selected, func); | ||||
| 	return GC::create<Button>(normal, selected, func); | ||||
| } | ||||
| 
 | ||||
| e2d::Button * e2d::Button::create(Node * normal, Node * mouseover, Node * selected, const Function & func) | ||||
| { | ||||
| 	return Create<Button>(normal, mouseover, selected, func); | ||||
| 	return GC::create<Button>(normal, mouseover, selected, func); | ||||
| } | ||||
| 
 | ||||
| e2d::Button * e2d::Button::create(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function & func) | ||||
| { | ||||
| 	return Create<Button>(normal, mouseover, selected, disabled, func); | ||||
| 	return GC::create<Button>(normal, mouseover, selected, disabled, func); | ||||
| } | ||||
| 
 | ||||
| bool e2d::Button::isEnable() const | ||||
|  |  | |||
|  | @ -76,27 +76,27 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N | |||
| 
 | ||||
| e2d::ButtonToggle * e2d::ButtonToggle::create() | ||||
| { | ||||
| 	return Create<ButtonToggle>(); | ||||
| 	return GC::create<ButtonToggle>(); | ||||
| } | ||||
| 
 | ||||
| e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, const Function & func) | ||||
| { | ||||
| 	return Create<ButtonToggle>(onNormal, offNormal, func); | ||||
| 	return GC::create<ButtonToggle>(onNormal, offNormal, func); | ||||
| } | ||||
| 
 | ||||
| e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, Node * onSelected, Node * offSelected, const Function & func) | ||||
| { | ||||
| 	return Create<ButtonToggle>(onNormal, offNormal, onSelected, offSelected, func); | ||||
| 	return GC::create<ButtonToggle>(onNormal, offNormal, onSelected, offSelected, func); | ||||
| } | ||||
| 
 | ||||
| e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, Node * onMouseOver, Node * offMouseOver, Node * onSelected, Node * offSelected, const Function & func) | ||||
| { | ||||
| 	return Create<ButtonToggle>(onNormal, offNormal, onMouseOver, offMouseOver, onSelected, offSelected, func); | ||||
| 	return GC::create<ButtonToggle>(onNormal, offNormal, onMouseOver, offMouseOver, onSelected, offSelected, func); | ||||
| } | ||||
| 
 | ||||
| e2d::ButtonToggle * e2d::ButtonToggle::create(Node * onNormal, Node * offNormal, Node * onMouseOver, Node * offMouseOver, Node * onSelected, Node * offSelected, Node * onDisabled, Node * offDisabled, const Function & func) | ||||
| { | ||||
| 	return Create<ButtonToggle>(onNormal, offNormal, onMouseOver, offMouseOver, onSelected, offSelected, onDisabled, offDisabled, func); | ||||
| 	return GC::create<ButtonToggle>(onNormal, offNormal, onMouseOver, offMouseOver, onSelected, offSelected, onDisabled, offDisabled, func); | ||||
| } | ||||
| 
 | ||||
| bool e2d::ButtonToggle::getState() const | ||||
|  |  | |||
|  | @ -16,12 +16,12 @@ e2d::Menu::Menu(const std::vector<Button*>& buttons) | |||
| 
 | ||||
| e2d::Menu * e2d::Menu::create() | ||||
| { | ||||
| 	return Create<Menu>(); | ||||
| 	return GC::create<Menu>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Menu * e2d::Menu::create(const std::vector<Button*>& buttons) | ||||
| { | ||||
| 	return Create<Menu>(buttons); | ||||
| 	return GC::create<Menu>(buttons); | ||||
| } | ||||
| 
 | ||||
| bool e2d::Menu::isEnable() const | ||||
|  |  | |||
|  | @ -37,13 +37,13 @@ e2d::Node::Node() | |||
| { | ||||
| 	if (s_fDefaultColliderEnabled) | ||||
| 	{ | ||||
| 		this->setCollider(Create<ColliderRect>(this)); | ||||
| 		this->setCollider(GC::create<ColliderRect>(this)); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| e2d::Node * e2d::Node::create() | ||||
| { | ||||
| 	return Create<Node>(); | ||||
| 	return GC::create<Node>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Node::~Node() | ||||
|  | @ -549,19 +549,19 @@ void e2d::Node::setCollider(Collider::Type type) | |||
| 	{ | ||||
| 	case Collider::Type::RECT: | ||||
| 	{ | ||||
| 		this->setCollider(Create<ColliderRect>(this)); | ||||
| 		this->setCollider(GC::create<ColliderRect>(this)); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	case Collider::Type::CIRCLE: | ||||
| 	{ | ||||
| 		this->setCollider(Create<ColliderCircle>(this)); | ||||
| 		this->setCollider(GC::create<ColliderCircle>(this)); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	case Collider::Type::ELLIPSE: | ||||
| 	{ | ||||
| 		this->setCollider(Create<ColliderEllipse>(this)); | ||||
| 		this->setCollider(GC::create<ColliderEllipse>(this)); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -983,7 +983,7 @@ void e2d::Node::onDestroy() | |||
| 	ColliderManager::__removeCollider(_collider); | ||||
| 	for (auto child : _children) | ||||
| 	{ | ||||
| 		SafeRelease(child); | ||||
| 		GC::release(child); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,17 +21,17 @@ e2d::Circle::Circle(Point center, double radius) | |||
| 
 | ||||
| e2d::Circle * e2d::Circle::create() | ||||
| { | ||||
| 	return Create<Circle>(); | ||||
| 	return GC::create<Circle>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Circle * e2d::Circle::create(double radius) | ||||
| { | ||||
| 	return Create<Circle>(radius); | ||||
| 	return GC::create<Circle>(radius); | ||||
| } | ||||
| 
 | ||||
| e2d::Circle * e2d::Circle::create(Point center, double radius) | ||||
| { | ||||
| 	return Create<Circle>(center, radius); | ||||
| 	return GC::create<Circle>(center, radius); | ||||
| } | ||||
| 
 | ||||
| e2d::Circle::~Circle() | ||||
|  |  | |||
|  | @ -24,17 +24,17 @@ e2d::Ellipse::Ellipse(Point center, double radiusX, double radiusY) | |||
| 
 | ||||
| e2d::Ellipse * e2d::Ellipse::create() | ||||
| { | ||||
| 	return Create<Ellipse>(); | ||||
| 	return GC::create<Ellipse>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Ellipse * e2d::Ellipse::create(double radiusX, double radiusY) | ||||
| { | ||||
| 	return Create<Ellipse>(radiusX, radiusY); | ||||
| 	return GC::create<Ellipse>(radiusX, radiusY); | ||||
| } | ||||
| 
 | ||||
| e2d::Ellipse * e2d::Ellipse::create(Point center, double radiusX, double radiusY) | ||||
| { | ||||
| 	return Create<Ellipse>(center, radiusX, radiusY); | ||||
| 	return GC::create<Ellipse>(center, radiusX, radiusY); | ||||
| } | ||||
| 
 | ||||
| e2d::Ellipse::~Ellipse() | ||||
|  |  | |||
|  | @ -18,17 +18,17 @@ e2d::Rect::Rect(Point topLeft, Size size) | |||
| 
 | ||||
| e2d::Rect * e2d::Rect::create() | ||||
| { | ||||
| 	return Create<Rect>(); | ||||
| 	return GC::create<Rect>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Rect * e2d::Rect::create(Size size) | ||||
| { | ||||
| 	return Create<Rect>(size); | ||||
| 	return GC::create<Rect>(size); | ||||
| } | ||||
| 
 | ||||
| e2d::Rect * e2d::Rect::create(Point topLeft, Size size) | ||||
| { | ||||
| 	return Create<Rect>(topLeft, size); | ||||
| 	return GC::create<Rect>(topLeft, size); | ||||
| } | ||||
| 
 | ||||
| e2d::Rect::~Rect() | ||||
|  |  | |||
|  | @ -24,17 +24,17 @@ e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiu | |||
| 
 | ||||
| e2d::RoundRect * e2d::RoundRect::create() | ||||
| { | ||||
| 	return Create<RoundRect>(); | ||||
| 	return GC::create<RoundRect>(); | ||||
| } | ||||
| 
 | ||||
| e2d::RoundRect * e2d::RoundRect::create(Size size, double radiusX, double radiusY) | ||||
| { | ||||
| 	return Create<RoundRect>(size, radiusX, radiusY); | ||||
| 	return GC::create<RoundRect>(size, radiusX, radiusY); | ||||
| } | ||||
| 
 | ||||
| e2d::RoundRect * e2d::RoundRect::create(Point topLeft, Size size, double radiusX, double radiusY) | ||||
| { | ||||
| 	return Create<RoundRect>(topLeft, size, radiusX, radiusY); | ||||
| 	return GC::create<RoundRect>(topLeft, size, radiusX, radiusY); | ||||
| } | ||||
| 
 | ||||
| e2d::RoundRect::~RoundRect() | ||||
|  |  | |||
|  | @ -40,32 +40,32 @@ e2d::Sprite::Sprite(int resNameId, const String& resType, double x, double y, do | |||
| 
 | ||||
| e2d::Sprite * e2d::Sprite::create() | ||||
| { | ||||
| 	return Create<Sprite>(); | ||||
| 	return GC::create<Sprite>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Sprite * e2d::Sprite::create(Image * image) | ||||
| { | ||||
| 	return Create<Sprite>(image); | ||||
| 	return GC::create<Sprite>(image); | ||||
| } | ||||
| 
 | ||||
| e2d::Sprite * e2d::Sprite::create(const String & filePath) | ||||
| { | ||||
| 	return Create<Sprite>(filePath); | ||||
| 	return GC::create<Sprite>(filePath); | ||||
| } | ||||
| 
 | ||||
| e2d::Sprite * e2d::Sprite::create(int resNameId, const String & resType) | ||||
| { | ||||
| 	return Create<Sprite>(resNameId, resType); | ||||
| 	return GC::create<Sprite>(resNameId, resType); | ||||
| } | ||||
| 
 | ||||
| e2d::Sprite * e2d::Sprite::create(const String & filePath, double x, double y, double width, double height) | ||||
| { | ||||
| 	return Create<Sprite>(filePath, x, y, width, height); | ||||
| 	return GC::create<Sprite>(filePath, x, y, width, height); | ||||
| } | ||||
| 
 | ||||
| e2d::Sprite * e2d::Sprite::create(int resNameId, const String & resType, double x, double y, double width, double height) | ||||
| { | ||||
| 	return Create<Sprite>(resNameId, resType, x, y, width, height); | ||||
| 	return GC::create<Sprite>(resNameId, resType, x, y, width, height); | ||||
| } | ||||
| 
 | ||||
| e2d::Sprite::~Sprite() | ||||
|  | @ -76,7 +76,7 @@ bool e2d::Sprite::open(Image * image) | |||
| { | ||||
| 	if (image) | ||||
| 	{ | ||||
| 		SafeRelease(_image); | ||||
| 		GC::release(_image); | ||||
| 		_image = image; | ||||
| 		_image->retain(); | ||||
| 
 | ||||
|  | @ -90,7 +90,7 @@ bool e2d::Sprite::open(const String& filePath) | |||
| { | ||||
| 	if (!_image) | ||||
| 	{ | ||||
| 		_image = Create<Image>(); | ||||
| 		_image = GC::create<Image>(); | ||||
| 		_image->retain(); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -106,7 +106,7 @@ bool e2d::Sprite::open(int resNameId, const String& resType) | |||
| { | ||||
| 	if (!_image) | ||||
| 	{ | ||||
| 		_image = Create<Image>(); | ||||
| 		_image = GC::create<Image>(); | ||||
| 		_image->retain(); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -158,5 +158,5 @@ void e2d::Sprite::onRender() | |||
| void e2d::Sprite::onDestroy() | ||||
| { | ||||
| 	Node::onDestroy(); | ||||
| 	SafeRelease(_image); | ||||
| 	GC::release(_image); | ||||
| } | ||||
|  |  | |||
|  | @ -92,12 +92,12 @@ e2d::Text::Text(const String & text, const Font & font, const Style & style) | |||
| 
 | ||||
| e2d::Text * e2d::Text::create() | ||||
| { | ||||
| 	return Create<Text>(); | ||||
| 	return GC::create<Text>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Text * e2d::Text::create(const String & text, const Font & font, const Style & style) | ||||
| { | ||||
| 	return Create<Text>(text, font, style); | ||||
| 	return GC::create<Text>(text, font, style); | ||||
| } | ||||
| 
 | ||||
| e2d::Text::~Text() | ||||
|  |  | |||
|  | @ -70,17 +70,17 @@ e2d::Music::~Music() | |||
| 
 | ||||
| e2d::Music * e2d::Music::create() | ||||
| { | ||||
| 	return Create<Music>(); | ||||
| 	return GC::create<Music>(); | ||||
| } | ||||
| 
 | ||||
| e2d::Music * e2d::Music::create(const e2d::String & filePath) | ||||
| { | ||||
| 	return Create<Music>(filePath); | ||||
| 	return GC::create<Music>(filePath); | ||||
| } | ||||
| 
 | ||||
| e2d::Music * e2d::Music::create(int resNameId, const String & resType) | ||||
| { | ||||
| 	return Create<Music>(resNameId, resType); | ||||
| 	return GC::create<Music>(resNameId, resType); | ||||
| } | ||||
| 
 | ||||
| bool e2d::Music::open(const e2d::String& filePath) | ||||
|  |  | |||
|  | @ -29,8 +29,8 @@ bool e2d::Transition::isDone() | |||
| 
 | ||||
| void e2d::Transition::onDestroy() | ||||
| { | ||||
| 	SafeRelease(_outScene); | ||||
| 	SafeRelease(_inScene); | ||||
| 	GC::release(_outScene); | ||||
| 	GC::release(_inScene); | ||||
| } | ||||
| 
 | ||||
| void e2d::Transition::_init(Scene * prev, Scene * next) | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ e2d::TransitionEmerge::TransitionEmerge(double duration) | |||
| 
 | ||||
| e2d::TransitionEmerge * e2d::TransitionEmerge::create(double duration) | ||||
| { | ||||
| 	return Create<TransitionEmerge>(duration); | ||||
| 	return GC::create<TransitionEmerge>(duration); | ||||
| } | ||||
| 
 | ||||
| void e2d::TransitionEmerge::_init(Scene * prev, Scene * next) | ||||
|  |  | |||
|  | @ -19,12 +19,12 @@ e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuratio | |||
| 
 | ||||
| e2d::TransitionFade * e2d::TransitionFade::create(double duration) | ||||
| { | ||||
| 	return Create<TransitionFade>(duration); | ||||
| 	return GC::create<TransitionFade>(duration); | ||||
| } | ||||
| 
 | ||||
| e2d::TransitionFade * e2d::TransitionFade::create(double fadeOutDuration, double fadeInDuration) | ||||
| { | ||||
| 	return Create<TransitionFade>(fadeOutDuration, fadeInDuration); | ||||
| 	return GC::create<TransitionFade>(fadeOutDuration, fadeInDuration); | ||||
| } | ||||
| 
 | ||||
| void e2d::TransitionFade::_init(Scene * prev, Scene * next) | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ e2d::TransitionMove::TransitionMove(double duration, Direction direction) | |||
| 
 | ||||
| e2d::TransitionMove * e2d::TransitionMove::create(double moveDuration, Direction direction) | ||||
| { | ||||
| 	return Create<TransitionMove>(moveDuration, direction); | ||||
| 	return GC::create<TransitionMove>(moveDuration, direction); | ||||
| } | ||||
| 
 | ||||
| void e2d::TransitionMove::_init(Scene * prev, Scene * next) | ||||
|  |  | |||
|  | @ -772,6 +772,80 @@ protected: | |||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 帧动画
 | ||||
| class Animation : | ||||
| 	public Object | ||||
| { | ||||
| public: | ||||
| 	Animation(); | ||||
| 
 | ||||
| 	Animation( | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	Animation( | ||||
| 		double interval						/* 帧间隔(秒) */ | ||||
| 	); | ||||
| 
 | ||||
| 	Animation( | ||||
| 		double interval,					/* 帧间隔(秒) */ | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建帧动画
 | ||||
| 	static Animation * create(); | ||||
| 
 | ||||
| 	// 创建帧动画
 | ||||
| 	static Animation * create( | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建特定帧间隔的帧动画
 | ||||
| 	static Animation * create( | ||||
| 		double interval						/* 帧间隔(秒) */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建特定帧间隔的帧动画
 | ||||
| 	static Animation * create( | ||||
| 		double interval,					/* 帧间隔(秒) */ | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Animation(); | ||||
| 
 | ||||
| 	// 添加关键帧
 | ||||
| 	void add( | ||||
| 		Image * frame	/* 关键帧 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加多个关键帧
 | ||||
| 	void add( | ||||
| 		const std::vector<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取帧间隔
 | ||||
| 	double getInterval() const; | ||||
| 
 | ||||
| 	// 获取关键帧
 | ||||
| 	const std::vector<Image*>& getFrames() const; | ||||
| 
 | ||||
| 	// 设置每一帧的时间间隔
 | ||||
| 	void setInterval( | ||||
| 		double interval		/* 帧间隔(秒) */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取动画的拷贝对象
 | ||||
| 	virtual Animation * clone() const; | ||||
| 
 | ||||
| 	// 销毁对象
 | ||||
| 	virtual void onDestroy() override; | ||||
| 
 | ||||
| protected: | ||||
| 	double	_interval; | ||||
| 	std::vector<Image*> _frames; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 精灵动作
 | ||||
| class Animate : | ||||
| 	public Action | ||||
|  |  | |||
|  | @ -382,4 +382,65 @@ private: | |||
| 	static void __discardResources(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 垃圾回收装置
 | ||||
| class GC | ||||
| { | ||||
| 	friend Game; | ||||
| 	friend Object; | ||||
| 
 | ||||
| public: | ||||
| 	// 创建可自动回收内存的对象
 | ||||
| 	template <typename Type, typename... Args> | ||||
| 	static inline Type * create(Args&&... args) | ||||
| 	{ | ||||
| 		auto newObj = new (std::nothrow) Type(std::forward<Args>(args)...); | ||||
| 		if (newObj) | ||||
| 		{ | ||||
| 			newObj->autorelease(); | ||||
| 			return newObj; | ||||
| 		} | ||||
| 		return nullptr; | ||||
| 	} | ||||
| 
 | ||||
| 	// 保留对象
 | ||||
| 	template <typename Type> | ||||
| 	static inline void retain(Type*& p) | ||||
| 	{ | ||||
| 		if (p != nullptr) | ||||
| 		{ | ||||
| 			p->retain(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// 释放对象
 | ||||
| 	template <typename Type> | ||||
| 	static inline void release(Type*& p) | ||||
| 	{ | ||||
| 		if (p != nullptr) | ||||
| 		{ | ||||
| 			p->release(); | ||||
| 			p = nullptr; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// 通知 GC 回收垃圾内存
 | ||||
| 	static void notify(); | ||||
| 
 | ||||
| 	// 手动回收垃圾内存
 | ||||
| 	static void flush(); | ||||
| 
 | ||||
| private: | ||||
| 	// 将对象放入 GC
 | ||||
| 	static void __add( | ||||
| 		Object * pObject | ||||
| 	); | ||||
| 
 | ||||
| 	// 更新 GC
 | ||||
| 	static void __update(); | ||||
| 
 | ||||
| 	// 清空所有对象
 | ||||
| 	static void __clear(); | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -7,6 +7,8 @@ namespace e2d | |||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class ColliderManager; | ||||
| 
 | ||||
| // 碰撞事件
 | ||||
| class Collision | ||||
| { | ||||
|  | @ -37,8 +39,6 @@ private: | |||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class ColliderManager; | ||||
| 
 | ||||
| // 碰撞体
 | ||||
| class Collider : | ||||
| 	public Object | ||||
|  |  | |||
							
								
								
									
										101
									
								
								core/e2dcommon.h
								
								
								
								
							
							
						
						
									
										101
									
								
								core/e2dcommon.h
								
								
								
								
							|  | @ -523,80 +523,6 @@ protected: | |||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 帧动画
 | ||||
| class Animation : | ||||
| 	public Object | ||||
| { | ||||
| public: | ||||
| 	Animation(); | ||||
| 
 | ||||
| 	Animation( | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	Animation( | ||||
| 		double interval						/* 帧间隔(秒) */ | ||||
| 	); | ||||
| 
 | ||||
| 	Animation( | ||||
| 		double interval,					/* 帧间隔(秒) */ | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建帧动画
 | ||||
| 	static Animation * create(); | ||||
| 
 | ||||
| 	// 创建帧动画
 | ||||
| 	static Animation * create( | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建特定帧间隔的帧动画
 | ||||
| 	static Animation * create( | ||||
| 		double interval						/* 帧间隔(秒) */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建特定帧间隔的帧动画
 | ||||
| 	static Animation * create( | ||||
| 		double interval,					/* 帧间隔(秒) */ | ||||
| 		const std::vector<Image*>& frames	/* 关键帧数组 */ | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Animation(); | ||||
| 
 | ||||
| 	// 添加关键帧
 | ||||
| 	void add( | ||||
| 		Image * frame	/* 关键帧 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加多个关键帧
 | ||||
| 	void add( | ||||
| 		const std::vector<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取帧间隔
 | ||||
| 	double getInterval() const; | ||||
| 
 | ||||
| 	// 获取关键帧
 | ||||
| 	const std::vector<Image*>& getFrames() const; | ||||
| 
 | ||||
| 	// 设置每一帧的时间间隔
 | ||||
| 	void setInterval( | ||||
| 		double interval		/* 帧间隔(秒) */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取动画的拷贝对象
 | ||||
| 	virtual Animation * clone() const; | ||||
| 
 | ||||
| 	// 销毁对象
 | ||||
| 	virtual void onDestroy() override; | ||||
| 
 | ||||
| protected: | ||||
| 	double	_interval; | ||||
| 	std::vector<Image*> _frames; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class Node; | ||||
| class SceneManager; | ||||
| class Transition; | ||||
|  | @ -688,31 +614,4 @@ protected: | |||
| }; | ||||
| 
 | ||||
| 
 | ||||
| template <typename Type, typename... Types> | ||||
| inline Type * Create(Types&&... args) | ||||
| { | ||||
| 	auto newObj = new (std::nothrow) Type(std::forward<Types>(args)...); | ||||
| 	if (newObj) | ||||
| 	{ | ||||
| 		newObj->autorelease(); | ||||
| 		return newObj; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		return nullptr; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| template <typename Type> | ||||
| inline void SafeRelease(Type*& p) | ||||
| {  | ||||
| 	if (p != nullptr) | ||||
| 	{  | ||||
| 		p->release();  | ||||
| 		p = nullptr;  | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -15,29 +15,6 @@ class Player; | |||
| class Collider; | ||||
| class Transition; | ||||
| 
 | ||||
| // 对象管理器
 | ||||
| class ObjectManager | ||||
| { | ||||
| 	friend Game; | ||||
| 	friend Object; | ||||
| 
 | ||||
| public: | ||||
| 	// 释放垃圾对象的内存空间
 | ||||
| 	static void flush(); | ||||
| 
 | ||||
| private: | ||||
| 	// 将对象放入内存池进行管理
 | ||||
| 	static void __add( | ||||
| 		Object * pObject | ||||
| 	); | ||||
| 
 | ||||
| 	// 更新对象管理器
 | ||||
| 	static void __update(); | ||||
| 
 | ||||
| 	// 清空所有对象
 | ||||
| 	static void __clear(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 场景管理器
 | ||||
| class SceneManager | ||||
|  |  | |||
|  | @ -197,6 +197,7 @@ | |||
|   </ItemDefinitionGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\core\Action\Action.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Action\Animation.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Action\CallFunc.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Action\Delay.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Action\JumpBy.cpp" /> | ||||
|  | @ -215,6 +216,7 @@ | |||
|     <ClCompile Include="..\..\core\Action\ActionGradual.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Action\Spawn.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Base\Game.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Base\GC.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Base\Input.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Base\Renderer.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Base\Time.cpp" /> | ||||
|  | @ -224,7 +226,6 @@ | |||
|     <ClCompile Include="..\..\core\Collider\ColliderEllipse.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Collider\ColliderRect.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Collider\Collision.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Common\Animation.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Common\Color.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Common\Function.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Common\Object.cpp" /> | ||||
|  | @ -236,7 +237,6 @@ | |||
|     <ClCompile Include="..\..\core\Custom\CustomTextRenderer.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Manager\ActionManager.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Manager\InputManager.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Manager\ObjectManager.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Manager\ColliderManager.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Manager\SceneManager.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Button.cpp" /> | ||||
|  |  | |||
|  | @ -54,9 +54,6 @@ | |||
|     <ClCompile Include="..\..\core\Manager\ActionManager.cpp"> | ||||
|       <Filter>Manager</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Manager\ObjectManager.cpp"> | ||||
|       <Filter>Manager</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Node\Button.cpp"> | ||||
|       <Filter>Node</Filter> | ||||
|     </ClCompile> | ||||
|  | @ -207,9 +204,6 @@ | |||
|     <ClCompile Include="..\..\core\Action\Animate.cpp"> | ||||
|       <Filter>Action</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Common\Animation.cpp"> | ||||
|       <Filter>Common</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Action\JumpBy.cpp"> | ||||
|       <Filter>Action</Filter> | ||||
|     </ClCompile> | ||||
|  | @ -225,6 +219,12 @@ | |||
|     <ClCompile Include="..\..\core\Collider\Collision.cpp"> | ||||
|       <Filter>Collider</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Action\Animation.cpp"> | ||||
|       <Filter>Action</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Base\GC.cpp"> | ||||
|       <Filter>Base</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue