149 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C++
		
	
	
	
		
		
			
		
	
	
			149 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C++
		
	
	
	
|  | #include "..\emanagers.h"
 | |||
|  | #include "..\ebase.h"
 | |||
|  | #include "..\etransitions.h"
 | |||
|  | #include <stack>
 | |||
|  | 
 | |||
|  | static e2d::EScene * s_pCurrentScene = nullptr; | |||
|  | static e2d::EScene * s_pNextScene = nullptr; | |||
|  | static e2d::ETransition * s_pTransition = nullptr; | |||
|  | static std::stack<e2d::EScene*> s_SceneStack; | |||
|  | 
 | |||
|  | void e2d::ESceneManager::enterScene(EScene * scene, ETransition * transition /* = nullptr */, bool saveCurrentScene /* = true */) | |||
|  | { | |||
|  | 	ASSERT(scene != nullptr, "Next scene NULL pointer exception!"); | |||
|  | 	scene->retain(); | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
 | |||
|  | 	s_pNextScene = scene; | |||
|  | 	 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	if (transition) | |||
|  | 	{ | |||
|  | 		s_pTransition = transition; | |||
|  | 		transition->retain(); | |||
|  | 		transition->_setTarget( | |||
|  | 			s_pCurrentScene, | |||
|  | 			s_pNextScene | |||
|  | 		); | |||
|  | 	} | |||
|  | 
 | |||
|  | 	if (s_pCurrentScene) | |||
|  | 	{ | |||
|  | 		s_pCurrentScene->m_bWillSave = saveCurrentScene; | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void e2d::ESceneManager::backScene(ETransition * transition /* = nullptr */) | |||
|  | { | |||
|  | 	// ջΪ<D5BB><CEAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><C3B7>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
 | |||
|  | 	WARN_IF(s_SceneStack.size() == 0, "Scene stack now is empty!"); | |||
|  | 	if (s_SceneStack.size() == 0) return; | |||
|  | 
 | |||
|  | 	// <20><>ջ<EFBFBD><D5BB>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>룬<EFBFBD><EBA3AC>Ϊ<EFBFBD><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
 | |||
|  | 	s_pNextScene = s_SceneStack.top(); | |||
|  | 	s_SceneStack.pop(); | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD>
 | |||
|  | 	if (s_pCurrentScene) | |||
|  | 	{ | |||
|  | 		s_pCurrentScene->m_bWillSave = false; | |||
|  | 	} | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	if (transition) | |||
|  | 	{ | |||
|  | 		s_pTransition = transition; | |||
|  | 		transition->retain(); | |||
|  | 		transition->_setTarget( | |||
|  | 			s_pCurrentScene, | |||
|  | 			s_pNextScene | |||
|  | 		); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void e2d::ESceneManager::clearScene() | |||
|  | { | |||
|  | 	// <20><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>ջ
 | |||
|  | 	while (s_SceneStack.size()) | |||
|  | 	{ | |||
|  | 		auto temp = s_SceneStack.top(); | |||
|  | 		SafeRelease(&temp); | |||
|  | 		s_SceneStack.pop(); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | e2d::EScene * e2d::ESceneManager::getCurrentScene() | |||
|  | { | |||
|  | 	return s_pCurrentScene; | |||
|  | } | |||
|  | 
 | |||
|  | void e2d::ESceneManager::__update() | |||
|  | { | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ִ<EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	if (s_pTransition) | |||
|  | 	{ | |||
|  | 		s_pTransition->_update(); | |||
|  | 		if (s_pTransition->isEnding()) | |||
|  | 		{ | |||
|  | 			s_pTransition->release(); | |||
|  | 			s_pTransition = nullptr; | |||
|  | 		} | |||
|  | 		return; | |||
|  | 	} | |||
|  | 
 | |||
|  | 	// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ָ<EFBFBD>벻Ϊ<EBB2BB><CEAA>ʱ<EFBFBD><CAB1><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	if (s_pNextScene) | |||
|  | 	{ | |||
|  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
 | |||
|  | 		__enterNextScene(); | |||
|  | 	} | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD>Ե<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>
 | |||
|  | 	ASSERT(s_pCurrentScene != nullptr, "Current scene NULL pointer exception."); | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	s_pCurrentScene->_update(); | |||
|  | } | |||
|  | 
 | |||
|  | void e2d::ESceneManager::__render() | |||
|  | { | |||
|  | 	// <20><><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
 | |||
|  | 	if (s_pCurrentScene) | |||
|  | 	{ | |||
|  | 		s_pCurrentScene->_render(); | |||
|  | 	} | |||
|  | 	// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	if (s_pTransition && s_pNextScene) | |||
|  | 	{ | |||
|  | 		s_pNextScene->_render(); | |||
|  | 	} | |||
|  | } | |||
|  | 
 | |||
|  | void e2d::ESceneManager::__enterNextScene() | |||
|  | { | |||
|  | 	if (s_pNextScene == nullptr) | |||
|  | 		return; | |||
|  | 
 | |||
|  | 	// ִ<>е<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> onCloseWindow <20><><EFBFBD><EFBFBD>
 | |||
|  | 	if (s_pCurrentScene) | |||
|  | 	{ | |||
|  | 		s_pCurrentScene->onExit(); | |||
|  | 
 | |||
|  | 		if (s_pCurrentScene->m_bWillSave) | |||
|  | 		{ | |||
|  | 			// <20><>Ҫ<EFBFBD><D2AA><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB>
 | |||
|  | 			s_SceneStack.push(s_pCurrentScene); | |||
|  | 		} | |||
|  | 		else | |||
|  | 		{ | |||
|  | 			SafeRelease(&s_pCurrentScene); | |||
|  | 		} | |||
|  | 	} | |||
|  | 
 | |||
|  | 	// ִ<><D6B4><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> onEnter <20><><EFBFBD><EFBFBD>
 | |||
|  | 	s_pNextScene->onEnter(); | |||
|  | 
 | |||
|  | 	s_pCurrentScene = s_pNextScene;		// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 	s_pNextScene = nullptr;				// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>
 | |||
|  | } |