201 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C++
		
	
	
	
		
		
			
		
	
	
			201 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C++
		
	
	
	
|  | #include "..\easy2d.h"
 | |||
|  | #include "..\Win\winbase.h"
 | |||
|  | #include <assert.h>
 | |||
|  | 
 | |||
|  | static std::vector<Action*> s_vActions; | |||
|  | 
 | |||
|  | void ActionManager::__exec() | |||
|  | { | |||
|  | 	// <20><>ʱָ<CAB1><D6B8>
 | |||
|  | 	static Action * action; | |||
|  | 	// ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
 | |||
|  | 	for (size_t i = 0; i < s_vActions.size(); i++) | |||
|  | 	{ | |||
|  | 		action = s_vActions[i]; | |||
|  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
 | |||
|  | 		if (action->isRunning()) | |||
|  | 		{ | |||
|  | 			if (action->isEnding()) | |||
|  | 			{ | |||
|  | 				// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 				action->autoRelease(); | |||
|  | 				action->release(); | |||
|  | 				s_vActions.erase(s_vActions.begin() + i); | |||
|  | 			} | |||
|  | 			else | |||
|  | 			{ | |||
|  | 				// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 				if (!action->m_bInit) | |||
|  | 				{ | |||
|  | 					action->_init(); | |||
|  | 				} | |||
|  | 				// ִ<>ж<EFBFBD><D0B6><EFBFBD>
 | |||
|  | 				action->_exec(GetNow()); | |||
|  | 			} | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::addAction(Action * action) | |||
|  | { | |||
|  | 	if (action) | |||
|  | 	{ | |||
|  | #ifdef _DEBUG
 | |||
|  | 		for (auto a : s_vActions) | |||
|  | 		{ | |||
|  | 			assert(a != action); | |||
|  | 		} | |||
|  | #endif
 | |||
|  | 		action->m_pParentScene = EApp::getLoadingScene(); | |||
|  | 		s_vActions.push_back(action); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::notifyAllSceneActions(EScene * scene) | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		if (action->m_pParentScene == scene) | |||
|  | 		{ | |||
|  | 			action->notify(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::waitAllSceneActions(EScene * scene) | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		if (action->m_pParentScene == scene) | |||
|  | 		{ | |||
|  | 			action->wait(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::stopAllSceneActions(EScene * scene) | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		if (action->m_pParentScene == scene) | |||
|  | 		{ | |||
|  | 			action->stop(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::startAction(Action * action) | |||
|  | { | |||
|  | 	resumeAction(action); | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::resumeAction(Action * action) | |||
|  | { | |||
|  | 	for (auto act : s_vActions) | |||
|  | 	{ | |||
|  | 		if (act == action) | |||
|  | 		{ | |||
|  | 			act->resume(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::pauseAction(Action * action) | |||
|  | { | |||
|  | 	for (auto act : s_vActions) | |||
|  | 	{ | |||
|  | 		if (act == action) | |||
|  | 		{ | |||
|  | 			act->pause(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::stopAction(Action * action) | |||
|  | { | |||
|  | 	for (auto act : s_vActions) | |||
|  | 	{ | |||
|  | 		if (act == action) | |||
|  | 		{ | |||
|  | 			act->stop(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::startSpriteAllActions(Sprite * sprite) | |||
|  | { | |||
|  | 	resumeSpriteAllActions(sprite); | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::resumeSpriteAllActions(Sprite * sprite) | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		if (action->m_pTargetSprite == sprite) | |||
|  | 		{ | |||
|  | 			action->resume(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::pauseSpriteAllActions(Sprite * sprite) | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		if (action->m_pTargetSprite == sprite) | |||
|  | 		{ | |||
|  | 			action->pause(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::stopSpriteAllActions(Sprite * sprite) | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		if (action->m_pTargetSprite == sprite) | |||
|  | 		{ | |||
|  | 			action->stop(); | |||
|  | 		} | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::startAllActions() | |||
|  | { | |||
|  | 	resumeAllActions(); | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::resumeAllActions() | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		action->resume(); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::pauseAllActions() | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		action->pause(); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::stopAllActions() | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		action->stop(); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void ActionManager::clearAllActions() | |||
|  | { | |||
|  | 	for (auto action : s_vActions) | |||
|  | 	{ | |||
|  | 		action->autoRelease(); | |||
|  | 		action->release(); | |||
|  | 	} | |||
|  | 	s_vActions.clear(); | |||
|  | } |