forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop.cpp
911 lines (794 loc) · 22.2 KB
/
loop.cpp
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project
Warzone 2100 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 2 of the License, or
(at your option) any later version.
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Loop.c
*
* The main game loop
*
*/
#include "lib/framework/frame.h"
#include "lib/framework/input.h"
#include "lib/framework/strres.h"
#include "lib/framework/wzapp.h"
#include "lib/framework/rational.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/piestate.h" //ivis render code
#include "lib/ivis_opengl/piemode.h"
// FIXME Direct iVis implementation include!
#include "lib/ivis_opengl/screen.h"
#include "lib/gamelib/gtime.h"
#include "lib/gamelib/animobj.h"
#include "lib/script/script.h"
#include "lib/sound/audio.h"
#include "lib/sound/cdaudio.h"
#include "lib/sound/mixer.h"
#include "lib/netplay/netplay.h"
#include "loop.h"
#include "objects.h"
#include "display.h"
#include "map.h"
#include "hci.h"
#include "ingameop.h"
#include "miscimd.h"
#include "effects.h"
#include "radar.h"
#include "projectile.h"
#include "console.h"
#include "power.h"
#include "message.h"
#include "bucket3d.h"
#include "display3d.h"
#include "warzoneconfig.h"
#include "multiplay.h" //ajl
#include "scripttabs.h"
#include "levels.h"
#include "visibility.h"
#include "multimenu.h"
#include "intelmap.h"
#include "loadsave.h"
#include "game.h"
#include "multijoin.h"
#include "lighting.h"
#include "intimage.h"
#include "lib/framework/cursors.h"
#include "seqdisp.h"
#include "mission.h"
#include "warcam.h"
#include "lighting.h"
#include "mapgrid.h"
#include "edit3d.h"
#include "drive.h"
#include "fpath.h"
#include "scriptextern.h"
#include "cluster.h"
#include "cmddroid.h"
#include "keybind.h"
#include "wrappers.h"
#include "random.h"
#include "qtscript.h"
#include "warzoneconfig.h"
#ifdef DEBUG
#include "objmem.h"
#endif
#include <numeric>
static void fireWaitingCallbacks(void);
/*
* Global variables
*/
unsigned int loopPieCount;
unsigned int loopPolyCount;
unsigned int loopStateChanges;
/*
* local variables
*/
static bool paused=false;
static bool video=false;
//holds which pause is valid at any one time
struct PAUSE_STATE
{
bool gameUpdatePause;
bool audioPause;
bool scriptPause;
bool scrollPause;
bool consolePause;
bool editPause;
};
static PAUSE_STATE pauseState;
static UDWORD numDroids[MAX_PLAYERS];
static UDWORD numMissionDroids[MAX_PLAYERS];
static UDWORD numTransporterDroids[MAX_PLAYERS];
static UDWORD numCommandDroids[MAX_PLAYERS];
static UDWORD numConstructorDroids[MAX_PLAYERS];
static SDWORD videoMode = 0;
LOOP_MISSION_STATE loopMissionState = LMS_NORMAL;
// this is set by scrStartMission to say what type of new level is to be started
SDWORD nextMissionType = LDS_NONE;//MISSION_NONE;
/* Force 3D display */
UDWORD mcTime;
static GAMECODE renderLoop()
{
if (bMultiPlayer && !NetPlay.isHostAlive && NetPlay.bComms && !NetPlay.isHost)
{
intAddInGamePopup();
}
HandleClosingWindows(); // Needs to be done outside the pause case.
audio_Update();
wzShowMouse(true);
INT_RETVAL intRetVal = INT_NONE;
if (!paused)
{
/* Run the in game interface and see if it grabbed any mouse clicks */
if (!rotActive && getWidgetsStatus() && dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING)
{
intRetVal = intRunWidgets();
// Send droid orders, if any. (Should do between intRunWidgets() calls, to avoid droid orders getting mixed up, in the case of multiple orders given while the game freezes due to net lag.)
sendQueuedDroidInfo();
}
//don't process the object lists if paused or about to quit to the front end
if (!gameUpdatePaused() && intRetVal != INT_QUIT)
{
if (dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING
&& (intRetVal == INT_INTERCEPT
|| (radarOnScreen && CoordInRadar(mouseX(), mouseY()) && radarPermitted)))
{
// Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor()
wzSetCursor(CURSOR_DEFAULT);
}
#ifdef DEBUG
// check all flag positions for duplicate delivery points
checkFactoryFlags();
#endif
//handles callbacks for positioning of DP's
process3DBuilding();
processDeliveryRepos();
//ajl. get the incoming netgame messages and process them.
// FIXME Previous comment is deprecated. multiPlayerLoop does some other weird stuff, but not that anymore.
if (bMultiPlayer)
{
multiPlayerLoop();
}
for (unsigned i = 0; i < MAX_PLAYERS; i++)
{
for (DROID *psCurr = apsDroidLists[i]; psCurr; psCurr = psCurr->psNext)
{
// Don't copy the next pointer - if droids somehow get destroyed in the graphics rendering loop, who cares if we crash.
calcDroidIllumination(psCurr);
}
}
/* update animations */
animObj_Update();
}
if (!consolePaused())
{
/* Process all the console messages */
updateConsoleMessages();
}
if (!scrollPaused() && dragBox3D.status != DRAG_DRAGGING && intMode != INT_INGAMEOP )
{
scroll();
}
}
else // paused
{
// Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor()
wzSetCursor(CURSOR_DEFAULT);
if(dragBox3D.status != DRAG_DRAGGING)
{
scroll();
}
if(InGameOpUp || isInGamePopupUp) // ingame options menu up, run it!
{
unsigned widgval = widgRunScreen(psWScreen);
intProcessInGameOptions(widgval);
if(widgval == INTINGAMEOP_QUIT_CONFIRM || widgval == INTINGAMEOP_POPUP_QUIT)
{
if(gamePaused())
{
kf_TogglePauseMode();
}
intRetVal = INT_QUIT;
}
}
if(bLoadSaveUp && runLoadSave(true) && strlen(sRequestResult))
{
debug( LOG_NEVER, "Returned %s", sRequestResult );
if(bRequestLoad)
{
loopMissionState = LMS_LOADGAME;
NET_InitPlayers(); // otherwise alliances were not cleared
sstrcpy(saveGameName, sRequestResult);
}
else
{
char msgbuffer[256]= {'\0'};
if (saveInMissionRes())
{
if (saveGame(sRequestResult, GTYPE_SAVE_START))
{
sstrcpy(msgbuffer, _("GAME SAVED: "));
sstrcat(msgbuffer, sRequestResult);
addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE);
}
else
{
ASSERT( false,"Mission Results: saveGame Failed" );
sstrcpy(msgbuffer, _("Could not save game!"));
addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE);
deleteSaveGame(sRequestResult);
}
}
else if (bMultiPlayer || saveMidMission())
{
if (saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION))//mid mission from [esc] menu
{
sstrcpy(msgbuffer, _("GAME SAVED: "));
sstrcat(msgbuffer, sRequestResult);
addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE);
}
else
{
ASSERT(!"saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION) failed", "Mid Mission: saveGame Failed" );
sstrcpy(msgbuffer, _("Could not save game!"));
addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE);
deleteSaveGame(sRequestResult);
}
}
else
{
ASSERT( false, "Attempt to save game with incorrect load/save mode" );
}
}
}
}
/* Check for quit */
bool quitting = false;
if (intRetVal == INT_QUIT)
{
if (!loop_GetVideoStatus())
{
//quitting from the game to the front end
//so get a new backdrop
quitting = true;
pie_LoadBackDrop(SCREEN_RANDOMBDROP);
}
}
if (!loop_GetVideoStatus() && !quitting)
{
if (!gameUpdatePaused())
{
if (dragBox3D.status != DRAG_DRAGGING
&& wallDrag.status != DRAG_DRAGGING
&& intRetVal != INT_INTERCEPT)
{
ProcessRadarInput();
}
processInput();
//no key clicks or in Intelligence Screen
if (!isMouseOverRadar() && intRetVal == INT_NONE && !InGameOpUp && !isInGamePopupUp)
{
processMouseClickInput();
}
displayWorld();
}
/* Display the in game interface */
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
pie_SetFogStatus(false);
if(bMultiPlayer && bDisplayMultiJoiningStatus)
{
intDisplayMultiJoiningStatus(bDisplayMultiJoiningStatus);
setWidgetsStatus(false);
}
if(getWidgetsStatus())
{
intDisplayWidgets();
}
pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
pie_SetFogStatus(true);
}
pie_GetResetCounts(&loopPieCount, &loopPolyCount, &loopStateChanges);
if ((fogStatus & FOG_BACKGROUND) && (loopMissionState == LMS_SAVECONTINUE))
{
pie_SetFogStatus(false);
}
if (!quitting)
{
/* Check for toggling display mode */
if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN))
{
wzToggleFullscreen();
}
}
// deal with the mission state
switch (loopMissionState)
{
case LMS_CLEAROBJECTS:
missionDestroyObjects();
setScriptPause(true);
loopMissionState = LMS_SETUPMISSION;
break;
case LMS_NORMAL:
// default
break;
case LMS_SETUPMISSION:
setScriptPause(false);
if (!setUpMission(nextMissionType))
{
return GAMECODE_QUITGAME;
}
break;
case LMS_SAVECONTINUE:
// just wait for this to be changed when the new mission starts
break;
case LMS_NEWLEVEL:
//nextMissionType = MISSION_NONE;
nextMissionType = LDS_NONE;
return GAMECODE_NEWLEVEL;
break;
case LMS_LOADGAME:
return GAMECODE_LOADGAME;
break;
default:
ASSERT( false, "unknown loopMissionState" );
break;
}
int clearMode = 0;
if(getDrawShadows())
{
clearMode |= CLEAR_SHADOW;
}
if (quitting || loopMissionState == LMS_SAVECONTINUE)
{
pie_SetFogStatus(false);
clearMode = CLEAR_BLACK;
}
pie_ScreenFlip(clearMode);//gameloopflip
if (quitting)
{
/* Check for toggling display mode */
if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN))
{
wzToggleFullscreen();
}
return GAMECODE_QUITGAME;
}
else if (loop_GetVideoStatus())
{
audio_StopAll();
return GAMECODE_PLAYVIDEO;
}
return GAMECODE_CONTINUE;
}
static void gameStateUpdate()
{
syncDebug("map = \"%s\", pseudorandom 32-bit integer = 0x%08X, allocated = %d %d %d %d %d %d %d %d %d %d, position = %d %d %d %d %d %d %d %d %d %d", game.map, gameRandU32(),
NetPlay.players[0].allocated, NetPlay.players[1].allocated, NetPlay.players[2].allocated, NetPlay.players[3].allocated, NetPlay.players[4].allocated, NetPlay.players[5].allocated, NetPlay.players[6].allocated, NetPlay.players[7].allocated, NetPlay.players[8].allocated, NetPlay.players[9].allocated,
NetPlay.players[0].position, NetPlay.players[1].position, NetPlay.players[2].position, NetPlay.players[3].position, NetPlay.players[4].position, NetPlay.players[5].position, NetPlay.players[6].position, NetPlay.players[7].position, NetPlay.players[8].position, NetPlay.players[9].position
);
for (unsigned n = 0; n < MAX_PLAYERS; ++n)
{
syncDebug("Player %d = \"%s\"", n, NetPlay.players[n].name);
}
// Actually send pending droid orders.
sendQueuedDroidInfo();
sendPlayerGameTime();
NETflush(); // Make sure the game time tick message is really sent over the network.
if (!paused && !scriptPaused() && !editPaused())
{
/* Update the event system */
if (!bInTutorial)
{
eventProcessTriggers(gameTime/SCR_TICKRATE);
}
else
{
eventProcessTriggers(realTime/SCR_TICKRATE);
}
updateScripts();
}
// Update abandoned structures
handleAbandonedStructures();
// Update the visibility change stuff
visUpdateLevel();
// Put all droids/structures/features into the grid.
gridReset();
// Check which objects are visible.
processVisibility();
// Update the map.
mapUpdate();
//update the findpath system
fpathUpdate();
// update the cluster system
clusterUpdate();
// update the command droids
cmdDroidUpdate();
if(getDrivingStatus())
{
driveUpdate();
}
fireWaitingCallbacks(); //Now is the good time to fire waiting callbacks (since interpreter is off now)
for (unsigned i = 0; i < MAX_PLAYERS; i++)
{
//update the current power available for a player
updatePlayerPower(i);
//set the flag for each player
setSatUplinkExists(false, i);
numCommandDroids[i] = 0;
numConstructorDroids[i] = 0;
numDroids[i]=0;
numTransporterDroids[i]=0;
DROID *psNext;
for (DROID *psCurr = apsDroidLists[i]; psCurr != NULL; psCurr = psNext)
{
// Copy the next pointer - not 100% sure if the droid could get destroyed but this covers us anyway
psNext = psCurr->psNext;
droidUpdate(psCurr);
// update the droid counts
numDroids[i]++;
switch (psCurr->droidType)
{
case DROID_COMMAND:
numCommandDroids[i] += 1;
break;
case DROID_CONSTRUCT:
case DROID_CYBORG_CONSTRUCT:
numConstructorDroids[i] += 1;
break;
case DROID_TRANSPORTER:
case DROID_SUPERTRANSPORTER:
if( (psCurr->psGroup != NULL) )
{
DROID *psDroid = NULL;
numTransporterDroids[i] += psCurr->psGroup->refCount-1;
// and count the units inside it...
for (psDroid = psCurr->psGroup->psList; psDroid != NULL && psDroid != psCurr; psDroid = psDroid->psGrpNext)
{
if (psDroid->droidType == DROID_CYBORG_CONSTRUCT || psDroid->droidType == DROID_CONSTRUCT)
{
numConstructorDroids[i] += 1;
}
if (psDroid->droidType == DROID_COMMAND)
{
numCommandDroids[i] += 1;
}
}
}
break;
default:
break;
}
}
numMissionDroids[i]=0;
for (DROID *psCurr = mission.apsDroidLists[i]; psCurr != NULL; psCurr = psNext)
{
/* Copy the next pointer - not 100% sure if the droid could
get destroyed but this covers us anyway */
psNext = psCurr->psNext;
missionDroidUpdate(psCurr);
numMissionDroids[i]++;
switch (psCurr->droidType)
{
case DROID_COMMAND:
numCommandDroids[i] += 1;
break;
case DROID_CONSTRUCT:
case DROID_CYBORG_CONSTRUCT:
numConstructorDroids[i] += 1;
break;
case DROID_TRANSPORTER:
case DROID_SUPERTRANSPORTER:
if( (psCurr->psGroup != NULL) )
{
numTransporterDroids[i] += psCurr->psGroup->refCount-1;
}
break;
default:
break;
}
}
for (DROID *psCurr = apsLimboDroids[i]; psCurr != NULL; psCurr = psNext)
{
/* Copy the next pointer - not 100% sure if the droid could
get destroyed but this covers us anyway */
psNext = psCurr->psNext;
// count the type of units
switch (psCurr->droidType)
{
case DROID_COMMAND:
numCommandDroids[i] += 1;
break;
case DROID_CONSTRUCT:
case DROID_CYBORG_CONSTRUCT:
numConstructorDroids[i] += 1;
break;
default:
break;
}
}
// FIXME: These for-loops are code duplicationo
/*set this up AFTER droidUpdate so that if trying to building a
new one, we know whether one exists already*/
setLasSatExists(false, i);
STRUCTURE *psNBuilding;
for (STRUCTURE *psCBuilding = apsStructLists[i]; psCBuilding != NULL; psCBuilding = psNBuilding)
{
/* Copy the next pointer - not 100% sure if the structure could get destroyed but this covers us anyway */
psNBuilding = psCBuilding->psNext;
structureUpdate(psCBuilding, false);
if (psCBuilding->pStructureType->type == REF_SAT_UPLINK &&
psCBuilding->status == SS_BUILT)
{
setSatUplinkExists(true, i);
}
//don't wait for the Las Sat to be built - can't build another if one is partially built
if (asWeaponStats[psCBuilding->asWeaps[0].nStat].
weaponSubClass == WSC_LAS_SAT)
{
setLasSatExists(true, i);
}
}
for (STRUCTURE *psCBuilding = mission.apsStructLists[i]; psCBuilding != NULL; psCBuilding = psNBuilding)
{
/* Copy the next pointer - not 100% sure if the structure could get destroyed but this covers us anyway. It shouldn't do since its not even on the map!*/
psNBuilding = psCBuilding->psNext;
structureUpdate(psCBuilding, true); // update for mission
if (psCBuilding->pStructureType->type == REF_SAT_UPLINK &&
psCBuilding->status == SS_BUILT)
{
setSatUplinkExists(true, i);
}
//don't wait for the Las Sat to be built - can't build another if one is partially built
if (asWeaponStats[psCBuilding->asWeaps[0].nStat].
weaponSubClass == WSC_LAS_SAT)
{
setLasSatExists(true, i);
}
}
}
missionTimerUpdate();
proj_UpdateAll();
FEATURE *psNFeat;
for (FEATURE *psCFeat = apsFeatureLists[0]; psCFeat; psCFeat = psNFeat)
{
psNFeat = psCFeat->psNext;
featureUpdate(psCFeat);
}
objmemUpdate();
// Must end update, since we may or may not have ticked, and some message queue processing code may vary depending on whether it's in an update.
gameTimeUpdateEnd();
}
/* The main game loop */
GAMECODE gameLoop(void)
{
static uint32_t lastFlushTime = 0;
static int renderBudget = 0; // Scaled time spent rendering minus scaled time spent updating.
static bool previousUpdateWasRender = false;
const Rational renderFraction(2, 5); // Minimum fraction of time spent rendering.
const Rational updateFraction = Rational(1) - renderFraction;
while (true)
{
// Receive NET_BLAH messages.
// Receive GAME_BLAH messages, and if it's time, process exactly as many GAME_BLAH messages as required to be able to tick the gameTime.
recvMessage();
// Update gameTime and graphicsTime, and corresponding deltas. Note that gameTime and graphicsTime pause, if we aren't getting our GAME_GAME_TIME messages.
gameTimeUpdate(renderBudget > 0 || previousUpdateWasRender);
if (deltaGameTime == 0)
{
break; // Not doing a game state update.
}
ASSERT(!paused && !gameUpdatePaused() && !editPaused(), "Nonsensical pause values.");
unsigned before = wzGetTicks();
syncDebug("Begin game state update, gameTime = %d", gameTime);
gameStateUpdate();
syncDebug("End game state update, gameTime = %d", gameTime);
unsigned after = wzGetTicks();
renderBudget -= (after - before) * renderFraction.n;
renderBudget = std::max(renderBudget, (-updateFraction*500).floor());
previousUpdateWasRender = false;
ASSERT(deltaGraphicsTime == 0, "Shouldn't update graphics and game state at once.");
}
if (realTime - lastFlushTime >= 400u)
{
lastFlushTime = realTime;
NETflush(); // Make sure that we aren't waiting too long to send data.
}
unsigned before = wzGetTicks();
GAMECODE renderReturn = renderLoop();
unsigned after = wzGetTicks();
renderBudget += (after - before) * updateFraction.n;
renderBudget = std::min(renderBudget, (renderFraction*500).floor());
previousUpdateWasRender = true;
return renderReturn;
}
/* The video playback loop */
void videoLoop(void)
{
bool videoFinished;
ASSERT( videoMode == 1, "videoMode out of sync" );
// display a frame of the FMV
videoFinished = !seq_UpdateFullScreenVideo(NULL);
pie_ScreenFlip(CLEAR_BLACK);
// should we stop playing?
if (videoFinished || keyPressed(KEY_ESC) || mouseReleased(MOUSE_LMB))
{
seq_StopFullScreenVideo();
//set the next video off - if any
if (videoFinished && seq_AnySeqLeft())
{
seq_StartNextFullScreenVideo();
}
else
{
// remove the intelligence screen if necessary
if (messageIsImmediate())
{
intResetScreen(true);
setMessageImmediate(false);
}
//don't do the callback if we're playing the win/lose video
if (!getScriptWinLoseVideo())
{
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_VIDEO_QUIT);
triggerEvent(TRIGGER_VIDEO_QUIT);
}
else
{
displayGameOver(getScriptWinLoseVideo() == PLAY_WIN);
}
}
}
}
void loop_SetVideoPlaybackMode(void)
{
videoMode += 1;
paused = true;
video = true;
gameTimeStop();
pie_SetFogStatus(false);
audio_StopAll();
wzShowMouse(false);
screen_StopBackDrop();
pie_ScreenFlip(CLEAR_BLACK);
}
void loop_ClearVideoPlaybackMode(void)
{
videoMode -=1;
paused = false;
video = false;
gameTimeStart();
pie_SetFogStatus(true);
cdAudio_Resume();
wzShowMouse(true);
ASSERT( videoMode == 0, "loop_ClearVideoPlaybackMode: out of sync." );
}
SDWORD loop_GetVideoMode(void)
{
return videoMode;
}
bool loop_GetVideoStatus(void)
{
return video;
}
bool editPaused(void)
{
return pauseState.editPause;
}
void setEditPause(bool state)
{
pauseState.editPause = state;
}
bool gamePaused( void )
{
return paused;
}
void setGamePauseStatus( bool val )
{
paused = val;
}
bool gameUpdatePaused(void)
{
return pauseState.gameUpdatePause;
}
bool audioPaused(void)
{
return pauseState.audioPause;
}
bool scriptPaused(void)
{
return pauseState.scriptPause;
}
bool scrollPaused(void)
{
return pauseState.scrollPause;
}
bool consolePaused(void)
{
return pauseState.consolePause;
}
void setGameUpdatePause(bool state)
{
pauseState.gameUpdatePause = state;
}
void setAudioPause(bool state)
{
pauseState.audioPause = state;
}
void setScriptPause(bool state)
{
pauseState.scriptPause = state;
}
void setScrollPause(bool state)
{
pauseState.scrollPause = state;
}
void setConsolePause(bool state)
{
pauseState.consolePause = state;
}
//set all the pause states to the state value
void setAllPauseStates(bool state)
{
setGameUpdatePause(state);
setAudioPause(state);
setScriptPause(state);
setScrollPause(state);
setConsolePause(state);
}
UDWORD getNumDroids(UDWORD player)
{
return(numDroids[player]);
}
UDWORD getNumTransporterDroids(UDWORD player)
{
return(numTransporterDroids[player]);
}
UDWORD getNumMissionDroids(UDWORD player)
{
return(numMissionDroids[player]);
}
UDWORD getNumCommandDroids(UDWORD player)
{
return numCommandDroids[player];
}
UDWORD getNumConstructorDroids(UDWORD player)
{
return numConstructorDroids[player];
}
// increase the droid counts - used by update factory to keep the counts in sync
void incNumDroids(UDWORD player)
{
numDroids[player] += 1;
}
void incNumCommandDroids(UDWORD player)
{
numCommandDroids[player] += 1;
}
void incNumConstructorDroids(UDWORD player)
{
numConstructorDroids[player] += 1;
}
/* Fire waiting beacon messages which we couldn't run before */
static void fireWaitingCallbacks(void)
{
bool bOK = true;
while(!isMsgStackEmpty() && bOK)
{
bOK = msgStackFireTop();
if(!bOK){
ASSERT(false, "fireWaitingCallbacks: msgStackFireTop() failed (stack count: %d)", msgStackGetCount());
}
}
}