| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | #include "..\e2daction.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Spawn::Spawn() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | e2d::Spawn::Spawn(int number, Action * action, ...) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 	va_list args; | 
					
						
							|  |  |  |  | 	va_start(args, action); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 	this->add(action); | 
					
						
							|  |  |  |  | 	for (int i = 1; i < number; i++) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 		this->add(va_arg(args, Action*)); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	va_end(args); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #ifdef HIGHER_THAN_VS2012
 | 
					
						
							|  |  |  |  | e2d::Spawn::Spawn(const std::initializer_list<Action*>& actions) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	this->add(actions); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Spawn::~Spawn() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Spawn::_init() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Action::_init(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (_target) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		for (auto action : _actions) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			action->_target = _target; | 
					
						
							|  |  |  |  | 			action->_init(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Spawn::onDestroy() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Action::onDestroy(); | 
					
						
							|  |  |  |  | 	for (auto action : _actions) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SafeRelease(&action); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Spawn::_update() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Action::_update(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	size_t doneNum = 0; | 
					
						
							|  |  |  |  | 	for (auto action : _actions) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (action->_isDone()) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			doneNum++; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			action->_update(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (doneNum == _actions.size()) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->stop(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Spawn::reset() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Action::reset(); | 
					
						
							|  |  |  |  | 	for (auto action : _actions) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		action->reset(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Spawn::_resetTime() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	for (auto action : _actions) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		action->_resetTime(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Spawn::add(Action * action) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (action) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		_actions.push_back(action); | 
					
						
							|  |  |  |  | 		action->retain(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | void e2d::Spawn::add(int number, Action * action, ...) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 	va_list args; | 
					
						
							|  |  |  |  | 	va_start(args, action); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	this->add(action); | 
					
						
							|  |  |  |  | 	for (int i = 1; i < number; i++) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 		this->add(va_arg(args, Action*)); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	va_end(args); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | #ifdef HIGHER_THAN_VS2012
 | 
					
						
							|  |  |  |  | void e2d::Spawn::add(const std::initializer_list<Action*>& actions) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	for (const auto &action : actions) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 		this->add(action); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Spawn * e2d::Spawn::clone() const | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	auto a = new Spawn(); | 
					
						
							|  |  |  |  | 	for (auto action : _actions) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		a->add(action->clone()); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Spawn * e2d::Spawn::reverse() const | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	auto a = new Spawn(); | 
					
						
							|  |  |  |  | 	for (auto action : _actions) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		a->add(action->reverse()); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	a->_actions.reserve(_actions.size()); | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							|  |  |  |  | } |