| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | #include "..\e2daction.h"
 | 
					
						
							|  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Loop::Loop(Action * action, int times /* = -1 */) | 
					
						
							|  |  |  | 	: _action(action) | 
					
						
							|  |  |  | 	, _times(0) | 
					
						
							|  |  |  | 	, _totalTimes(times) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	ASSERT(action, "Loop NULL pointer exception!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (action) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		_action = action; | 
					
						
							|  |  |  | 		_action->retain(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Loop::~Loop() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Loop * e2d::Loop::clone() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	if (_action) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 		return GC::create<Loop>(_action->clone()); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return nullptr; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-14 00:36:01 +08:00
										 |  |  | e2d::Loop * e2d::Loop::reverse() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	return GC::create<Loop>(_action); | 
					
						
							| 
									
										
										
										
											2018-05-14 00:36:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | void e2d::Loop::_init() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Action::_init(); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (_action) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		_action->_target = _target; | 
					
						
							|  |  |  | 		_action->_init(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Loop::_update() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Action::_update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (_times == _totalTimes) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		this->stop(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	if (_action) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		_action->_update(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 		if (_action->_isDone()) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-14 22:51:40 +08:00
										 |  |  | 			++_times; | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Action::reset(); | 
					
						
							|  |  |  | 			_action->reset(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 		this->stop(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Loop::reset() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Action::reset(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	if (_action) _action->reset(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	_times = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Loop::onDestroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Action::onDestroy(); | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	GC::release(_action); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Loop::_resetTime() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	if (_action) _action->_resetTime(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } |