AnimateWindowManager.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: AnimateWindowManager.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Mar 2002
  34. //
  35. // Filename: AnimateWindowManager.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: This will contain the logic behind the different animations that
  40. // can happen to a window.
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //-----------------------------------------------------------------------------
  45. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  46. //-----------------------------------------------------------------------------
  47. //-----------------------------------------------------------------------------
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. //-----------------------------------------------------------------------------
  50. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  51. #include "GameClient/AnimateWindowManager.h"
  52. #include "GameClient/GameWindow.h"
  53. #include "GameClient/Display.h"
  54. #include "GameClient/ProcessAnimateWindow.h"
  55. //-----------------------------------------------------------------------------
  56. // DEFINES ////////////////////////////////////////////////////////////////////
  57. //-----------------------------------------------------------------------------
  58. //-----------------------------------------------------------------------------
  59. // AnimateWindow PUBLIC FUNCTIONS /////////////////////////////////////////////
  60. //-----------------------------------------------------------------------------
  61. AnimateWindow::AnimateWindow( void )
  62. {
  63. m_delay = 0;
  64. m_startPos.x = m_startPos.y = 0;
  65. m_endPos.x = m_endPos.y = 0;
  66. m_curPos.x = m_curPos.y = 0;
  67. m_win = NULL;
  68. m_animType = WIN_ANIMATION_NONE;
  69. m_restPos.x = m_restPos.y = 0;
  70. m_vel.x = m_vel.y = 0.0f;
  71. m_needsToFinish = FALSE;
  72. m_isFinished = FALSE;
  73. m_endTime = 0;
  74. m_startTime = 0;
  75. }
  76. AnimateWindow::~AnimateWindow( void )
  77. {
  78. m_win = NULL;
  79. }
  80. void AnimateWindow::setAnimData( ICoord2D startPos, ICoord2D endPos,
  81. ICoord2D curPos, ICoord2D restPos,
  82. Coord2D vel, UnsignedInt startTime,
  83. UnsignedInt endTime )
  84. {
  85. m_startPos = startPos;
  86. m_endPos = endPos;
  87. m_curPos = curPos;
  88. m_restPos = restPos;
  89. m_vel = vel;
  90. m_startTime = startTime;
  91. m_endTime = endTime;
  92. }
  93. //-----------------------------------------------------------------------------
  94. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  95. //-----------------------------------------------------------------------------
  96. static void clearWinList(AnimateWindowList &winList)
  97. {
  98. AnimateWindow *win = NULL;
  99. while (!winList.empty())
  100. {
  101. win = *(winList.begin());
  102. winList.pop_front();
  103. if (win)
  104. win->deleteInstance();
  105. win = NULL;
  106. }
  107. }
  108. AnimateWindowManager::AnimateWindowManager( void )
  109. {
  110. // we don't allocate many of these, so no MemoryPools used
  111. m_slideFromRight = NEW ProcessAnimateWindowSlideFromRight;
  112. m_slideFromRightFast = NEW ProcessAnimateWindowSlideFromRightFast;
  113. m_slideFromLeft = NEW ProcessAnimateWindowSlideFromLeft;
  114. m_slideFromTop = NEW ProcessAnimateWindowSlideFromTop;
  115. m_slideFromTopFast = NEW ProcessAnimateWindowSlideFromTopFast;
  116. m_slideFromBottom = NEW ProcessAnimateWindowSlideFromBottom;
  117. m_spiral = NEW ProcessAnimateWindowSpiral;
  118. m_slideFromBottomTimed = NEW ProcessAnimateWindowSlideFromBottomTimed;
  119. m_winList.clear();
  120. m_needsUpdate = FALSE;
  121. m_reverse = FALSE;
  122. m_winMustFinishList.clear();
  123. }
  124. AnimateWindowManager::~AnimateWindowManager( void )
  125. {
  126. if(m_slideFromRight)
  127. delete m_slideFromRight;
  128. if(m_slideFromRightFast)
  129. delete m_slideFromRightFast;
  130. if(m_slideFromLeft)
  131. delete m_slideFromLeft;
  132. if(m_slideFromTop)
  133. delete m_slideFromTop;
  134. if(m_slideFromTopFast)
  135. delete m_slideFromTopFast;
  136. if(m_slideFromBottom)
  137. delete m_slideFromBottom;
  138. if(m_spiral)
  139. delete m_spiral;
  140. if (m_slideFromBottomTimed)
  141. delete m_slideFromBottomTimed;
  142. m_slideFromRight = NULL;
  143. resetToRestPosition( );
  144. clearWinList(m_winList);
  145. clearWinList(m_winMustFinishList);
  146. }
  147. void AnimateWindowManager::init( void )
  148. {
  149. clearWinList(m_winList);
  150. clearWinList(m_winMustFinishList);
  151. m_needsUpdate = FALSE;
  152. m_reverse = FALSE;
  153. }
  154. void AnimateWindowManager::reset( void )
  155. {
  156. resetToRestPosition();
  157. clearWinList(m_winList);
  158. clearWinList(m_winMustFinishList);
  159. m_needsUpdate = FALSE;
  160. m_reverse = FALSE;
  161. }
  162. void AnimateWindowManager::update( void )
  163. {
  164. ProcessAnimateWindow *processAnim = NULL;
  165. // if we need to update the windows that need to finish, update that list
  166. if(m_needsUpdate)
  167. {
  168. AnimateWindowList::iterator it = m_winMustFinishList.begin();
  169. m_needsUpdate = FALSE;
  170. while (it != m_winMustFinishList.end())
  171. {
  172. AnimateWindow *animWin = *it;
  173. if (!animWin)
  174. {
  175. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  176. return;
  177. }
  178. processAnim = getProcessAnimate( animWin->getAnimType() );
  179. if(processAnim)
  180. {
  181. if(m_reverse)
  182. {
  183. if(!processAnim->reverseAnimateWindow(animWin))
  184. m_needsUpdate = TRUE;
  185. }
  186. else
  187. {
  188. if(!processAnim->updateAnimateWindow(animWin))
  189. m_needsUpdate = TRUE;
  190. }
  191. }
  192. it ++;
  193. }
  194. }
  195. AnimateWindowList::iterator it = m_winList.begin();
  196. while (it != m_winList.end())
  197. {
  198. AnimateWindow *animWin = *it;
  199. if (!animWin)
  200. {
  201. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  202. return;
  203. }
  204. processAnim = getProcessAnimate( animWin->getAnimType() );
  205. if(m_reverse)
  206. {
  207. if(processAnim)
  208. processAnim->reverseAnimateWindow(animWin);
  209. }
  210. else
  211. {
  212. if(processAnim)
  213. processAnim->updateAnimateWindow(animWin);
  214. }
  215. it ++;
  216. }
  217. }
  218. void AnimateWindowManager::registerGameWindow(GameWindow *win, AnimTypes animType, Bool needsToFinish, UnsignedInt ms, UnsignedInt delayMs)
  219. {
  220. if(!win)
  221. {
  222. DEBUG_CRASH(("Win was NULL as it was passed into registerGameWindow... not good indeed"));
  223. return;
  224. }
  225. if(animType <= WIN_ANIMATION_NONE || animType >= WIN_ANIMATION_COUNT )
  226. {
  227. DEBUG_CRASH(("an Invalid WIN_ANIMATION type was passed into registerGameWindow... please fix me "));
  228. return;
  229. }
  230. // Create a new AnimateWindow class and fill in it's data.
  231. AnimateWindow *animWin = newInstance(AnimateWindow);
  232. animWin->setGameWindow(win);
  233. animWin->setAnimType(animType);
  234. animWin->setNeedsToFinish(needsToFinish);
  235. animWin->setDelay(delayMs);
  236. // Run the window through the processAnim's init function.
  237. ProcessAnimateWindow *processAnim = getProcessAnimate( animType );
  238. if(processAnim)
  239. {
  240. processAnim->setMaxDuration(ms);
  241. processAnim->initAnimateWindow( animWin );
  242. }
  243. // Add the Window to the proper list
  244. if(needsToFinish)
  245. {
  246. m_winMustFinishList.push_back(animWin);
  247. m_needsUpdate = TRUE;
  248. }
  249. else
  250. m_winList.push_back(animWin);
  251. }
  252. ProcessAnimateWindow *AnimateWindowManager::getProcessAnimate( AnimTypes animType )
  253. {
  254. switch (animType) {
  255. case WIN_ANIMATION_SLIDE_RIGHT:
  256. {
  257. return m_slideFromRight;
  258. }
  259. case WIN_ANIMATION_SLIDE_RIGHT_FAST:
  260. {
  261. return m_slideFromRightFast;
  262. }
  263. case WIN_ANIMATION_SLIDE_LEFT:
  264. {
  265. return m_slideFromLeft;
  266. }
  267. case WIN_ANIMATION_SLIDE_TOP:
  268. {
  269. return m_slideFromTop;
  270. }
  271. case WIN_ANIMATION_SLIDE_BOTTOM:
  272. {
  273. return m_slideFromBottom;
  274. }
  275. case WIN_ANIMATION_SPIRAL:
  276. {
  277. return m_spiral;
  278. }
  279. case WIN_ANIMATION_SLIDE_BOTTOM_TIMED:
  280. {
  281. return m_slideFromBottomTimed;
  282. }
  283. case WIN_ANIMATION_SLIDE_TOP_FAST:
  284. {
  285. return m_slideFromTopFast;
  286. }
  287. default:
  288. return NULL;
  289. }
  290. }
  291. void AnimateWindowManager::reverseAnimateWindow( void )
  292. {
  293. m_reverse = TRUE;
  294. m_needsUpdate = TRUE;
  295. ProcessAnimateWindow *processAnim = NULL;
  296. UnsignedInt maxDelay = 0;
  297. AnimateWindowList::iterator it = m_winMustFinishList.begin();
  298. while (it != m_winMustFinishList.end())
  299. {
  300. AnimateWindow *animWin = *it;
  301. if (!animWin)
  302. {
  303. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  304. return;
  305. }
  306. if(animWin->getDelay() > maxDelay)
  307. maxDelay = animWin->getDelay();
  308. it ++;
  309. }
  310. it = m_winMustFinishList.begin();
  311. while (it != m_winMustFinishList.end())
  312. {
  313. AnimateWindow *animWin = *it;
  314. if (!animWin)
  315. {
  316. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  317. return;
  318. }
  319. // Run the window through the processAnim's init function.
  320. processAnim = getProcessAnimate( animWin->getAnimType() );
  321. if(processAnim)
  322. {
  323. processAnim->initReverseAnimateWindow( animWin, maxDelay );
  324. }
  325. animWin->setFinished(FALSE);
  326. it ++;
  327. }
  328. it = m_winList.begin();
  329. while (it != m_winList.end())
  330. {
  331. AnimateWindow *animWin = *it;
  332. if (!animWin)
  333. {
  334. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  335. return;
  336. }
  337. processAnim = getProcessAnimate( animWin->getAnimType() );
  338. if(processAnim)
  339. processAnim->initReverseAnimateWindow(animWin);
  340. animWin->setFinished(FALSE);
  341. it ++;
  342. }
  343. }
  344. void AnimateWindowManager::resetToRestPosition( void )
  345. {
  346. m_reverse = TRUE;
  347. m_needsUpdate = TRUE;
  348. AnimateWindowList::iterator it = m_winMustFinishList.begin();
  349. while (it != m_winMustFinishList.end())
  350. {
  351. AnimateWindow *animWin = *it;
  352. if (!animWin)
  353. {
  354. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  355. return;
  356. }
  357. ICoord2D restPos = animWin->getRestPos();
  358. GameWindow *win = animWin->getGameWindow();
  359. if(win)
  360. win->winSetPosition(restPos.x, restPos.y);
  361. it ++;
  362. }
  363. it = m_winList.begin();
  364. while (it != m_winList.end())
  365. {
  366. AnimateWindow *animWin = *it;
  367. if (!animWin)
  368. {
  369. DEBUG_CRASH(("There's No AnimateWindow in the AnimateWindow List"));
  370. return;
  371. }
  372. ICoord2D restPos = animWin->getRestPos();
  373. GameWindow *win = animWin->getGameWindow();
  374. if(win)
  375. win->winSetPosition(restPos.x, restPos.y);
  376. it ++;
  377. }
  378. }
  379. //-----------------------------------------------------------------------------
  380. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  381. //-----------------------------------------------------------------------------