forked from themrdemonized/xray-monolith
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePersistent.cpp
More file actions
1016 lines (882 loc) · 26.9 KB
/
GamePersistent.cpp
File metadata and controls
1016 lines (882 loc) · 26.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
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
#include "pch_script.h"
#include "gamepersistent.h"
#include "../xrEngine/fmesh.h"
#include "../xrEngine/xr_ioconsole.h"
#include "../xrEngine/gamemtllib.h"
#include "../Include/xrRender/Kinematics.h"
#include "profiler.h"
#include "MainMenu.h"
#include "script_wallmarks_manager.h"
#include "UICursor.h"
#include "game_base_space.h"
#include "level.h"
#include "ParticlesObject.h"
#include "game_base_space.h"
#include "stalker_animation_data_storage.h"
#include "stalker_velocity_holder.h"
#include "ActorEffector.h"
#include "actor.h"
#include "spectator.h"
#include "UI/UItextureMaster.h"
#include "../xrEngine/xrSASH.h"
#include "ai_space.h"
#include "../xrServerEntities/script_engine.h"
#include "holder_custom.h"
#include "game_cl_base.h"
#include "xrserver_objects_alife_monsters.h"
#include "../xrServerEntities/xrServer_Object_Base.h"
#include "UI/UIGameTutorial.h"
#include "../xrEngine/xr_input.h"
#ifndef MASTER_GOLD
# include "custommonster.h"
#endif // MASTER_GOLD
#ifndef _EDITOR
# include "ai_debug.h"
#endif // _EDITOR
#include "gametype_chooser.h"
//#ifdef DEBUG_MEMORY_MANAGER
// static void * ode_alloc (size_t size) { return Memory.mem_alloc(size,"ODE"); }
// static void * ode_realloc (void *ptr, size_t oldsize, size_t newsize) { return Memory.mem_realloc(ptr,newsize,"ODE"); }
// static void ode_free (void *ptr, size_t size) { return xr_free(ptr); }
//#else // DEBUG_MEMORY_MANAGER
// static void * ode_alloc (size_t size) { return xr_malloc(size); }
// static void * ode_realloc (void *ptr, size_t oldsize, size_t newsize) { return xr_realloc(ptr,newsize); }
// static void ode_free (void *ptr, size_t size) { return xr_free(ptr); }
//#endif // DEBUG_MEMORY_MANAGER
CGamePersistent::CGamePersistent(void)
{
m_bPickableDOF = false;
m_game_params.m_e_game_type = eGameIDNoGame;
ambient_effect_next_time = 0;
ambient_effect_stop_time = 0;
ambient_particles = 0;
ambient_effect_wind_start = 0.f;
ambient_effect_wind_in_time = 0.f;
ambient_effect_wind_end = 0.f;
ambient_effect_wind_out_time = 0.f;
ambient_effect_wind_on = false;
ZeroMemory(ambient_sound_next_time, sizeof(ambient_sound_next_time));
m_pUI_core = NULL;
m_pMainMenu = NULL;
m_intro = NULL;
m_intro_event.bind(this, &CGamePersistent::start_logo_intro);
#ifdef DEBUG
m_frame_counter = 0;
m_last_stats_frame = u32(-2);
#endif
//
//dSetAllocHandler (ode_alloc );
//dSetReallocHandler (ode_realloc );
//dSetFreeHandler (ode_free );
//
BOOL bDemoMode = (0 != strstr(Core.Params, "-demomode "));
if (bDemoMode)
{
string256 fname;
LPCSTR name = strstr(Core.Params, "-demomode ") + 10;
sscanf(name, "%s", fname);
R_ASSERT2(fname[0], "Missing filename for 'demomode'");
Msg("- playing in demo mode '%s'", fname);
pDemoFile = FS.r_open(fname);
Device.seqFrame.Add(this);
eDemoStart = Engine.Event.Handler_Attach("GAME:demo", this);
uTime2Change = 0;
}
else
{
pDemoFile = NULL;
eDemoStart = NULL;
}
eQuickLoad = Engine.Event.Handler_Attach("Game:QuickLoad", this);
Fvector3* DofValue = Console->GetFVectorPtr("r2_dof");
SetBaseDof(*DofValue);
m_pWallmarksManager = nullptr;
}
CGamePersistent::~CGamePersistent(void)
{
FS.r_close(pDemoFile);
Device.seqFrame.Remove(this);
Engine.Event.Handler_Detach(eDemoStart, this);
Engine.Event.Handler_Detach(eQuickLoad, this);
}
void CGamePersistent::RegisterModel(IRenderVisual* V)
{
// Check types
switch (V->getType())
{
case MT_SKELETON_ANIM:
case MT_SKELETON_RIGID:
{
u16 def_idx = GMLib.GetMaterialIdx("default_object");
R_ASSERT2(GMLib.GetMaterialByIdx(def_idx)->Flags.is(SGameMtl::flDynamic),
"'default_object' - must be dynamic");
IKinematics* K = smart_cast<IKinematics*>(V);
VERIFY(K);
int cnt = K->LL_BoneCount();
for (u16 k = 0; k < cnt; k++)
{
CBoneData& bd = K->LL_GetData(k);
if (*(bd.game_mtl_name))
{
bd.game_mtl_idx = GMLib.GetMaterialIdx(*bd.game_mtl_name);
R_ASSERT2(GMLib.GetMaterialByIdx(bd.game_mtl_idx)->Flags.is(SGameMtl::flDynamic),
"Required dynamic game material");
}
else
{
bd.game_mtl_idx = def_idx;
}
}
}
break;
}
}
extern void clean_game_globals();
extern void init_game_globals();
void CGamePersistent::OnAppStart()
{
// load game materials
GMLib.Load();
init_game_globals();
__super::OnAppStart();
m_pUI_core = xr_new<ui_core>();
m_pMainMenu = xr_new<CMainMenu>();
m_pWallmarksManager = xr_new<ScriptWallmarksManager>();
}
void CGamePersistent::OnAppEnd()
{
if (m_pMainMenu->IsActive())
m_pMainMenu->Activate(false);
xr_delete(m_pMainMenu);
xr_delete(m_pUI_core);
xr_delete(m_pWallmarksManager);
__super::OnAppEnd();
clean_game_globals();
GMLib.Unload();
}
void CGamePersistent::Start(LPCSTR op)
{
__super::Start(op);
}
void CGamePersistent::Disconnect()
{
// destroy ambient particles
CParticlesObject::Destroy(ambient_particles);
__super::Disconnect();
// stop all played emitters
::Sound->stop_emitters();
m_game_params.m_e_game_type = eGameIDNoGame;
}
#include "xr_level_controller.h"
void CGamePersistent::OnGameStart()
{
__super::OnGameStart();
UpdateGameType();
}
LPCSTR GameTypeToString(EGameIDs gt, bool bShort)
{
switch (gt)
{
case eGameIDSingle:
return "single";
break;
case eGameIDDeathmatch:
return (bShort) ? "dm" : "deathmatch";
break;
case eGameIDTeamDeathmatch:
return (bShort) ? "tdm" : "teamdeathmatch";
break;
case eGameIDArtefactHunt:
return (bShort) ? "ah" : "artefacthunt";
break;
case eGameIDCaptureTheArtefact:
return (bShort) ? "cta" : "capturetheartefact";
break;
case eGameIDDominationZone:
return (bShort) ? "dz" : "dominationzone";
break;
case eGameIDTeamDominationZone:
return (bShort) ? "tdz" : "teamdominationzone";
break;
default:
return "---";
}
}
EGameIDs ParseStringToGameType(LPCSTR str)
{
if (!xr_strcmp(str, "single"))
return eGameIDSingle;
else if (!xr_strcmp(str, "deathmatch") || !xr_strcmp(str, "dm"))
return eGameIDDeathmatch;
else if (!xr_strcmp(str, "teamdeathmatch") || !xr_strcmp(str, "tdm"))
return eGameIDTeamDeathmatch;
else if (!xr_strcmp(str, "artefacthunt") || !xr_strcmp(str, "ah"))
return eGameIDArtefactHunt;
else if (!xr_strcmp(str, "capturetheartefact") || !xr_strcmp(str, "cta"))
return eGameIDCaptureTheArtefact;
else if (!xr_strcmp(str, "dominationzone"))
return eGameIDDominationZone;
else if (!xr_strcmp(str, "teamdominationzone"))
return eGameIDTeamDominationZone;
else
return eGameIDNoGame; //EGameIDs
}
void CGamePersistent::UpdateGameType()
{
__super::UpdateGameType();
m_game_params.m_e_game_type = ParseStringToGameType(m_game_params.m_game_type);
if (m_game_params.m_e_game_type == eGameIDSingle)
g_current_keygroup = _sp;
else
g_current_keygroup = _mp;
}
void CGamePersistent::OnGameEnd()
{
__super::OnGameEnd();
xr_delete(g_stalker_animation_data_storage);
xr_delete(g_stalker_velocity_holder);
}
void CGamePersistent::WeathersUpdate()
{
if (g_pGameLevel && !g_dedicated_server)
{
CActor* actor = smart_cast<CActor*>(Level().CurrentViewEntity());
BOOL bIndoor = TRUE;
if (actor) bIndoor = actor->renderable_ROS()->get_luminocity_hemi() < 0.05f;
int data_set = (Random.randF() < (1.f - Environment().CurrentEnv->weight)) ? 0 : 1;
CEnvDescriptor* const _env = Environment().Current[data_set];
VERIFY(_env);
CEnvAmbient* env_amb = Environment().m_paused ? Environment().CurrentEnv->env_ambient : _env->env_ambient;
if (env_amb)
{
CEnvAmbient::SSndChannelVec& vec = env_amb->get_snd_channels();
CEnvAmbient::SSndChannelVecIt I = vec.begin();
CEnvAmbient::SSndChannelVecIt E = vec.end();
for (u32 idx = 0; I != E; ++I, ++idx)
{
CEnvAmbient::SSndChannel& ch = **I;
R_ASSERT(idx<32);
if (ambient_sound_next_time[idx] == 0) //first
{
ambient_sound_next_time[idx] = Device.dwTimeGlobal + ch.get_rnd_sound_first_time();
}
else if (Device.dwTimeGlobal > ambient_sound_next_time[idx])
{
ref_sound& snd = ch.get_rnd_sound();
Fvector pos;
float angle = ::Random.randF(PI_MUL_2);
pos.x = _cos(angle);
pos.y = 0;
pos.z = _sin(angle);
pos.normalize().mul(ch.get_rnd_sound_dist()).add(Device.vCameraPosition);
pos.y += 10.f;
snd.play_at_pos(0, pos);
#ifdef DEBUG
if (!snd._handle() && strstr(Core.Params, "-nosound"))
continue;
#endif // DEBUG
VERIFY(snd._handle());
u32 _length_ms = iFloor(snd.get_length_sec() * 1000.0f);
ambient_sound_next_time[idx] = Device.dwTimeGlobal + _length_ms + ch.get_rnd_sound_time();
// Msg("- Playing ambient sound channel [%s] file[%s]",ch.m_load_section.c_str(),snd._handle()->file_name());
}
}
/*
if (Device.dwTimeGlobal > ambient_sound_next_time)
{
ref_sound* snd = env_amb->get_rnd_sound();
ambient_sound_next_time = Device.dwTimeGlobal + env_amb->get_rnd_sound_time();
if (snd)
{
Fvector pos;
float angle = ::Random.randF(PI_MUL_2);
pos.x = _cos(angle);
pos.y = 0;
pos.z = _sin(angle);
pos.normalize ().mul(env_amb->get_rnd_sound_dist()).add(Device.vCameraPosition);
pos.y += 10.f;
snd->play_at_pos (0,pos);
}
}
*/
// start effect
if ((FALSE == bIndoor) && (0 == ambient_particles) && Device.dwTimeGlobal > ambient_effect_next_time)
{
CEnvAmbient::SEffect* eff = env_amb->get_rnd_effect();
if (eff)
{
Environment().wind_gust_factor = eff->wind_gust_factor;
ambient_effect_next_time = Device.dwTimeGlobal + env_amb->get_rnd_effect_time();
ambient_effect_stop_time = Device.dwTimeGlobal + eff->life_time;
ambient_effect_wind_start = Device.fTimeGlobal;
ambient_effect_wind_in_time = Device.fTimeGlobal + eff->wind_blast_in_time;
ambient_effect_wind_end = Device.fTimeGlobal + eff->life_time / 1000.f;
ambient_effect_wind_out_time = Device.fTimeGlobal + eff->life_time / 1000.f + eff->
wind_blast_out_time;
ambient_effect_wind_on = true;
ambient_particles = CParticlesObject::Create(eff->particles.c_str(), FALSE, false);
Fvector pos;
pos.add(Device.vCameraPosition, eff->offset);
ambient_particles->play_at_pos(pos);
if (eff->sound._handle()) eff->sound.play_at_pos(0, pos);
Environment().wind_blast_strength_start_value = Environment().wind_strength_factor;
Environment().wind_blast_strength_stop_value = eff->wind_blast_strength;
if (Environment().wind_blast_strength_start_value == 0.f)
{
Environment().wind_blast_start_time.set(0.f, eff->wind_blast_direction.x,
eff->wind_blast_direction.y,
eff->wind_blast_direction.z);
}
else
{
Environment().wind_blast_start_time.set(0.f, Environment().wind_blast_direction.x,
Environment().wind_blast_direction.y,
Environment().wind_blast_direction.z);
}
Environment().wind_blast_stop_time.set(0.f, eff->wind_blast_direction.x,
eff->wind_blast_direction.y, eff->wind_blast_direction.z);
}
}
}
if (Device.fTimeGlobal >= ambient_effect_wind_start && Device.fTimeGlobal <= ambient_effect_wind_in_time &&
ambient_effect_wind_on)
{
float delta = ambient_effect_wind_in_time - ambient_effect_wind_start;
float t;
if (delta != 0.f)
{
float cur_in = Device.fTimeGlobal - ambient_effect_wind_start;
t = cur_in / delta;
}
else
{
t = 0.f;
}
Environment().wind_blast_current.slerp(Environment().wind_blast_start_time,
Environment().wind_blast_stop_time, t);
Environment().wind_blast_direction.set(Environment().wind_blast_current.x,
Environment().wind_blast_current.y,
Environment().wind_blast_current.z);
Environment().wind_strength_factor = Environment().wind_blast_strength_start_value + t * (Environment().
wind_blast_strength_stop_value - Environment().wind_blast_strength_start_value);
}
// stop if time exceed or indoor
if (bIndoor || Device.dwTimeGlobal >= ambient_effect_stop_time)
{
if (ambient_particles) ambient_particles->Stop();
Environment().wind_gust_factor = 0.f;
}
if (Device.fTimeGlobal >= ambient_effect_wind_end && ambient_effect_wind_on)
{
Environment().wind_blast_strength_start_value = Environment().wind_strength_factor;
Environment().wind_blast_strength_stop_value = 0.f;
ambient_effect_wind_on = false;
}
if (Device.fTimeGlobal >= ambient_effect_wind_end && Device.fTimeGlobal <= ambient_effect_wind_out_time)
{
float delta = ambient_effect_wind_out_time - ambient_effect_wind_end;
float t;
if (delta != 0.f)
{
float cur_in = Device.fTimeGlobal - ambient_effect_wind_end;
t = cur_in / delta;
}
else
{
t = 0.f;
}
Environment().wind_strength_factor = Environment().wind_blast_strength_start_value + t * (Environment().
wind_blast_strength_stop_value - Environment().wind_blast_strength_start_value);
}
if (Device.fTimeGlobal > ambient_effect_wind_out_time && ambient_effect_wind_out_time != 0.f)
{
Environment().wind_strength_factor = 0.0;
}
// if particles not playing - destroy
if (ambient_particles && !ambient_particles->IsPlaying())
CParticlesObject::Destroy(ambient_particles);
}
}
bool allow_intro()
{
#ifdef MASTER_GOLD
if (g_SASH.IsRunning())
#else // #ifdef MASTER_GOLD
if ((0 != strstr(Core.Params, "-nointro")) || g_SASH.IsRunning())
#endif // #ifdef MASTER_GOLD
{
return false;
}
else
return true;
}
bool allow_logo() // AVO: skip NVIDIA and other logos at load time
{
if (0 != strstr(Core.Params, "-skiplogo"))
{
return false;
}
else
{
return true;
}
}
void CGamePersistent::start_logo_intro()
{
if (Device.dwPrecacheFrame == 0)
{
m_intro_event.bind(this, &CGamePersistent::update_logo_intro);
if (!g_dedicated_server && 0 == xr_strlen(m_game_params.m_game_or_spawn) && NULL == g_pGameLevel)
{
VERIFY(NULL == m_intro);
m_intro = xr_new<CUISequencer>();
if (allow_logo()) // AVO: skip NVIDIA and other logos at load time
{
m_intro->Start("intro_logo");
Msg("intro_start intro_logo");
}
Console->Hide();
}
}
}
void CGamePersistent::update_logo_intro()
{
if (m_intro && (false == m_intro->IsActive()))
{
m_intro_event = 0;
xr_delete(m_intro);
Msg("intro_delete ::update_logo_intro");
Console->Execute("main_menu on");
}
else if (!m_intro)
{
m_intro_event = 0;
}
}
void CGamePersistent::game_loaded()
{
if (Device.dwPrecacheFrame <= 2)
{
if (g_pGameLevel &&
g_pGameLevel->bReady &&
(allow_intro() && psDeviceFlags2.test(rsKeypress)) &&
load_screen_renderer.b_need_user_input &&
m_game_params.m_e_game_type == eGameIDSingle)
{
VERIFY(NULL == m_intro);
m_intro = xr_new<CUISequencer>();
m_intro->Start("game_loaded");
Msg("intro_start game_loaded");
m_intro->m_on_destroy_event.bind(this, &CGamePersistent::update_game_loaded);
// demonized: Reset mouse state on loading the game
pInput->resetMouseState();
// demonized
// Callback for when loading screen happens and "Press Any Key to Continue" prompt appears
luabind::functor<void> funct;
if (ai().script_engine().functor("_G.OnLoadingScreenKeyPrompt", funct))
{
funct();
}
}
else if ( g_pGameLevel &&
g_pGameLevel->bReady &&
m_game_params.m_e_game_type == eGameIDSingle
)
{
Msg("intro_start game_loaded");
luabind::functor<void> funct;
if (ai().script_engine().functor("_G.OnLoadingScreenKeyPrompt", funct))
{
funct();
}
}
m_intro_event = 0;
}
}
namespace crash_saving {
extern void (*save_impl)();
extern void _save_impl();
}
void CGamePersistent::update_game_loaded()
{
xr_delete(m_intro);
Msg("intro_delete ::update_game_loaded");
start_game_intro();
// demonized
// Enable crash saving here
crash_saving::save_impl = &crash_saving::_save_impl;
// Callback for when player dismisses loading screen after "Press Any Key to Continue" pressed
luabind::functor<void> funct;
if (ai().script_engine().functor("_G.OnLoadingScreenDismissed", funct))
{
funct();
}
}
void CGamePersistent::start_game_intro()
{
if (!allow_intro())
{
m_intro_event = 0;
return;
}
if (g_pGameLevel && g_pGameLevel->bReady && Device.dwPrecacheFrame <= 2)
{
m_intro_event.bind(this, &CGamePersistent::update_game_intro);
if (0 == stricmp(m_game_params.m_new_or_load, "new"))
{
VERIFY(NULL == m_intro);
m_intro = xr_new<CUISequencer>();
m_intro->Start("intro_game");
Msg("intro_start intro_game");
}
}
}
void CGamePersistent::update_game_intro()
{
if (m_intro && (false == m_intro->IsActive()))
{
xr_delete(m_intro);
Msg("intro_delete ::update_game_intro");
m_intro_event = 0;
}
else if (!m_intro)
{
m_intro_event = 0;
}
}
extern CUISequencer* g_tutorial;
extern CUISequencer* g_tutorial2;
void CGamePersistent::OnFrame()
{
if (Device.dwPrecacheFrame == 5 && m_intro_event.empty())
{
m_intro_event.bind(this, &CGamePersistent::game_loaded);
}
if (g_tutorial2)
{
g_tutorial2->Destroy();
xr_delete(g_tutorial2);
}
if (g_tutorial && !g_tutorial->IsActive())
{
xr_delete(g_tutorial);
}
if (0 == Device.dwFrame % 200)
CUITextureMaster::FreeCachedShaders();
#ifdef DEBUG
++m_frame_counter;
#endif
if (!g_dedicated_server && !m_intro_event.empty()) m_intro_event();
if (!g_dedicated_server && Device.dwPrecacheFrame == 0 && !m_intro && m_intro_event.empty())
load_screen_renderer.stop();
if (!m_pMainMenu->IsActive())
m_pMainMenu->DestroyInternal(false);
if (!g_pGameLevel) return;
if (!g_pGameLevel->bReady) return;
if (Device.Paused())
{
if (Level().IsDemoPlay())
{
CSpectator* tmp_spectr = smart_cast<CSpectator*>(Level().CurrentControlEntity());
if (tmp_spectr)
{
tmp_spectr->UpdateCL(); //updating spectator in pause (pause ability of demo play)
}
}
#ifndef MASTER_GOLD
if (Level().CurrentViewEntity() && IsGameTypeSingle())
{
if (!g_actor || (g_actor->ID() != Level().CurrentViewEntity()->ID()))
{
CCustomMonster *custom_monster = smart_cast<CCustomMonster*>(Level().CurrentViewEntity());
if (custom_monster) // can be spectator in multiplayer
custom_monster->UpdateCamera();
}
else
{
CCameraBase* C = NULL;
if (g_actor)
{
if (!Actor()->Holder())
C = Actor()->cam_Active();
else
C = Actor()->Holder()->Camera();
Actor()->Cameras().UpdateFromCamera(C);
Actor()->Cameras().ApplyDevice(VIEWPORT_NEAR);
#ifdef DEBUG
if (psActorFlags.test(AF_NO_CLIP))
{
Actor()->dbg_update_cl = 0;
Actor()->dbg_update_shedule = 0;
Device.dwTimeDelta = 0;
Device.fTimeDelta = 0.01f;
Actor()->UpdateCL();
Actor()->shedule_Update(0);
Actor()->dbg_update_cl = 0;
Actor()->dbg_update_shedule = 0;
CSE_Abstract* e = Level().Server->ID_to_entity(Actor()->ID());
VERIFY(e);
CSE_ALifeCreatureActor* s_actor = smart_cast<CSE_ALifeCreatureActor*>(e);
VERIFY(s_actor);
xr_vector<u16>::iterator it = s_actor->children.begin();
for (; it != s_actor->children.end(); it++)
{
CObject* obj = Level().Objects.net_Find(*it);
if (obj && Engine.Sheduler.Registered(obj))
{
obj->dbg_update_shedule = 0;
obj->dbg_update_cl = 0;
obj->shedule_Update(0);
obj->UpdateCL();
obj->dbg_update_shedule = 0;
obj->dbg_update_cl = 0;
}
}
}
#endif // DEBUG
}
}
}
#else // MASTER_GOLD
if (g_actor && IsGameTypeSingle())
{
CCameraBase* C = NULL;
if (!Actor()->Holder())
C = Actor()->cam_Active();
else
C = Actor()->Holder()->Camera();
Actor()->Cameras().UpdateFromCamera(C);
Actor()->Cameras().ApplyDevice(VIEWPORT_NEAR);
}
#endif // MASTER_GOLD
}
__super::OnFrame();
if (!Device.Paused())
Engine.Sheduler.Update();
// update weathers ambient
if (!Device.Paused())
WeathersUpdate();
if (0 != pDemoFile)
{
if (Device.dwTimeGlobal > uTime2Change)
{
// Change level + play demo
if (pDemoFile->elapsed() < 3) pDemoFile->seek(0); // cycle
// Read params
string512 params;
pDemoFile->r_string(params, sizeof(params));
string256 o_server, o_client, o_demo;
u32 o_time;
sscanf(params, "%[^,],%[^,],%[^,],%d", o_server, o_client, o_demo, &o_time);
// Start _new level + demo
Engine.Event.Defer("KERNEL:disconnect");
Engine.Event.Defer("KERNEL:start", size_t(xr_strdup(_Trim(o_server))), size_t(xr_strdup(_Trim(o_client))));
Engine.Event.Defer("GAME:demo", size_t(xr_strdup(_Trim(o_demo))), u64(o_time));
uTime2Change = 0xffffffff; // Block changer until Event received
}
}
#ifdef DEBUG
if ((m_last_stats_frame + 1) < m_frame_counter)
profiler().clear();
#endif
UpdateDof();
}
#include "game_sv_single.h"
#include "xrServer.h"
#include "UIGameCustom.h"
#include "ui/UIMainIngameWnd.h"
#include "ui/UIPdaWnd.h"
void CGamePersistent::OnEvent(EVENT E, u64 P1, u64 P2)
{
if (E == eQuickLoad)
{
if (Device.Paused())
Device.Pause(FALSE, TRUE, TRUE, "eQuickLoad");
if (CurrentGameUI())
{
CurrentGameUI()->HideShownDialogs();
CurrentGameUI()->UIMainIngameWnd->reset_ui();
CurrentGameUI()->GetPdaMenu().Reset();
}
if (g_tutorial)
g_tutorial->Stop();
if (g_tutorial2)
g_tutorial2->Stop();
LPSTR saved_name = (LPSTR)(P1);
Level().remove_objects();
game_sv_Single* game = smart_cast<game_sv_Single*>(Level().Server->game);
R_ASSERT(game);
game->restart_simulator(saved_name);
xr_free(saved_name);
return;
}
else if (E == eDemoStart)
{
string256 cmd;
LPCSTR demo = LPCSTR(P1);
xr_sprintf(cmd, "demo_play %s", demo);
Console->Execute(cmd);
xr_free(demo);
uTime2Change = Device.TimerAsync() + u32(P2) * 1000;
}
}
void CGamePersistent::Statistics(CGameFont* F)
{
#ifdef DEBUG
# ifndef _EDITOR
m_last_stats_frame = m_frame_counter;
profiler().show_stats(F, !!psAI_Flags.test(aiStats));
# endif
#endif
}
float CGamePersistent::MtlTransparent(u32 mtl_idx)
{
return GMLib.GetMaterialByIdx((u16)mtl_idx)->fVisTransparencyFactor;
}
static BOOL bRestorePause = FALSE;
static BOOL bEntryFlag = TRUE;
void CGamePersistent::OnAppActivate()
{
bool bIsMP = (g_pGameLevel && Level().game && GameID() != eGameIDSingle);
bIsMP &= !Device.Paused();
if (!bIsMP)
{
Device.Pause(FALSE, !bRestorePause, TRUE, "CGP::OnAppActivate");
}
else
{
Device.Pause(FALSE, TRUE, TRUE, "CGP::OnAppActivate MP");
}
bEntryFlag = TRUE;
}
void CGamePersistent::OnAppDeactivate()
{
if (!bEntryFlag) return;
bool bIsMP = (g_pGameLevel && Level().game && GameID() != eGameIDSingle);
bRestorePause = FALSE;
if (!bIsMP)
{
bRestorePause = Device.Paused();
Device.Pause(TRUE, TRUE, TRUE, "CGP::OnAppDeactivate");
}
else
{
Device.Pause(TRUE, FALSE, TRUE, "CGP::OnAppDeactivate MP");
}
bEntryFlag = FALSE;
}
bool CGamePersistent::OnRenderPPUI_query()
{
return MainMenu()->OnRenderPPUI_query();
// enable PP or not
}
extern void draw_wnds_rects();
void CGamePersistent::OnRenderPPUI_main()
{
// always
MainMenu()->OnRenderPPUI_main();
draw_wnds_rects();
}
void CGamePersistent::OnRenderPPUI_PP()
{
MainMenu()->OnRenderPPUI_PP();
}
#include "string_table.h"
#include "../xrEngine/x_ray.h"
void CGamePersistent::LoadTitle(bool change_tip, shared_str map_name)
{
pApp->LoadStage();
if (change_tip)
{
string512 buff;
u8 tip_num;
luabind::functor<u8> m_functor;
bool is_single = !xr_strcmp(m_game_params.m_game_type, "single");
if (is_single)
{
R_ASSERT(ai().script_engine().functor("loadscreen.get_tip_number", m_functor));
tip_num = m_functor(map_name.c_str());
}
else
{
R_ASSERT(ai().script_engine().functor("loadscreen.get_mp_tip_number", m_functor));
tip_num = m_functor(map_name.c_str());
}
if (tip_num < 1)
return;
// tip_num = 83;
xr_sprintf(buff, "%s%d:", CStringTable().translate("ls_tip_number").c_str(), tip_num);
shared_str tmp = buff;
if (is_single)
xr_sprintf(buff, "ls_tip_%d", tip_num);
else
xr_sprintf(buff, "ls_mp_tip_%d", tip_num);
pApp->LoadTitleInt(CStringTable().translate("ls_header").c_str(), tmp.c_str(),
CStringTable().translate(buff).c_str());
}
}
bool CGamePersistent::CanBePaused()
{
return IsGameTypeSingle() || (g_pGameLevel && Level().IsDemoPlay());
}
void CGamePersistent::SetPickableEffectorDOF(bool bSet)
{
m_bPickableDOF = bSet;
if (!bSet)
RestoreEffectorDOF();
}
void CGamePersistent::GetCurrentDof(Fvector3& dof)
{
dof = m_dof[1];
}
void CGamePersistent::SetBaseDof(const Fvector3& dof)
{
m_dof[0] = m_dof[1] = m_dof[2] = m_dof[3] = dof;
}
void CGamePersistent::SetEffectorDOF(const Fvector& needed_dof)
{
if (m_bPickableDOF) return;
m_dof[0] = needed_dof;
m_dof[2] = m_dof[1]; //current
}
void CGamePersistent::RestoreEffectorDOF()
{
SetEffectorDOF(m_dof[3]);
}
#include "hudmanager.h"
// m_dof [4]; // 0-dest 1-current 2-from 3-original
void CGamePersistent::UpdateDof()
{
static float diff_far = pSettings->r_float("zone_pick_dof", "far"); //70.0f;
static float diff_near = pSettings->r_float("zone_pick_dof", "near"); //-70.0f;
if (m_bPickableDOF)
{
Fvector pick_dof;
pick_dof.y = HUD().GetCurrentRayQuery().range;
pick_dof.x = pick_dof.y + diff_near;
pick_dof.z = pick_dof.y + diff_far;
m_dof[0] = pick_dof;
m_dof[2] = m_dof[1]; //current
}
if (m_dof[1].similar(m_dof[0]))
return;
float td = Device.fTimeDelta;
Fvector diff;
diff.sub(m_dof[0], m_dof[2]);
diff.mul(td / 0.2f); //0.2 sec
m_dof[1].add(diff);
(m_dof[0].x < m_dof[2].x) ? clamp(m_dof[1].x, m_dof[0].x, m_dof[2].x) : clamp(m_dof[1].x, m_dof[2].x, m_dof[0].x);
(m_dof[0].y < m_dof[2].y) ? clamp(m_dof[1].y, m_dof[0].y, m_dof[2].y) : clamp(m_dof[1].y, m_dof[2].y, m_dof[0].y);