ProcessAnimateWindow.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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: ProcessAnimateWindow.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: ProcessAnimateWindow.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Holds all the process modules for the Animate Window Class
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  50. #include "GameClient/ProcessAnimateWindow.h"
  51. #include "GameClient/AnimateWindowManager.h"
  52. #include "GameClient/GameWindow.h"
  53. #include "GameClient/Display.h"
  54. //-----------------------------------------------------------------------------
  55. // DEFINES ////////////////////////////////////////////////////////////////////
  56. //-----------------------------------------------------------------------------
  57. //-----------------------------------------------------------------------------
  58. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  59. //-----------------------------------------------------------------------------
  60. //-----------------------------------------------------------------------------
  61. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  62. //-----------------------------------------------------------------------------
  63. //-----------------------------------------------------------------------------
  64. // ProcessAnimateWindowSlideFromRight PUBLIC FUNCTIONS ////////////////////////
  65. //-----------------------------------------------------------------------------
  66. ProcessAnimateWindowSlideFromRight::ProcessAnimateWindowSlideFromRight( void )
  67. {
  68. m_maxVel.x = -40.0f; // top speed windows travel in x and y
  69. m_maxVel.y = 0.0f;
  70. m_slowDownThreshold = 80; // when widnows get this close to their resting
  71. // positions they start to slow down
  72. m_slowDownRatio = 0.67f; // how fast the windows slow down (smaller slows quicker)
  73. m_speedUpRatio = 2.0f - m_slowDownRatio; // how fast the windows speed up
  74. }
  75. //-----------------------------------------------------------------------------
  76. ProcessAnimateWindowSlideFromRight::~ProcessAnimateWindowSlideFromRight( void ) { }
  77. //-----------------------------------------------------------------------------
  78. void ProcessAnimateWindowSlideFromRight::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  79. {
  80. if(!animWin)
  81. {
  82. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  83. return;
  84. }
  85. if(animWin->getDelay() > 0)
  86. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  87. Coord2D vel = animWin->getVel();
  88. vel.x *= -1;
  89. vel.y *= -1;
  90. animWin->setVel( vel );
  91. animWin->setFinished( FALSE );
  92. }
  93. //-----------------------------------------------------------------------------
  94. void ProcessAnimateWindowSlideFromRight::initAnimateWindow( AnimateWindow *animWin )
  95. {
  96. ICoord2D restPos = {0,0};
  97. ICoord2D startPos = {0,0};
  98. ICoord2D curPos = {0,0};
  99. ICoord2D endPos = {0,0};
  100. Coord2D vel = {0.0f,0.0f};
  101. if(!animWin)
  102. {
  103. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  104. return;
  105. }
  106. animWin->setFinished( FALSE );
  107. // it's set that the window is passed in as it's current position being it's rest position
  108. // so save off the rest position
  109. GameWindow *win = animWin->getGameWindow();
  110. if(!win)
  111. {
  112. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  113. return;
  114. }
  115. win->winGetPosition(&restPos.x, &restPos.y);
  116. endPos.x = restPos.x;
  117. endPos.y = restPos.y;
  118. //set the initial positions for the window. In this case, off the Right of the screen
  119. Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  120. startPos.x = curPos.x = restPos.x + travelDistance;
  121. startPos.y = curPos.y = restPos.y;
  122. //set the window's position to the new start positions.
  123. win->winSetPosition(startPos.x, startPos.y);
  124. //Now initialize the velocities
  125. vel.x = m_maxVel.x;
  126. vel.y = 0.0f;
  127. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  128. }
  129. //-----------------------------------------------------------------------------
  130. Bool ProcessAnimateWindowSlideFromRight::updateAnimateWindow( AnimateWindow *animWin )
  131. {
  132. if(!animWin)
  133. {
  134. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  135. return TRUE;
  136. }
  137. // if the window has finished animating into position, return
  138. if(animWin->isFinished())
  139. return TRUE;
  140. // if the window hasn't started animating...return that we're not finished
  141. if(timeGetTime() < animWin->getStartTime())
  142. return FALSE;
  143. // it's set that the window is passed in as it's current position being it's rest position
  144. // so save off the rest position
  145. GameWindow *win = animWin->getGameWindow();
  146. if(!win)
  147. {
  148. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  149. return TRUE;
  150. }
  151. ICoord2D curPos = animWin->getCurPos();
  152. ICoord2D endPos = animWin->getEndPos();
  153. Coord2D vel = animWin->getVel();
  154. curPos.x += (Int)vel.x;
  155. if(curPos.x < endPos.x)
  156. {
  157. curPos.x = endPos.x;
  158. animWin->setFinished( TRUE );
  159. return TRUE;
  160. }
  161. win->winSetPosition(curPos.x, curPos.y);
  162. animWin->setCurPos(curPos);
  163. if( curPos.x - endPos.x <= m_slowDownThreshold )
  164. {
  165. vel.x *= m_slowDownRatio;
  166. }
  167. if( vel.x >= -1.0f)
  168. vel.x = -1.0f;
  169. animWin->setVel(vel);
  170. return FALSE;
  171. }
  172. Bool ProcessAnimateWindowSlideFromRight::reverseAnimateWindow( AnimateWindow *animWin )
  173. {
  174. if(!animWin)
  175. {
  176. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  177. return TRUE;
  178. }
  179. // if the window has finished animating into position, return
  180. if(animWin->isFinished())
  181. return TRUE;
  182. // if the window hasn't started animating...return that we're not finished
  183. if(timeGetTime() < animWin->getStartTime())
  184. return FALSE;
  185. // it's set that the window is passed in as it's current position being it's rest position
  186. // so save off the rest position
  187. GameWindow *win = animWin->getGameWindow();
  188. if(!win)
  189. {
  190. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  191. return TRUE;
  192. }
  193. ICoord2D curPos = animWin->getCurPos();
  194. ICoord2D startPos = animWin->getStartPos();
  195. Coord2D vel = animWin->getVel();
  196. curPos.x += (Int)vel.x;
  197. if(curPos.x > startPos.x)
  198. {
  199. curPos.x = startPos.x;
  200. animWin->setFinished( TRUE );
  201. win->winSetPosition(curPos.x, curPos.y);
  202. return TRUE;
  203. }
  204. win->winSetPosition(curPos.x, curPos.y);
  205. animWin->setCurPos(curPos);
  206. ICoord2D endPos = animWin->getEndPos();
  207. if( curPos.x - endPos.x <= m_slowDownThreshold )
  208. {
  209. vel.x *= m_speedUpRatio;
  210. }
  211. else
  212. {
  213. vel.x = -m_maxVel.x;
  214. }
  215. if( vel.x > -m_maxVel.x)
  216. vel.x = -m_maxVel.x;
  217. animWin->setVel(vel);
  218. return FALSE;
  219. }
  220. //-----------------------------------------------------------------------------
  221. // ProcessAnimateWindowSlideFromLeft PUBLIC FUNCTIONS ////////////////////////
  222. //-----------------------------------------------------------------------------
  223. ProcessAnimateWindowSlideFromLeft::ProcessAnimateWindowSlideFromLeft( void )
  224. {
  225. m_maxVel.x = 40.0f; // top speed windows travel in x and y
  226. m_maxVel.y = 0.0f;
  227. m_slowDownThreshold = 80; // when widnows get this close to their resting
  228. // positions they start to slow down
  229. m_slowDownRatio = 0.67f; // how fast the windows slow down (smaller slows quicker)
  230. m_speedUpRatio = 2.0f - m_slowDownRatio; // how fast the windows speed up
  231. }
  232. ProcessAnimateWindowSlideFromLeft::~ProcessAnimateWindowSlideFromLeft( void ) { }
  233. void ProcessAnimateWindowSlideFromLeft::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  234. {
  235. if(!animWin)
  236. {
  237. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  238. return;
  239. }
  240. if(animWin->getDelay() > 0)
  241. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  242. Coord2D vel = animWin->getVel();
  243. vel.x *= -1;
  244. vel.y *= -1;
  245. animWin->setVel( vel );
  246. }
  247. void ProcessAnimateWindowSlideFromLeft::initAnimateWindow( AnimateWindow *animWin )
  248. {
  249. ICoord2D restPos = {0,0};
  250. ICoord2D startPos = {0,0};
  251. ICoord2D curPos = {0,0};
  252. ICoord2D endPos = {0,0};
  253. Coord2D vel = {0.0f,0.0f};
  254. if(!animWin)
  255. {
  256. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  257. return;
  258. }
  259. // it's set that the window is passed in as it's current position being it's rest position
  260. // so save off the rest position
  261. GameWindow *win = animWin->getGameWindow();
  262. if(!win)
  263. {
  264. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  265. return;
  266. }
  267. win->winGetPosition(&restPos.x, &restPos.y);
  268. endPos.x = restPos.x;
  269. endPos.y = restPos.y;
  270. //set the initial positions for the window. In this case, off the Left of the screen
  271. Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  272. startPos.x = curPos.x = restPos.x - travelDistance;
  273. startPos.y = curPos.y = restPos.y;
  274. //set the window's position to the new start positions.
  275. win->winSetPosition(startPos.x, startPos.y);
  276. //Now initialize the velocities
  277. vel = m_maxVel;
  278. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  279. }
  280. Bool ProcessAnimateWindowSlideFromLeft::updateAnimateWindow( AnimateWindow *animWin )
  281. {
  282. if(!animWin)
  283. {
  284. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  285. return TRUE;
  286. }
  287. // if the window has finished animating into position, return
  288. if(animWin->isFinished())
  289. return TRUE;
  290. // if the window hasn't started animating...return that we're not finished
  291. if(timeGetTime() < animWin->getStartTime())
  292. return FALSE;
  293. // it's set that the window is passed in as it's current position being it's rest position
  294. // so save off the rest position
  295. GameWindow *win = animWin->getGameWindow();
  296. if(!win)
  297. {
  298. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  299. return TRUE;
  300. }
  301. ICoord2D curPos = animWin->getCurPos();
  302. ICoord2D endPos = animWin->getEndPos();
  303. Coord2D vel = animWin->getVel();
  304. curPos.x += (Int)vel.x;
  305. if(curPos.x > endPos.x)
  306. {
  307. curPos.x = endPos.x;
  308. animWin->setFinished( TRUE );
  309. return TRUE;
  310. }
  311. win->winSetPosition(curPos.x, curPos.y);
  312. animWin->setCurPos(curPos);
  313. if( endPos.x - curPos.x <= m_slowDownThreshold )
  314. {
  315. vel.x *= m_slowDownRatio;
  316. }
  317. if( vel.x < 1.0f)
  318. vel.x = 1.0f;
  319. animWin->setVel(vel);
  320. return FALSE;
  321. }
  322. Bool ProcessAnimateWindowSlideFromLeft::reverseAnimateWindow( AnimateWindow *animWin )
  323. {
  324. if(!animWin)
  325. {
  326. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  327. return TRUE;
  328. }
  329. // if the window has finished animating into position, return
  330. if(animWin->isFinished())
  331. return TRUE;
  332. // if the window hasn't started animating...return that we're not finished
  333. if(timeGetTime() < animWin->getStartTime())
  334. return FALSE;
  335. // it's set that the window is passed in as it's current position being it's rest position
  336. // so save off the rest position
  337. GameWindow *win = animWin->getGameWindow();
  338. if(!win)
  339. {
  340. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  341. return TRUE;
  342. }
  343. ICoord2D curPos = animWin->getCurPos();
  344. ICoord2D startPos = animWin->getStartPos();
  345. Coord2D vel = animWin->getVel();
  346. curPos.x += (Int)vel.x;
  347. if(curPos.x < startPos.x)
  348. {
  349. curPos.x = startPos.x;
  350. animWin->setFinished( TRUE );
  351. win->winSetPosition(curPos.x, curPos.y);
  352. return TRUE;
  353. }
  354. win->winSetPosition(curPos.x, curPos.y);
  355. animWin->setCurPos(curPos);
  356. ICoord2D endPos = animWin->getEndPos();
  357. if( endPos.x - curPos.x <= m_slowDownThreshold )
  358. {
  359. vel.x *= m_speedUpRatio;
  360. }
  361. else
  362. {
  363. vel.x = -m_maxVel.x;
  364. }
  365. if( vel.x < -m_maxVel.x)
  366. vel.x = -m_maxVel.x;
  367. animWin->setVel(vel);
  368. return FALSE;
  369. }
  370. //-----------------------------------------------------------------------------
  371. // ProcessAnimateWindowSlideFromTop PUBLIC FUNCTIONS ////////////////////////
  372. //-----------------------------------------------------------------------------
  373. ProcessAnimateWindowSlideFromTop::ProcessAnimateWindowSlideFromTop( void )
  374. {
  375. m_maxVel.y = 40.0f; // top speed windows travel in x and y
  376. m_maxVel.x = 0.0f;
  377. m_slowDownThreshold = 80; // when widnows get this close to their resting
  378. // positions they start to slow down
  379. m_slowDownRatio = 0.67f; // how fast the windows slow down (smaller slows quicker)
  380. m_speedUpRatio = 2.0f - m_slowDownRatio; // how fast the windows speed up
  381. }
  382. ProcessAnimateWindowSlideFromTop::~ProcessAnimateWindowSlideFromTop( void ) { }
  383. void ProcessAnimateWindowSlideFromTop::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  384. {
  385. if(!animWin)
  386. {
  387. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  388. return;
  389. }
  390. if(animWin->getDelay() > 0)
  391. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  392. Coord2D vel = animWin->getVel();
  393. vel.x *= -1;
  394. vel.y *= -1;
  395. animWin->setVel( vel );
  396. }
  397. void ProcessAnimateWindowSlideFromTop::initAnimateWindow( AnimateWindow *animWin )
  398. {
  399. ICoord2D restPos = {0,0};
  400. ICoord2D startPos = {0,0};
  401. ICoord2D curPos = {0,0};
  402. ICoord2D endPos = {0,0};
  403. Coord2D vel = {0.0f,0.0f};
  404. if(!animWin)
  405. {
  406. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  407. return;
  408. }
  409. // it's set that the window is passed in as it's current position being it's rest position
  410. // so save off the rest position
  411. GameWindow *win = animWin->getGameWindow();
  412. if(!win)
  413. {
  414. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  415. return;
  416. }
  417. win->winGetPosition(&restPos.x, &restPos.y);
  418. endPos.x = restPos.x;
  419. endPos.y = restPos.y;
  420. //set the initial positions for the window. In this case, off the Top of the screen
  421. Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  422. startPos.x = curPos.x = restPos.x ;
  423. startPos.y = curPos.y = restPos.y - travelDistance;
  424. //set the window's position to the new start positions.
  425. win->winSetPosition(startPos.x, startPos.y);
  426. //Now initialize the velocities
  427. vel = m_maxVel;
  428. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  429. }
  430. Bool ProcessAnimateWindowSlideFromTop::updateAnimateWindow( AnimateWindow *animWin )
  431. {
  432. if(!animWin)
  433. {
  434. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  435. return TRUE;
  436. }
  437. // if the window has finished animating into position, return
  438. if(animWin->isFinished())
  439. return TRUE;
  440. // if the window hasn't started animating...return that we're not finished
  441. if(timeGetTime() < animWin->getStartTime())
  442. return FALSE;
  443. // it's set that the window is passed in as it's current position being it's rest position
  444. // so save off the rest position
  445. GameWindow *win = animWin->getGameWindow();
  446. if(!win)
  447. {
  448. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  449. return TRUE;
  450. }
  451. ICoord2D curPos = animWin->getCurPos();
  452. ICoord2D endPos = animWin->getEndPos();
  453. Coord2D vel = animWin->getVel();
  454. curPos.y += (Int)vel.y;
  455. if(curPos.y > endPos.y)
  456. {
  457. curPos.y = endPos.y;
  458. win->winSetPosition(curPos.x, curPos.y);
  459. animWin->setFinished( TRUE );
  460. return TRUE;
  461. }
  462. win->winSetPosition(curPos.x, curPos.y);
  463. animWin->setCurPos(curPos);
  464. if( endPos.y - curPos.y <= m_slowDownThreshold )
  465. {
  466. vel.y *= m_slowDownRatio;
  467. }
  468. if( vel.y < 1.0f)
  469. vel.y = 1.0f;
  470. animWin->setVel(vel);
  471. return FALSE;
  472. }
  473. Bool ProcessAnimateWindowSlideFromTop::reverseAnimateWindow( AnimateWindow *animWin )
  474. {
  475. if(!animWin)
  476. {
  477. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  478. return TRUE;
  479. }
  480. // if the window has finished animating into position, return
  481. if(animWin->isFinished())
  482. return TRUE;
  483. // if the window hasn't started animating...return that we're not finished
  484. if(timeGetTime() < animWin->getStartTime())
  485. return FALSE;
  486. // it's set that the window is passed in as it's current position being it's rest position
  487. // so save off the rest position
  488. GameWindow *win = animWin->getGameWindow();
  489. if(!win)
  490. {
  491. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  492. return TRUE;
  493. }
  494. ICoord2D curPos = animWin->getCurPos();
  495. ICoord2D startPos = animWin->getStartPos();
  496. Coord2D vel = animWin->getVel();
  497. curPos.y += (Int)vel.y;
  498. if(curPos.y < startPos.y)
  499. {
  500. curPos.y = startPos.y;
  501. animWin->setFinished( TRUE );
  502. win->winSetPosition(curPos.x, curPos.y);
  503. return TRUE;
  504. }
  505. win->winSetPosition(curPos.x, curPos.y);
  506. animWin->setCurPos(curPos);
  507. ICoord2D endPos = animWin->getEndPos();
  508. if( endPos.y - curPos.y <= m_slowDownThreshold )
  509. {
  510. vel.y *= m_speedUpRatio;
  511. }
  512. else
  513. {
  514. vel.y = -m_maxVel.y;
  515. }
  516. if( vel.y < -m_maxVel.y)
  517. vel.y = -m_maxVel.y;
  518. animWin->setVel(vel);
  519. return FALSE;
  520. }
  521. //-----------------------------------------------------------------------------
  522. // ProcessAnimateWindowSlideFromBottom PUBLIC FUNCTIONS ////////////////////////
  523. //-----------------------------------------------------------------------------
  524. ProcessAnimateWindowSlideFromBottom::ProcessAnimateWindowSlideFromBottom( void )
  525. {
  526. m_maxVel.y = -40.0f; // top speed windows travel in x and y
  527. m_maxVel.x = 0.0f;
  528. m_slowDownThreshold = 80; // when widnows get this close to their resting
  529. // positions they start to slow down
  530. m_slowDownRatio = 0.67f; // how fast the windows slow down (smaller slows quicker)
  531. m_speedUpRatio = 2.0f - m_slowDownRatio; // how fast the windows speed up
  532. }
  533. ProcessAnimateWindowSlideFromBottom::~ProcessAnimateWindowSlideFromBottom( void ) { }
  534. void ProcessAnimateWindowSlideFromBottom::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  535. {
  536. if(!animWin)
  537. {
  538. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  539. return;
  540. }
  541. if(animWin->getDelay() > 0)
  542. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  543. Coord2D vel = animWin->getVel();
  544. vel.x *= -1;
  545. vel.y *= -1;
  546. animWin->setVel( vel );
  547. }
  548. void ProcessAnimateWindowSlideFromBottom::initAnimateWindow( AnimateWindow *animWin )
  549. {
  550. ICoord2D restPos = {0,0};
  551. ICoord2D startPos = {0,0};
  552. ICoord2D curPos = {0,0};
  553. ICoord2D endPos = {0,0};
  554. Coord2D vel = {0.0f,0.0f};
  555. if(!animWin)
  556. {
  557. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  558. return;
  559. }
  560. // it's set that the window is passed in as it's current position being it's rest position
  561. // so save off the rest position
  562. GameWindow *win = animWin->getGameWindow();
  563. if(!win)
  564. {
  565. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  566. return;
  567. }
  568. win->winGetPosition(&restPos.x, &restPos.y);
  569. endPos.x = restPos.x;
  570. endPos.y = restPos.y;
  571. //set the initial positions for the window. In this case, off the Bottom of the screen
  572. Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  573. startPos.x = curPos.x = restPos.x;
  574. startPos.y = curPos.y = restPos.y + travelDistance;
  575. //set the window's position to the new start positions.
  576. win->winSetPosition(startPos.x, startPos.y);
  577. //Now initialize the velocities
  578. vel = m_maxVel;
  579. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  580. }
  581. Bool ProcessAnimateWindowSlideFromBottom::updateAnimateWindow( AnimateWindow *animWin )
  582. {
  583. if(!animWin)
  584. {
  585. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  586. return TRUE;
  587. }
  588. // if the window has finished animating into position, return
  589. if(animWin->isFinished())
  590. return TRUE;
  591. // if the window hasn't started animating...return that we're not finished
  592. if(timeGetTime() < animWin->getStartTime())
  593. return FALSE;
  594. // it's set that the window is passed in as it's current position being it's rest position
  595. // so save off the rest position
  596. GameWindow *win = animWin->getGameWindow();
  597. if(!win)
  598. {
  599. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  600. return TRUE;
  601. }
  602. ICoord2D curPos = animWin->getCurPos();
  603. ICoord2D endPos = animWin->getEndPos();
  604. Coord2D vel = animWin->getVel();
  605. curPos.y += (Int)vel.y;
  606. if(curPos.y < endPos.y)
  607. {
  608. curPos.y = endPos.y;
  609. animWin->setFinished( TRUE );
  610. win->winSetPosition(curPos.x, curPos.y);
  611. return TRUE;
  612. }
  613. win->winSetPosition(curPos.x, curPos.y);
  614. animWin->setCurPos(curPos);
  615. if( curPos.y - endPos.y <= m_slowDownThreshold )
  616. {
  617. vel.y *= m_slowDownRatio;
  618. }
  619. if( vel.y >= -1.0f)
  620. vel.y = -1.0f;
  621. animWin->setVel(vel);
  622. return FALSE;
  623. }
  624. Bool ProcessAnimateWindowSlideFromBottom::reverseAnimateWindow( AnimateWindow *animWin )
  625. {
  626. if(!animWin)
  627. {
  628. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  629. return TRUE;
  630. }
  631. // if the window has finished animating into position, return
  632. if(animWin->isFinished())
  633. return TRUE;
  634. // if the window hasn't started animating...return that we're not finished
  635. if(timeGetTime() < animWin->getStartTime())
  636. return FALSE;
  637. // it's set that the window is passed in as it's current position being it's rest position
  638. // so save off the rest position
  639. GameWindow *win = animWin->getGameWindow();
  640. if(!win)
  641. {
  642. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  643. return TRUE;
  644. }
  645. ICoord2D curPos = animWin->getCurPos();
  646. ICoord2D startPos = animWin->getStartPos();
  647. Coord2D vel = animWin->getVel();
  648. curPos.y += (Int)vel.y;
  649. if(curPos.y > startPos.y)
  650. {
  651. curPos.y = startPos.y;
  652. animWin->setFinished( TRUE );
  653. win->winSetPosition(curPos.x, curPos.y);
  654. return TRUE;
  655. }
  656. win->winSetPosition(curPos.x, curPos.y);
  657. animWin->setCurPos(curPos);
  658. ICoord2D endPos = animWin->getEndPos();
  659. if( curPos.y - endPos.y <= m_slowDownThreshold )
  660. {
  661. vel.y *= m_speedUpRatio;
  662. }
  663. else
  664. {
  665. vel.y = -m_maxVel.y;
  666. }
  667. if( vel.y > -m_maxVel.y)
  668. vel.y = -m_maxVel.y;
  669. animWin->setVel(vel);
  670. return FALSE;
  671. }
  672. //-----------------------------------------------------------------------------
  673. // ProcessAnimateWindowSlideFromBottomTimed PUBLIC FUNCTIONS ////////////////////////
  674. //-----------------------------------------------------------------------------
  675. ProcessAnimateWindowSlideFromBottomTimed::ProcessAnimateWindowSlideFromBottomTimed( void )
  676. {
  677. m_maxDuration = 1000;
  678. }
  679. ProcessAnimateWindowSlideFromBottomTimed::~ProcessAnimateWindowSlideFromBottomTimed( void ) { }
  680. void ProcessAnimateWindowSlideFromBottomTimed::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  681. {
  682. ICoord2D restPos = {0,0};
  683. ICoord2D startPos = {0,0};
  684. ICoord2D curPos = {0,0};
  685. ICoord2D endPos = {0,0};
  686. Coord2D vel = {0.0f,0.0f};
  687. if(!animWin)
  688. {
  689. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  690. return;
  691. }
  692. // it's set that the window is passed in as it's current position being it's rest position
  693. // so save off the rest position
  694. GameWindow *win = animWin->getGameWindow();
  695. if(!win)
  696. {
  697. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  698. return;
  699. }
  700. restPos = animWin->getRestPos();
  701. startPos.x = restPos.x;
  702. curPos.y = startPos.y = restPos.y;
  703. //set the initial positions for the window. In this case, off the Bottom of the screen
  704. Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  705. endPos.x = curPos.x = restPos.x;
  706. endPos.y = restPos.y + travelDistance;
  707. //set the window's position to the new start positions.
  708. win->winSetPosition(startPos.x, startPos.y);
  709. UnsignedInt now = timeGetTime();
  710. DEBUG_LOG(("initReverseAnimateWindow at %d (%d->%d)\n", now, now, now + m_maxDuration));
  711. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, now, now + m_maxDuration);
  712. }
  713. void ProcessAnimateWindowSlideFromBottomTimed::initAnimateWindow( AnimateWindow *animWin )
  714. {
  715. ICoord2D restPos = {0,0};
  716. ICoord2D startPos = {0,0};
  717. ICoord2D curPos = {0,0};
  718. ICoord2D endPos = {0,0};
  719. Coord2D vel = {0.0f,0.0f};
  720. if(!animWin)
  721. {
  722. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  723. return;
  724. }
  725. // it's set that the window is passed in as it's current position being it's rest position
  726. // so save off the rest position
  727. GameWindow *win = animWin->getGameWindow();
  728. if(!win)
  729. {
  730. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  731. return;
  732. }
  733. win->winGetPosition(&restPos.x, &restPos.y);
  734. endPos.x = restPos.x;
  735. endPos.y = restPos.y;
  736. //set the initial positions for the window. In this case, off the Bottom of the screen
  737. Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  738. startPos.x = curPos.x = restPos.x;
  739. startPos.y = curPos.y = restPos.y + travelDistance;
  740. //set the window's position to the new start positions.
  741. win->winSetPosition(startPos.x, startPos.y);
  742. UnsignedInt now = timeGetTime();
  743. UnsignedInt delay = animWin->getDelay();
  744. DEBUG_LOG(("initAnimateWindow at %d (%d->%d)\n", now, now + delay, now + m_maxDuration + delay));
  745. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, now + delay, now + m_maxDuration + delay);
  746. }
  747. Bool ProcessAnimateWindowSlideFromBottomTimed::updateAnimateWindow( AnimateWindow *animWin )
  748. {
  749. if(!animWin)
  750. {
  751. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  752. return TRUE;
  753. }
  754. // if the window has finished animating into position, return
  755. if(animWin->isFinished())
  756. return TRUE;
  757. // if the window hasn't started animating...return that we're not finished
  758. if(timeGetTime() < animWin->getStartTime())
  759. return FALSE;
  760. // it's set that the window is passed in as it's current position being it's rest position
  761. // so save off the rest position
  762. GameWindow *win = animWin->getGameWindow();
  763. if(!win)
  764. {
  765. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  766. return TRUE;
  767. }
  768. ICoord2D startPos = animWin->getStartPos();
  769. ICoord2D curPos = animWin->getCurPos();
  770. ICoord2D endPos = animWin->getEndPos();
  771. UnsignedInt now = timeGetTime();
  772. UnsignedInt startTime = animWin->getStartTime();
  773. UnsignedInt endTime = animWin->getEndTime();
  774. if (now < startTime)
  775. return FALSE;
  776. Real percentDone = 1.0f - (Real)(endTime - now) / (Real)(m_maxDuration);
  777. if (now >= endTime)
  778. {
  779. curPos.y = endPos.y;
  780. animWin->setFinished( TRUE );
  781. win->winSetPosition(curPos.x, curPos.y);
  782. DEBUG_LOG(("window finished animating at %d (%d->%d)\n", now, startTime, endTime));
  783. return TRUE;
  784. }
  785. curPos.y = startPos.y + percentDone*(endPos.y - startPos.y);
  786. DEBUG_LOG(("(%d,%d) -> (%d,%d) -> (%d,%d) at %g\n",
  787. startPos.x, startPos.y, curPos.x, curPos.y, endPos.x, endPos.y, percentDone));
  788. win->winSetPosition(curPos.x, curPos.y);
  789. animWin->setCurPos(curPos);
  790. return FALSE;
  791. }
  792. Bool ProcessAnimateWindowSlideFromBottomTimed::reverseAnimateWindow( AnimateWindow *animWin )
  793. {
  794. return updateAnimateWindow(animWin);
  795. }
  796. //-----------------------------------------------------------------------------
  797. // ProcessAnimateWindowSpiral PUBLIC FUNCTIONS ////////////////////////
  798. //-----------------------------------------------------------------------------
  799. ProcessAnimateWindowSpiral::ProcessAnimateWindowSpiral( void )
  800. {
  801. m_maxR = TheDisplay->getWidth() / 2;
  802. m_deltaTheta = .33f;
  803. }
  804. //-----------------------------------------------------------------------------
  805. ProcessAnimateWindowSpiral::~ProcessAnimateWindowSpiral( void ) { }
  806. //-----------------------------------------------------------------------------
  807. void ProcessAnimateWindowSpiral::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  808. {
  809. if(!animWin)
  810. {
  811. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  812. return;
  813. }
  814. if(animWin->getDelay() > 0)
  815. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  816. Coord2D vel = animWin->getVel();
  817. vel.x = 0;
  818. vel.y = 0;
  819. animWin->setVel( vel );
  820. }
  821. //-----------------------------------------------------------------------------
  822. void ProcessAnimateWindowSpiral::initAnimateWindow( AnimateWindow *animWin )
  823. {
  824. ICoord2D restPos = {0,0};
  825. ICoord2D startPos = {0,0};
  826. ICoord2D curPos = {0,0};
  827. ICoord2D endPos = {0,0};
  828. ICoord2D size = {0,0};
  829. Coord2D vel = {0.0f,0.0f};
  830. if(!animWin)
  831. {
  832. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  833. return;
  834. }
  835. // it's set that the window is passed in as it's current position being it's rest position
  836. // so save off the rest position
  837. GameWindow *win = animWin->getGameWindow();
  838. if(!win)
  839. {
  840. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  841. return;
  842. }
  843. win->winGetPosition(&restPos.x, &restPos.y);
  844. win->winGetSize(&size.x,&size.y);
  845. endPos.x = restPos.x;
  846. endPos.y = restPos.y;
  847. //set the initial positions for the window. In this case, off the Bottom of the screen
  848. vel.x = 0;
  849. vel.y = m_maxR;
  850. startPos.x = curPos.x = (vel.y * cos(vel.x)) + endPos.x;
  851. startPos.y = curPos.y = (vel.y * sin(vel.x)) + endPos.y;
  852. //set the window's position to the new start positions.
  853. win->winSetPosition(startPos.x, startPos.y);
  854. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  855. }
  856. //-----------------------------------------------------------------------------
  857. Bool ProcessAnimateWindowSpiral::updateAnimateWindow( AnimateWindow *animWin )
  858. {
  859. if(!animWin)
  860. {
  861. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  862. return TRUE;
  863. }
  864. // if the window has finished animating into position, return
  865. if(animWin->isFinished())
  866. return TRUE;
  867. // if the window hasn't started animating...return that we're not finished
  868. if(timeGetTime() < animWin->getStartTime())
  869. return FALSE;
  870. // it's set that the window is passed in as it's current position being it's rest position
  871. // so save off the rest position
  872. GameWindow *win = animWin->getGameWindow();
  873. if(!win)
  874. {
  875. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  876. return TRUE;
  877. }
  878. ICoord2D curPos = animWin->getCurPos();
  879. ICoord2D endPos = animWin->getEndPos();
  880. Coord2D vel = animWin->getVel();
  881. curPos.x = (vel.y * cos(vel.x)) + endPos.x;
  882. curPos.y = (vel.y * sin(vel.x)) + endPos.y;
  883. vel.x = vel.x + m_deltaTheta;
  884. vel.y -=5;
  885. ICoord2D size;
  886. win->winGetSize(&size.x, &size.y);
  887. Int m_max = min(size.x/2, size.y/2);
  888. if(vel.y < m_max)
  889. {
  890. ICoord2D restPos = animWin->getRestPos();
  891. animWin->setFinished( TRUE );
  892. win->winSetPosition(restPos.x, restPos.y);
  893. return TRUE;
  894. }
  895. win->winSetPosition(curPos.x, curPos.y);
  896. animWin->setCurPos(curPos);
  897. animWin->setVel(vel);
  898. return FALSE;
  899. }
  900. //-----------------------------------------------------------------------------
  901. Bool ProcessAnimateWindowSpiral::reverseAnimateWindow( AnimateWindow *animWin )
  902. {
  903. if(!animWin)
  904. {
  905. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  906. return TRUE;
  907. }
  908. // if the window has finished animating into position, return
  909. if(animWin->isFinished())
  910. return TRUE;
  911. // it's set that the window is passed in as it's current position being it's rest position
  912. // so save off the rest position
  913. GameWindow *win = animWin->getGameWindow();
  914. if(!win)
  915. {
  916. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  917. return TRUE;
  918. }
  919. ICoord2D curPos = animWin->getCurPos();
  920. ICoord2D endPos = animWin->getEndPos();
  921. Coord2D vel = animWin->getVel();
  922. curPos.x = (vel.y * cos(vel.x)) + endPos.x;
  923. curPos.y = (vel.y * sin(vel.x)) + endPos.y;
  924. vel.x = vel.x - m_deltaTheta;
  925. vel.y +=5;
  926. ICoord2D size;
  927. win->winGetSize(&size.x, &size.y);
  928. // Int m_max = min(size.x/2, size.y/2);
  929. if(vel.y > m_maxR)
  930. {
  931. //ICoord2D restPos = animWin->getRestPos();
  932. animWin->setFinished( TRUE );
  933. //win->winSetPosition(restPos.x, restPos.y);
  934. return TRUE;
  935. }
  936. win->winSetPosition(curPos.x, curPos.y);
  937. animWin->setCurPos(curPos);
  938. animWin->setVel(vel);
  939. return FALSE;
  940. }
  941. //-----------------------------------------------------------------------------
  942. // ProcessAnimateWindowSlideFromTopFast PUBLIC FUNCTIONS ////////////////////////
  943. //-----------------------------------------------------------------------------
  944. ProcessAnimateWindowSlideFromTopFast::ProcessAnimateWindowSlideFromTopFast( void )
  945. {
  946. m_maxVel.y = 60.0f; // top speed windows travel in x and y
  947. m_maxVel.x = 0.0f;
  948. m_slowDownThreshold = 40; // when widnows get this close to their resting
  949. // positions they start to slow down
  950. m_slowDownRatio = 0.67f; // how fast the windows slow down (smaller slows quicker)
  951. m_speedUpRatio = 4.0f - m_slowDownRatio; // how fast the windows speed up
  952. }
  953. ProcessAnimateWindowSlideFromTopFast::~ProcessAnimateWindowSlideFromTopFast( void ) { }
  954. void ProcessAnimateWindowSlideFromTopFast::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  955. {
  956. if(!animWin)
  957. {
  958. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  959. return;
  960. }
  961. if(animWin->getDelay() > 0)
  962. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  963. Coord2D vel = animWin->getVel();
  964. vel.x *= -1;
  965. vel.y *= -1;
  966. animWin->setVel( vel );
  967. }
  968. void ProcessAnimateWindowSlideFromTopFast::initAnimateWindow( AnimateWindow *animWin )
  969. {
  970. ICoord2D restPos = {0,0};
  971. ICoord2D startPos = {0,0};
  972. ICoord2D curPos = {0,0};
  973. ICoord2D endPos = {0,0};
  974. Coord2D vel = {0.0f,0.0f};
  975. ICoord2D size = {0,0};
  976. if(!animWin)
  977. {
  978. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  979. return;
  980. }
  981. // it's set that the window is passed in as it's current position being it's rest position
  982. // so save off the rest position
  983. GameWindow *win = animWin->getGameWindow();
  984. if(!win)
  985. {
  986. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  987. return;
  988. }
  989. win->winGetPosition(&restPos.x, &restPos.y);
  990. endPos.x = restPos.x;
  991. endPos.y = restPos.y;
  992. win->winGetSize(&size.x, &size.y);
  993. //set the initial positions for the window. In this case, off the Top of the screen
  994. //Int travelDistance = TheDisplay->getWidth();// / 4 * 3;
  995. startPos.x = curPos.x = restPos.x ;
  996. startPos.y = curPos.y = -size.y;//restPos.y - travelDistance;
  997. //set the window's position to the new start positions.
  998. win->winSetPosition(startPos.x, startPos.y);
  999. //Now initialize the velocities
  1000. vel = m_maxVel;
  1001. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  1002. }
  1003. Bool ProcessAnimateWindowSlideFromTopFast::updateAnimateWindow( AnimateWindow *animWin )
  1004. {
  1005. if(!animWin)
  1006. {
  1007. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  1008. return TRUE;
  1009. }
  1010. // if the window has finished animating into position, return
  1011. if(animWin->isFinished())
  1012. return TRUE;
  1013. // if the window hasn't started animating...return that we're not finished
  1014. if(timeGetTime() < animWin->getStartTime())
  1015. return FALSE;
  1016. // it's set that the window is passed in as it's current position being it's rest position
  1017. // so save off the rest position
  1018. GameWindow *win = animWin->getGameWindow();
  1019. if(!win)
  1020. {
  1021. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  1022. return TRUE;
  1023. }
  1024. ICoord2D curPos = animWin->getCurPos();
  1025. ICoord2D endPos = animWin->getEndPos();
  1026. Coord2D vel = animWin->getVel();
  1027. curPos.y += (Int)vel.y;
  1028. if(curPos.y > endPos.y)
  1029. {
  1030. curPos.y = endPos.y;
  1031. win->winSetPosition(curPos.x, curPos.y);
  1032. animWin->setFinished( TRUE );
  1033. return TRUE;
  1034. }
  1035. win->winSetPosition(curPos.x, curPos.y);
  1036. animWin->setCurPos(curPos);
  1037. if( endPos.y - curPos.y <= m_slowDownThreshold )
  1038. {
  1039. vel.y *= m_slowDownRatio;
  1040. }
  1041. if( vel.y < 1.0f)
  1042. vel.y = 1.0f;
  1043. animWin->setVel(vel);
  1044. return FALSE;
  1045. }
  1046. Bool ProcessAnimateWindowSlideFromTopFast::reverseAnimateWindow( AnimateWindow *animWin )
  1047. {
  1048. if(!animWin)
  1049. {
  1050. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  1051. return TRUE;
  1052. }
  1053. // if the window has finished animating into position, return
  1054. if(animWin->isFinished())
  1055. return TRUE;
  1056. // if the window hasn't started animating...return that we're not finished
  1057. if(timeGetTime() < animWin->getStartTime())
  1058. return FALSE;
  1059. // it's set that the window is passed in as it's current position being it's rest position
  1060. // so save off the rest position
  1061. GameWindow *win = animWin->getGameWindow();
  1062. if(!win)
  1063. {
  1064. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  1065. return TRUE;
  1066. }
  1067. ICoord2D curPos = animWin->getCurPos();
  1068. ICoord2D startPos = animWin->getStartPos();
  1069. Coord2D vel = animWin->getVel();
  1070. curPos.y += (Int)vel.y;
  1071. if(curPos.y < startPos.y)
  1072. {
  1073. curPos.y = startPos.y;
  1074. animWin->setFinished( TRUE );
  1075. win->winSetPosition(curPos.x, curPos.y);
  1076. return TRUE;
  1077. }
  1078. win->winSetPosition(curPos.x, curPos.y);
  1079. animWin->setCurPos(curPos);
  1080. ICoord2D endPos = animWin->getEndPos();
  1081. if( endPos.y - curPos.y <= m_slowDownThreshold )
  1082. {
  1083. vel.y *= m_speedUpRatio;
  1084. }
  1085. else
  1086. {
  1087. vel.y = -m_maxVel.y;
  1088. }
  1089. if( vel.y < -m_maxVel.y)
  1090. vel.y = -m_maxVel.y;
  1091. animWin->setVel(vel);
  1092. return FALSE;
  1093. }
  1094. //-----------------------------------------------------------------------------
  1095. // ProcessAnimateWindowSlideFromRightFast PUBLIC FUNCTIONS ////////////////////////
  1096. //-----------------------------------------------------------------------------
  1097. ProcessAnimateWindowSlideFromRightFast::ProcessAnimateWindowSlideFromRightFast( void )
  1098. {
  1099. m_maxVel.x = -80.0f; // top speed windows travel in x and y
  1100. m_maxVel.y = 0.0f;
  1101. m_slowDownThreshold = 60; // when widnows get this close to their resting
  1102. // positions they start to slow down
  1103. m_slowDownRatio = 0.77f; // how fast the windows slow down (smaller slows quicker)
  1104. m_speedUpRatio = 3.0f - m_slowDownRatio; // how fast the windows speed up
  1105. }
  1106. //-----------------------------------------------------------------------------
  1107. ProcessAnimateWindowSlideFromRightFast::~ProcessAnimateWindowSlideFromRightFast( void ) { }
  1108. //-----------------------------------------------------------------------------
  1109. void ProcessAnimateWindowSlideFromRightFast::initReverseAnimateWindow( AnimateWindow *animWin, UnsignedInt maxDelay )
  1110. {
  1111. if(!animWin)
  1112. {
  1113. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  1114. return;
  1115. }
  1116. if(animWin->getDelay() > 0)
  1117. animWin->setStartTime(timeGetTime() + (maxDelay - animWin->getDelay()));
  1118. Coord2D vel = animWin->getVel();
  1119. vel.x *= -1;
  1120. vel.y *= -1;
  1121. animWin->setVel( vel );
  1122. animWin->setFinished( FALSE );
  1123. GameWindow * win = animWin->getGameWindow();
  1124. ICoord2D pos, tempPos;
  1125. win->winGetPosition(&pos.x, &pos.y);
  1126. tempPos = animWin->getCurPos();
  1127. tempPos.y = pos.y;
  1128. animWin->setCurPos(tempPos);
  1129. tempPos = animWin->getEndPos();
  1130. tempPos.y = pos.y;
  1131. animWin->setEndPos(tempPos);
  1132. tempPos = animWin->getStartPos();
  1133. tempPos.y = pos.y;
  1134. animWin->setStartPos(tempPos);
  1135. }
  1136. //-----------------------------------------------------------------------------
  1137. void ProcessAnimateWindowSlideFromRightFast::initAnimateWindow( AnimateWindow *animWin )
  1138. {
  1139. ICoord2D restPos = {0,0};
  1140. ICoord2D startPos = {0,0};
  1141. ICoord2D size = {0,0};
  1142. ICoord2D curPos = {0,0};
  1143. ICoord2D endPos = {0,0};
  1144. Coord2D vel = {0.0f,0.0f};
  1145. if(!animWin)
  1146. {
  1147. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into initAnimateWindow as a NULL Pointer... bad bad bad!"));
  1148. return;
  1149. }
  1150. animWin->setFinished( FALSE );
  1151. // it's set that the window is passed in as it's current position being it's rest position
  1152. // so save off the rest position
  1153. GameWindow *win = animWin->getGameWindow();
  1154. if(!win)
  1155. {
  1156. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  1157. return;
  1158. }
  1159. win->winGetPosition(&restPos.x, &restPos.y);
  1160. win->winGetSize(&size.x, &size.y);
  1161. endPos.x = restPos.x;
  1162. endPos.y = restPos.y;
  1163. //set the initial positions for the window. In this case, off the Right of the screen
  1164. Int travelDistance = TheDisplay->getWidth() - restPos.x + size.x ;// / 4 * 3;
  1165. startPos.x = curPos.x = restPos.x + travelDistance;
  1166. startPos.y = curPos.y = restPos.y;
  1167. //set the window's position to the new start positions.
  1168. win->winSetPosition(startPos.x, startPos.y);
  1169. //Now initialize the velocities
  1170. vel.x = m_maxVel.x;
  1171. vel.y = 0.0f;
  1172. animWin->setAnimData(startPos, endPos, curPos, restPos, vel, timeGetTime() + animWin->getDelay(), 0);
  1173. }
  1174. //-----------------------------------------------------------------------------
  1175. Bool ProcessAnimateWindowSlideFromRightFast::updateAnimateWindow( AnimateWindow *animWin )
  1176. {
  1177. if(!animWin)
  1178. {
  1179. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  1180. return TRUE;
  1181. }
  1182. // if the window has finished animating into position, return
  1183. if(animWin->isFinished())
  1184. return TRUE;
  1185. // if the window hasn't started animating...return that we're not finished
  1186. if(timeGetTime() < animWin->getStartTime())
  1187. return FALSE;
  1188. // it's set that the window is passed in as it's current position being it's rest position
  1189. // so save off the rest position
  1190. GameWindow *win = animWin->getGameWindow();
  1191. if(!win)
  1192. {
  1193. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  1194. return TRUE;
  1195. }
  1196. ICoord2D curPos = animWin->getCurPos();
  1197. ICoord2D endPos = animWin->getEndPos();
  1198. Coord2D vel = animWin->getVel();
  1199. curPos.x += (Int)vel.x;
  1200. if(curPos.x < endPos.x)
  1201. {
  1202. curPos.x = endPos.x;
  1203. animWin->setFinished( TRUE );
  1204. return TRUE;
  1205. }
  1206. win->winSetPosition(curPos.x, curPos.y);
  1207. animWin->setCurPos(curPos);
  1208. if( curPos.x - endPos.x <= m_slowDownThreshold )
  1209. {
  1210. vel.x *= m_slowDownRatio;
  1211. }
  1212. if( vel.x >= -1.0f)
  1213. vel.x = -1.0f;
  1214. animWin->setVel(vel);
  1215. return FALSE;
  1216. }
  1217. Bool ProcessAnimateWindowSlideFromRightFast::reverseAnimateWindow( AnimateWindow *animWin )
  1218. {
  1219. if(!animWin)
  1220. {
  1221. DEBUG_ASSERTCRASH( animWin, ("animWin was passed into updateAnimateWindow as a NULL Pointer... bad bad bad!"));
  1222. return TRUE;
  1223. }
  1224. // if the window has finished animating into position, return
  1225. if(animWin->isFinished())
  1226. return TRUE;
  1227. // if the window hasn't started animating...return that we're not finished
  1228. if(timeGetTime() < animWin->getStartTime())
  1229. return FALSE;
  1230. // it's set that the window is passed in as it's current position being it's rest position
  1231. // so save off the rest position
  1232. GameWindow *win = animWin->getGameWindow();
  1233. if(!win)
  1234. {
  1235. DEBUG_ASSERTCRASH( win, ("animWin contains a NULL Pointer for it's GameWindow... Whatup wit dat?"));
  1236. return TRUE;
  1237. }
  1238. ICoord2D curPos = animWin->getCurPos();
  1239. ICoord2D startPos = animWin->getStartPos();
  1240. Coord2D vel = animWin->getVel();
  1241. curPos.x += (Int)vel.x;
  1242. if(curPos.x > startPos.x)
  1243. {
  1244. curPos.x = startPos.x;
  1245. animWin->setFinished( TRUE );
  1246. win->winSetPosition(curPos.x, curPos.y);
  1247. return TRUE;
  1248. }
  1249. win->winSetPosition(curPos.x, curPos.y);
  1250. animWin->setCurPos(curPos);
  1251. ICoord2D endPos = animWin->getEndPos();
  1252. if( curPos.x - endPos.x <= m_slowDownThreshold )
  1253. {
  1254. vel.x *= m_speedUpRatio;
  1255. }
  1256. else
  1257. {
  1258. vel.x = -m_maxVel.x;
  1259. }
  1260. if( vel.x > -m_maxVel.x)
  1261. vel.x = -m_maxVel.x;
  1262. animWin->setVel(vel);
  1263. return FALSE;
  1264. }