forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathGameClient.cpp
More file actions
1620 lines (1319 loc) · 47.2 KB
/
GameClient.cpp
File metadata and controls
1620 lines (1319 loc) · 47.2 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
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
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Command & Conquer Generals(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: GameClient.cpp ////////////////////////////////////////////////////
// Implementation of GameClient singleton
// Author: Michael S. Booth, March 2001
///////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "GameClient/GameClient.h"
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "Common/ActionManager.h"
#include "Common/GameEngine.h"
#include "Common/GameState.h"
#include "Common/GameUtility.h"
#include "Common/GlobalData.h"
#include "Common/PerfTimer.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "Common/Xfer.h"
#include "Common/GameLOD.h"
#include "GameClient/Anim2D.h"
#include "GameClient/CampaignManager.h"
#include "GameClient/CommandXlat.h"
#include "GameClient/ControlBar.h"
#include "GameClient/Diplomacy.h"
#include "GameClient/Display.h"
#include "GameClient/DisplayStringManager.h"
#include "GameClient/Drawable.h"
#include "GameClient/DrawGroupInfo.h"
#include "GameClient/Eva.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GlobalLanguage.h"
#include "GameClient/GraphDraw.h"
#include "GameClient/GUICommandTranslator.h"
#include "GameClient/HeaderTemplate.h"
#include "GameClient/HintSpy.h"
#include "GameClient/HotKey.h"
#include "GameClient/IMEManager.h"
#include "GameClient/InGameUI.h"
#include "GameClient/Keyboard.h"
#include "GameClient/LanguageFilter.h"
#include "GameClient/LookAtXlat.h"
#include "GameClient/MetaEvent.h"
#include "GameClient/Mouse.h"
#include "GameClient/ParticleSys.h"
#include "GameClient/PlaceEventTranslator.h"
#include "GameClient/RayEffect.h"
#include "GameClient/SelectionXlat.h"
#include "GameClient/Shell.h"
#include "GameClient/TerrainVisual.h"
#include "GameClient/View.h"
#include "GameClient/VideoPlayer.h"
#include "GameClient/WindowXlat.h"
#include "GameLogic/FPUControl.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/GhostObject.h"
#include "GameLogic/Object.h"
#include "GameLogic/ScriptEngine.h" // For TheScriptEngine - jkmcd
#define DRAWABLE_HASH_SIZE 8192
/// The GameClient singleton instance
GameClient *TheGameClient = nullptr;
//-------------------------------------------------------------------------------------------------
GameClient::GameClient()
{
// zero our translator list
for( Int i = 0; i < MAX_CLIENT_TRANSLATORS; i++ )
m_translators[ i ] = TRANSLATOR_ID_INVALID;
m_numTranslators = 0;
m_commandTranslator = nullptr;
m_drawableTOC.clear();
m_textBearingDrawableList.clear();
m_frame = 0;
m_drawableList = nullptr;
m_nextDrawableID = (DrawableID)1;
TheDrawGroupInfo = new DrawGroupInfo;
}
//std::vector<std::string> preloadTextureNamesGlobalHack;
//std::vector<std::string> preloadTextureNamesGlobalHack2;
//-------------------------------------------------------------------------------------------------
GameClient::~GameClient()
{
#ifdef PERF_TIMERS
delete TheGraphDraw;
TheGraphDraw = nullptr;
#endif
delete TheDrawGroupInfo;
TheDrawGroupInfo = nullptr;
// clear any drawable TOC we might have
m_drawableTOC.clear();
//DEBUG_LOG(("Preloaded texture files ------------------------------------------"));
//for (Int oog=0; oog<preloadTextureNamesGlobalHack2.size(); ++oog)
//{
// DEBUG_LOG(("%s", preloadTextureNamesGlobalHack2[oog]));
//}
//DEBUG_LOG(("------------------------------------------------------------------"));
//for (oog=0; oog<preloadTextureNamesGlobalHack.size(); ++oog)
//{
// DEBUG_LOG(("%s", preloadTextureNamesGlobalHack[oog]));
//}
//DEBUG_LOG(("End Texture files ------------------------------------------------"));
delete TheCampaignManager;
TheCampaignManager = nullptr;
// destroy all Drawables
Drawable *draw, *nextDraw;
for( draw = m_drawableList; draw; draw = nextDraw )
{
nextDraw = draw->getNextDrawable();
destroyDrawable( draw );
}
m_drawableList = nullptr;
// delete the ray effects
delete TheRayEffects;
TheRayEffects = nullptr;
// delete the hot key manager
delete TheHotKeyManager;
TheHotKeyManager = nullptr;
// destroy the in-game user interface
delete TheInGameUI;
TheInGameUI = nullptr;
// delete the shell
delete TheShell;
TheShell = nullptr;
delete TheIMEManager;
TheIMEManager = nullptr;
// delete window manager
delete TheWindowManager;
TheWindowManager = nullptr;
// delete the font library
TheFontLibrary->reset();
delete TheFontLibrary;
TheFontLibrary = nullptr;
TheMouse->reset();
delete TheMouse;
TheMouse = nullptr;
///@todo : TheTerrainVisual used to be the first thing destroyed.
//I had to put in here so that drawables free their track marks before
//the terrain visual deletes the track laying system. MW
// destroy the terrain visual representation
delete TheTerrainVisual;
TheTerrainVisual = nullptr;
// destroy the display
delete TheDisplay;
TheDisplay = nullptr;
delete TheHeaderTemplateManager;
TheHeaderTemplateManager = nullptr;
delete TheLanguageFilter;
TheLanguageFilter = nullptr;
delete TheVideoPlayer;
TheVideoPlayer = nullptr;
// destroy all translators
for( UnsignedInt i = 0; i < m_numTranslators; i++ )
TheMessageStream->removeTranslator( m_translators[ i ] );
m_numTranslators = 0;
m_commandTranslator = nullptr;
delete TheAnim2DCollection;
TheAnim2DCollection = nullptr;
delete TheMappedImageCollection;
TheMappedImageCollection = nullptr;
delete TheKeyboard;
TheKeyboard = nullptr;
delete TheDisplayStringManager;
TheDisplayStringManager = nullptr;
delete TheEva;
TheEva = nullptr;
}
//-------------------------------------------------------------------------------------------------
/** Initialize resources for the game client */
//-------------------------------------------------------------------------------------------------
void GameClient::init()
{
setFrameRate(MSEC_PER_LOGICFRAME_REAL); // from GameCommon.h... tell W3D what our expected framerate is
INI ini;
// Load the DrawGroupInfo here, before the Display Manager is loaded.
ini.loadFileDirectory("Data\\INI\\DrawGroupInfo", INI_LOAD_OVERWRITE, nullptr);
// Override the ini values with localized versions:
if (TheGlobalLanguageData && TheGlobalLanguageData->m_drawGroupInfoFont.name.isNotEmpty())
{
TheDrawGroupInfo->m_fontName = TheGlobalLanguageData->m_drawGroupInfoFont.name;
TheDrawGroupInfo->m_fontSize = TheGlobalLanguageData->m_drawGroupInfoFont.size;
TheDrawGroupInfo->m_fontIsBold = TheGlobalLanguageData->m_drawGroupInfoFont.bold;
}
// create the display string factory
TheDisplayStringManager = createDisplayStringManager();
if( TheDisplayStringManager ) {
TheDisplayStringManager->init();
TheDisplayStringManager->setName("TheDisplayStringManager");
}
if (!TheGlobalData->m_headless)
{
// create the keyboard
TheKeyboard = createKeyboard();
TheKeyboard->init();
TheKeyboard->setName("TheKeyboard");
}
// allocate and load image collection for the GUI and just load the 256x256 ones for now
TheMappedImageCollection = MSGNEW("GameClientSubsystem") ImageCollection;
TheMappedImageCollection->load( 512 );
// now that we have all the images loaded ... load any animation definitions from those images
TheAnim2DCollection = MSGNEW("GameClientSubsystem") Anim2DCollection;
TheAnim2DCollection->init();
TheAnim2DCollection->setName("TheAnim2DCollection");
// register message translators
if( TheMessageStream )
{
//
// NOTE: Make sure m_translators[] is large enough to accommodate all the translators you
// are loading here. See MAX_CLIENT_TRANSLATORS
//
// since we only allocate one of each, don't bother pooling 'em
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") WindowTranslator, 10 );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") MetaEventTranslator, 20 );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") HotKeyTranslator, 25 );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") PlaceEventTranslator, 30 );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") GUICommandTranslator, 40 );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") SelectionTranslator, 50 );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") LookAtTranslator, 60 );
m_translators[ m_numTranslators ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") CommandTranslator, 70 );
// we keep a pointer to the command translator because it's useful
m_commandTranslator = (CommandTranslator *)TheMessageStream->findTranslator( m_translators[ m_numTranslators++ ] );
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") HintSpyTranslator, 100 );
//
// the client message translator should probably remain as the last reaction of the
// client before the messages are given to the network for processing. This
// lets all systems in the client give events that can be processed by the
// client message translator
//
m_translators[ m_numTranslators++ ] = TheMessageStream->attachTranslator( MSGNEW("GameClientSubsystem") GameClientMessageDispatcher, 999999999 );
}
// create the font library
TheFontLibrary = createFontLibrary();
if( TheFontLibrary )
TheFontLibrary->init();
// create the mouse
TheMouse = TheGlobalData->m_headless ? NEW MouseDummy : createMouse();
TheMouse->parseIni();
TheMouse->initCursorResources();
TheMouse->setName("TheMouse");
// instantiate the display
TheDisplay = createGameDisplay();
if( TheDisplay ) {
TheDisplay->init();
TheDisplay->setName("TheDisplay");
}
TheHeaderTemplateManager = MSGNEW("GameClientSubsystem") HeaderTemplateManager;
if(TheHeaderTemplateManager){
TheHeaderTemplateManager->init();
}
// create the window manager
TheWindowManager = TheGlobalData->m_headless ? NEW GameWindowManagerDummy : createWindowManager();
if( TheWindowManager )
{
TheWindowManager->init();
TheWindowManager->setName("TheWindowManager");
// TheWindowManager->initTestGUI();
}
// create the IME manager
TheIMEManager = CreateIMEManagerInterface();
if ( TheIMEManager )
{
TheIMEManager->init();
TheIMEManager->setName("TheIMEManager");
}
// create the shell
TheShell = MSGNEW("GameClientSubsystem") Shell;
if( TheShell ) {
TheShell->init();
TheShell->setName("TheShell");
}
// instantiate the in-game user interface
TheInGameUI = createInGameUI();
if( TheInGameUI ) {
TheInGameUI->init();
TheInGameUI->setName("TheInGameUI");
}
TheHotKeyManager = MSGNEW("GameClientSubsystem") HotKeyManager;
if( TheHotKeyManager ) {
TheHotKeyManager->init();
TheHotKeyManager->setName("TheHotKeyManager");
}
// instantiate the terrain visual display
TheTerrainVisual = createTerrainVisual();
if( TheTerrainVisual ) {
TheTerrainVisual->init();
TheTerrainVisual->setName("TheTerrainVisual");
}
// allocate the ray effects manager
TheRayEffects = MSGNEW("GameClientSubsystem") RayEffectSystem;
if( TheRayEffects ) {
TheRayEffects->init();
TheRayEffects->setName("TheRayEffects");
}
// set the limits of the mouse now that we've created the display and such
if( TheMouse )
{
// finish initializing the mouse.
TheMouse->init();
TheMouse->initCapture();
TheMouse->setPosition( 0, 0 );
TheMouse->setMouseLimits();
TheMouse->setName("TheMouse");
}
// create the video player
TheVideoPlayer = createVideoPlayer();
if ( TheVideoPlayer )
{
TheVideoPlayer->init();
TheVideoPlayer->setName("TheVideoPlayer");
}
// create the language filter.
TheLanguageFilter = createLanguageFilter();
if (TheLanguageFilter)
{
TheLanguageFilter->init();
TheLanguageFilter->setName("TheLanguageFilter");
}
TheCampaignManager = MSGNEW("GameClientSubsystem") CampaignManager;
TheCampaignManager->init();
TheEva = MSGNEW("GameClientSubsystem") Eva;
TheEva->init();
TheEva->setName("TheEva");
TheDisplayStringManager->postProcessLoad();
#ifdef PERF_TIMERS
TheGraphDraw = new GraphDraw;
#endif
}
//-------------------------------------------------------------------------------------------------
/** Reset the game client for a new game */
void GameClient::reset()
{
Drawable *draw, *nextDraw;
m_drawableHash.clear();
#if USING_STLPORT
m_drawableHash.resize(DRAWABLE_HASH_SIZE);
#else
m_drawableHash.reserve(DRAWABLE_HASH_SIZE);
#endif
// need to reset the in game UI to clear drawables before they are destroyed
TheInGameUI->reset();
// destroy all Drawables
for( draw = m_drawableList; draw; draw = nextDraw )
{
nextDraw = draw->getNextDrawable();
destroyDrawable( draw );
}
m_drawableList = nullptr;
TheDisplay->reset();
TheTerrainVisual->reset();
TheRayEffects->reset();
TheVideoPlayer->reset();
TheEva->reset();
// clear any drawable TOC we might have
m_drawableTOC.clear();
// TheSuperHackers @fix Mauller 13/04/2025 Reset the drawable id so it does not keep growing over the lifetime of the game.
m_nextDrawableID = (DrawableID)1;
}
/** -----------------------------------------------------------------------------------------------
* Return a new unique object id.
*/
DrawableID GameClient::allocDrawableID()
{
/// @todo Find unused value in current set
DrawableID ret = m_nextDrawableID;
m_nextDrawableID = (DrawableID)((UnsignedInt)m_nextDrawableID + 1);
return ret;
}
/** -----------------------------------------------------------------------------------------------
* Given a drawable, register it with the GameClient and give it a unique ID.
*/
void GameClient::registerDrawable( Drawable *draw )
{
// assign this drawable a unique ID, this will add it to the fast lookup table too
draw->setID( allocDrawableID() );
// add the drawable to the master list
draw->prependToList( &m_drawableList );
}
/** -----------------------------------------------------------------------------------------------
* Redraw all views, update the GUI, play sound effects, etc.
*/
DECLARE_PERF_TIMER(GameClient_update)
DECLARE_PERF_TIMER(GameClient_draw)
void GameClient::update()
{
USE_PERF_TIMER(GameClient_update)
// create the FRAME_TICK message
GameMessage *frameMsg = TheMessageStream->appendMessage( GameMessage::MSG_FRAME_TICK );
frameMsg->appendTimestampArgument( getFrame() );
static Bool playSizzle = FALSE;
// We need to show the movie first.
if(TheGlobalData->m_playIntro && !TheDisplay->isMoviePlaying())
{
if(TheGameLODManager && TheGameLODManager->didMemPass())
TheDisplay->playLogoMovie("EALogoMovie", 5000, 3000);
else
TheDisplay->playLogoMovie("EALogoMovie640", 5000, 3000);
TheWritableGlobalData->m_playIntro = FALSE;
TheWritableGlobalData->m_afterIntro = TRUE;
playSizzle = TRUE;
}
//Initial Game Condition. We must show the movie first and then we can display the shell
if(TheGlobalData->m_afterIntro && !TheDisplay->isMoviePlaying())
{
if( playSizzle && TheGlobalData->m_playSizzle )
{
TheWritableGlobalData->m_allowExitOutOfMovies = TRUE;
if(TheGameLODManager && TheGameLODManager->didMemPass())
TheDisplay->playMovie("Sizzle");
else
TheDisplay->playMovie("Sizzle640");
playSizzle = FALSE;
}
else
{
TheWritableGlobalData->m_breakTheMovie = TRUE;
TheWritableGlobalData->m_allowExitOutOfMovies = TRUE;
if(TheGameLODManager && !TheGameLODManager->didMemPass())
{
TheWritableGlobalData->m_breakTheMovie = FALSE;
WindowLayout *legal = TheWindowManager->winCreateLayout("Menus/LegalPage.wnd");
if(legal)
{
legal->hide(FALSE);
legal->bringForward();
Int beginTime = timeGetTime();
while(beginTime + 4000 > timeGetTime() )
{
if (GameClient::isMovieAbortRequested())
{
break;
}
TheWindowManager->update();
// redraw all views, update the GUI
TheDisplay->draw();
Sleep(100);
}
setFPMode();
legal->destroyWindows();
deleteInstance(legal);
}
TheWritableGlobalData->m_breakTheMovie = TRUE;
}
TheShell->showShellMap(TRUE);
TheShell->showShell();
TheWritableGlobalData->m_afterIntro = FALSE;
}
}
// update animation 2d collection
TheAnim2DCollection->UPDATE();
// update the keyboard
if( TheKeyboard )
{
TheKeyboard->UPDATE();
TheKeyboard->createStreamMessages();
}
// Update the Eva stuff
TheEva->UPDATE();
// update the mouse
if( TheMouse )
{
TheMouse->UPDATE();
TheMouse->createStreamMessages();
}
if(TheGlobalData->m_playIntro || TheGlobalData->m_afterIntro)
{
// redraw all views, update the GUI
TheDisplay->UPDATE();
TheDisplay->DRAW();
return;
}
// update the window system itself
{
TheWindowManager->UPDATE();
}
// update the video player
{
TheVideoPlayer->UPDATE();
}
const Bool freezeTime = TheGameEngine->isTimeFrozen() || TheGameEngine->isGameHalted();
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
if (!freezeTime)
{
Int numPlayers = ThePlayerList->getPlayerCount();
Int numNonLocalPlayers = 0;
Int nonLocalPlayerIndices[MAX_PLAYER_COUNT];
#if ENABLE_CONFIGURABLE_SHROUD
if (TheGlobalData->m_shroudOn)
#else
if (true)
#endif
{
if (TheGhostObjectManager->trackAllPlayers())
{
//Find indices of all active players
for (Int i=0; i < numPlayers; i++)
{
Player *player = ThePlayerList->getNthPlayer(i);
if (player->getPlayerTemplate() != nullptr && player->getPlayerIndex() != localPlayerIndex)
nonLocalPlayerIndices[numNonLocalPlayers++] = player->getPlayerIndex();
}
//update ghost objects which don't have drawables or objects.
TheGhostObjectManager->updateOrphanedObjects(nonLocalPlayerIndices, numNonLocalPlayers);
}
else
{
TheGhostObjectManager->updateOrphanedObjects(nullptr, 0);
}
}
// call the update for all client drawables
Drawable* draw = firstDrawable();
while (draw)
{ // update() could free the Drawable, so go ahead and grab 'next'
Drawable* next = draw->getNextDrawable();
#if ENABLE_CONFIGURABLE_SHROUD
if (TheGlobalData->m_shroudOn)
#else
if (true)
#endif
{
//immobile objects need to take snapshots whenever they become fogged
//so need to refresh their status. We can't rely on external calls
//to getShroudStatus() because they are only made for visible on-screen
//objects.
Object *object=draw->getObject();
if (object)
{
if (TheGhostObjectManager->trackAllPlayers())
{
// TheSuperHackers @info Update the shrouded status for all objects
// that own a ghost object for all non local players. This is costly.
if (object->hasGhostObject())
{
Int *playerIndex = nonLocalPlayerIndices;
Int *const playerIndexEnd = nonLocalPlayerIndices + numNonLocalPlayers;
for (; playerIndex < playerIndexEnd; ++playerIndex)
{
object->getShroudedStatus(*playerIndex);
}
}
}
ObjectShroudStatus ss=object->getShroudedStatus(localPlayerIndex);
if (ss >= OBJECTSHROUD_FOGGED && draw->getShroudClearFrame() != InvalidShroudClearFrame) {
UnsignedInt limit = 2*LOGICFRAMES_PER_SECOND;
if (object->isEffectivelyDead()) {
// extend the time, so we can see the dead plane blow up & crash.
limit += 3*LOGICFRAMES_PER_SECOND;
}
if (TheGameLogic->getFrame() < limit + draw->getShroudClearFrame()) {
// It's been less than 2 seconds since we could see them clear, so keep showing them.
ss = OBJECTSHROUD_CLEAR;
}
}
draw->setFullyObscuredByShroud(ss >= OBJECTSHROUD_FOGGED);
}
}
draw->updateDrawable();
draw = next;
}
}
#if defined(RTS_DEBUG)
// need to draw the first frame, then don't draw again until TheGlobalData->m_noDraw
if (TheGlobalData->m_noDraw > TheGameLogic->getFrame() && TheGameLogic->getFrame() > 0)
{
return;
}
#endif
// update all particle systems
if( !freezeTime )
{
// update particle systems
TheParticleSystemManager->setLocalPlayerIndex(localPlayerIndex);
TheParticleSystemManager->update();
}
// update the terrain visuals
{
TheTerrainVisual->UPDATE();
}
// update display
{
TheDisplay->UPDATE();
}
{
USE_PERF_TIMER(GameClient_draw)
// redraw all views, update the GUI
//if(TheGameLogic->getFrame() >= 2)
TheDisplay->DRAW();
}
{
// let display string factory handle its update
TheDisplayStringManager->update();
}
{
// update the shell
TheShell->UPDATE();
}
{
// update the in game UI
TheInGameUI->UPDATE();
}
}
void GameClient::step()
{
TheDisplay->step();
}
void GameClient::updateHeadless()
{
// TheSuperHackers @info helmutbuhler 03/05/2025 bobtista 02/02/2026
// Update particles to prevent accumulation in headless mode. Particles are generated
// during GameLogic and only cleaned up during rendering. update() lets particles finish
// their lifecycle naturally instead of abruptly removing them with reset().
TheParticleSystemManager->update();
}
Bool GameClient::isMovieAbortRequested()
{
// TheSuperHackers @feature User can skip video by pressing ESC
if (TheKeyboard)
{
TheKeyboard->UPDATE();
KeyboardIO *io = TheKeyboard->findKey(KEY_ESC, KeyboardIO::STATUS_UNUSED);
if (io && BitIsSet(io->state, KEY_STATE_DOWN))
{
io->setUsed();
return TRUE;
}
}
// TheSuperHackers @feature Service OS for Window Close / Alt-F4 events
TheGameEngine->serviceWindowsOS();
TheMessageStream->propagateMessages();
if (TheGameEngine->getQuitting() || (TheGameLogic && TheGameLogic->isQuitToDesktopRequested()))
{
return TRUE;
}
return FALSE;
}
/** -----------------------------------------------------------------------------------------------
* Call the given callback function for each object contained within the given region.
*/
void GameClient::iterateDrawablesInRegion( Region3D *region, GameClientFuncPtr userFunc, void *userData )
{
Drawable *draw, *nextDrawable;
for( draw = m_drawableList; draw; draw=nextDrawable )
{
nextDrawable = draw->getNextDrawable();
Coord3D pos = *draw->getPosition();
if( region == nullptr ||
(pos.x >= region->lo.x && pos.x <= region->hi.x &&
pos.y >= region->lo.y && pos.y <= region->hi.y &&
pos.z >= region->lo.z && pos.z <= region->hi.z) )
{
(*userFunc)( draw, userData );
}
}
}
/**Helper function to update fake GLA structures to become visible to certain players.
We should only call this during critical moments, such as changing teams, changing to
observer, etc.*/
void GameClient::updateFakeDrawables()
{
}
/** -----------------------------------------------------------------------------------------------
* Given an object id, return the associated object.
* For efficiency, a small Least Recently Used cache is incorporated.
* This method is the primary interface for accessing objects, and should be used
* instead of pointers to "attach" objects to each other.
*/
Drawable* GameClient::findDrawableByID( const DrawableID id )
{
DrawablePtrHashIt it = m_drawableHash.find(id);
if (it == m_drawableHash.end()) {
// no such drawable
return nullptr;
}
return (*it).second;
}
/** -----------------------------------------------------------------------------------------------
* Destroy the drawable immediately.
*/
void GameClient::destroyDrawable( Drawable *draw )
{
// remove any notion of the Drawable in the in-game user interface
TheInGameUI->disregardDrawable( draw );
// remove from the master list
draw->removeFromList(&m_drawableList);
//
// because drawables and objects are tightly coupled, not only MUST we maintain
// our links in all instances, but it is NECESSARY for the client to actually
// modify data in the logic, that is the pointer in an object to *this* drawable
//
Object *obj = draw->getObject();
if( obj )
{
DEBUG_ASSERTCRASH( obj->getDrawable() == draw, ("Object/Drawable pointer mismatch!") );
obj->friend_bindToDrawable( nullptr );
}
// remove the drawable from our hash of drawables
removeDrawableFromLookupTable( draw );
// free storage
deleteInstance(draw);
}
// ------------------------------------------------------------------------------------------------
/** Add drawable to lookup table for fast id searching */
// ------------------------------------------------------------------------------------------------
void GameClient::addDrawableToLookupTable(Drawable *draw )
{
// sanity
if( draw == nullptr )
return;
// add to lookup
m_drawableHash[ draw->getID() ] = draw;
}
// ------------------------------------------------------------------------------------------------
/** Remove drawable from lookup table of fast id searching */
// ------------------------------------------------------------------------------------------------
void GameClient::removeDrawableFromLookupTable( Drawable *draw )
{
// sanity
if( draw == nullptr )
return;
// remove from table
m_drawableHash.erase( draw->getID() );
}
//-------------------------------------------------------------------------------------------------
/** Load a map into the game interface */
Bool GameClient::loadMap( AsciiString mapName )
{
// sanity
if( mapName.isEmpty() )
return false;
assert( 0 ); // who calls this?
return TRUE;
}
//-------------------------------------------------------------------------------------------------
/** Unload a map from the game interface */
void GameClient::unloadMap( AsciiString mapName )
{
assert( 0 ); // who calls this?
}
//-------------------------------------------------------------------------------------------------
void GameClient::setTimeOfDay( TimeOfDay tod )
{
Drawable *draw = firstDrawable();
while( draw )
{
draw->setTimeOfDay( tod );
draw = draw->getNextDrawable();
}
}
//-------------------------------------------------------------------------------------------------
void GameClient::assignSelectedDrawablesToGroup( Int group )
{
/*
Drawable *draw = firstDrawable();
while( draw )
{
if( draw->isSelected() && draw->getObject()->isLocallyControlled())
{
draw->setDrawableGroup( group );
}
else if( draw->getDrawableGroup() == group )
{
draw->setDrawableGroup( 0 );
}
draw = draw->getNextDrawable();
}
*/
}
//-------------------------------------------------------------------------------------------------
void GameClient::selectDrawablesInGroup( Int group )
{
/*
Drawable *draw = firstDrawable();
// create a message that will assign a group ID to all the selected drawables, this
// way when we do things with this current selected group of units, we only have
// to refer to the group ID and not each individual object ID
GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
//We are creating a new group from scratch.
teamMsg->appendBooleanArgument( true );
while( draw )
{
int counter = 0;
const Object *object = draw->getObject();
if( object && draw->getDrawableGroup() == group && object->isLocallyControlled() && !object->isContained() )
{
//Only select the object if it is locally controlled and not contained by anything.
TheInGameUI->selectDrawable(draw);
teamMsg->appendObjectIDArgument( draw->getObject()->getID() );
}
else
{
TheInGameUI->deselectDrawable(draw);
}
draw = draw->getNextDrawable();
counter++;
}
*/
}
// ------------------------------------------------------------------------------------------------
void GameClient::addTextBearingDrawable( Drawable *tbd )
{
if ( tbd != nullptr )
m_textBearingDrawableList.push_back( tbd );
}
// ------------------------------------------------------------------------------------------------