| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | #include "..\emanagers.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | #include "..\etools.h"
 | 
					
						
							|  |  |  | #include "..\enodes.h"
 | 
					
						
							|  |  |  | #include "..\Win\winbase.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | static std::vector<e2d::ETimer*> s_vTimers; | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::TimerProc() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-04 10:03:14 +08:00
										 |  |  | 	if (s_vTimers.empty()) | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (size_t i = 0; i < s_vTimers.size(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		auto &t = s_vTimers[i]; | 
					
						
							| 
									
										
										
										
											2017-11-08 15:23:07 +08:00
										 |  |  | 		if (t->_isReady()) | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-08 15:23:07 +08:00
										 |  |  | 			t->_callOn(); | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | void e2d::ETimerManager::bindTimer(ETimer * timer, EScene * pParentScene) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 	ETimerManager::bindTimer(timer, pParentScene->getRoot()); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::bindTimer(ETimer * timer, ENode * pParentNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	WARN_IF(timer == nullptr, "ETimer NULL pointer exception!"); | 
					
						
							|  |  |  | 	WARN_IF(pParentNode == nullptr, "Bind ETimer with a NULL ENode pointer!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (timer && pParentNode) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 		ASSERT( | 
					
						
							|  |  |  | 			!timer->m_pParentNode, | 
					
						
							|  |  |  | 			"The timer is already binded, it cannot bind again!" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		timer->start(); | 
					
						
							|  |  |  | 		timer->retain(); | 
					
						
							|  |  |  | 		timer->m_pParentNode = pParentNode; | 
					
						
							|  |  |  | 		s_vTimers.push_back(timer); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::startTimers(const EString & name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		if ((*timer)->getName() == name) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 			(*timer)->start(); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::stopTimers(const EString & name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		if ((*timer)->getName() == name) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 			(*timer)->stop(); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::delTimers(const EString & name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	std::vector<ETimer*>::iterator mIter; | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	for (mIter = s_vTimers.begin(); mIter != s_vTimers.end();) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ((*mIter)->getName() == name) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  | 			SafeRelease(&(*mIter)); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 			mIter = s_vTimers.erase(mIter); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			mIter++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::startAllTimersBindedWith(EScene * pParentScene) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 	ETimerManager::startAllTimersBindedWith(pParentScene->getRoot()); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::stopAllTimersBindedWith(EScene * pParentScene) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 	ETimerManager::stopAllTimersBindedWith(pParentScene->getRoot()); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::startAllTimersBindedWith(ENode * pParentNode) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		if ((*timer)->getParentNode() == pParentNode) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 			(*timer)->start(); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		ETimerManager::startAllTimersBindedWith((*child)); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::stopAllTimersBindedWith(ENode * pParentNode) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		if ((*timer)->getParentNode() == pParentNode) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 			(*timer)->stop(); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		ETimerManager::stopAllTimersBindedWith((*child)); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | void e2d::ETimerManager::_clearAllTimersBindedWith(ENode * pParentNode) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	for (size_t i = 0; i < s_vTimers.size();) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		auto t = s_vTimers[i]; | 
					
						
							|  |  |  | 		if (t->getParentNode() == pParentNode) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  | 			SafeRelease(&t); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 			s_vTimers.erase(s_vTimers.begin() + i); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | void e2d::ETimerManager::_clearManager() | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | 	s_vTimers.clear(); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | void e2d::ETimerManager::_resetAllTimers() | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		(*timer)->m_tLast = GetNow(); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::startAllTimers() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ETimerManager::startAllTimersBindedWith(EApp::getCurrentScene()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ETimerManager::stopAllTimers() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ETimerManager::stopAllTimersBindedWith(EApp::getCurrentScene()); | 
					
						
							|  |  |  | } |