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