forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsceneentity.cpp
5656 lines (4809 loc) · 154 KB
/
sceneentity.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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include <stdarg.h>
#include "baseflex.h"
#include "entitylist.h"
#include "choreoevent.h"
#include "choreoactor.h"
#include "choreochannel.h"
#include "choreoscene.h"
#include "studio.h"
#include "networkstringtable_gamedll.h"
#include "ai_basenpc.h"
#include "engine/IEngineSound.h"
#include "ai_navigator.h"
#include "saverestore_utlvector.h"
#include "ai_baseactor.h"
#include "AI_Criteria.h"
#include "tier1/strtools.h"
#include "checksum_crc.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "utlbuffer.h"
#include "tier0/icommandline.h"
#include "sceneentity.h"
#include "datacache/idatacache.h"
#include "dt_utlvector_send.h"
#include "ichoreoeventcallback.h"
#include "scenefilecache/ISceneFileCache.h"
#include "SceneCache.h"
#include "scripted.h"
#include "env_debughistory.h"
#ifdef HL2_EPISODIC
#include "npc_alyx_episodic.h"
#endif // HL2_EPISODIC
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern ISoundEmitterSystemBase *soundemitterbase;
extern ISceneFileCache *scenefilecache;
class CSceneEntity;
class CBaseFlex;
// VCDS are loaded from their compiled/binary format (much faster)
// Requies vcds be saved as compiled assets
//#define COMPILED_VCDS 1
static ConVar scene_forcecombined( "scene_forcecombined", "0", 0, "When playing back, force use of combined .wav files even in english." );
static ConVar scene_maxcaptionradius( "scene_maxcaptionradius", "1200", 0, "Only show closed captions if recipient is within this many units of speaking actor (0==disabled)." );
// Assume sound system is 100 msec lagged (only used if we can't find snd_mixahead cvar!)
#define SOUND_SYSTEM_LATENCY_DEFAULT ( 0.1f )
// Think every 50 msec (FIXME: Try 10hz?)
#define SCENE_THINK_INTERVAL 0.001 // FIXME: make scene's think in concert with their npc's
#define FINDNAMEDENTITY_MAX_ENTITIES 32 // max number of entities to be considered for random entity selection in FindNamedEntity
// List of the last 5 lines of speech from NPCs for bug reports
static recentNPCSpeech_t speechListSounds[ SPEECH_LIST_MAX_SOUNDS ] = { { 0, "", "" }, { 0, "", "" }, { 0, "", "" }, { 0, "", "" }, { 0, "", "" } };
static int speechListIndex = 0;
// Only allow scenes to change their pitch within a range of values
#define SCENE_MIN_PITCH 0.25f
#define SCENE_MAX_PITCH 2.5f
//===========================================================================================================
// SCENE LIST MANAGER
//===========================================================================================================
#define SCENE_LIST_MANAGER_MAX_SCENES 16
//-----------------------------------------------------------------------------
// Purpose: Entity that manages a list of scenes
//-----------------------------------------------------------------------------
class CSceneListManager : public CLogicalEntity
{
DECLARE_CLASS( CSceneListManager, CLogicalEntity );
public:
DECLARE_DATADESC();
virtual void Activate( void );
void ShutdownList( void );
void SceneStarted( CBaseEntity *pSceneOrManager );
void AddListManager( CSceneListManager *pManager );
void RemoveScene( int iIndex );
// Inputs
void InputShutdown( inputdata_t &inputdata );
private:
CUtlVector< CHandle< CSceneListManager > > m_hListManagers;
string_t m_iszScenes[SCENE_LIST_MANAGER_MAX_SCENES];
EHANDLE m_hScenes[SCENE_LIST_MANAGER_MAX_SCENES];
};
//-----------------------------------------------------------------------------
// Purpose: This class exists solely to call think on all scene entities in a deterministic order
//-----------------------------------------------------------------------------
class CSceneManager : public CBaseEntity
{
DECLARE_CLASS( CSceneManager, CBaseEntity );
DECLARE_DATADESC();
public:
virtual void Spawn()
{
BaseClass::Spawn();
SetNextThink( gpGlobals->curtime );
}
virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_DONT_SAVE; }
virtual void Think();
void ClearAllScenes();
void AddSceneEntity( CSceneEntity *scene );
void RemoveSceneEntity( CSceneEntity *scene );
void QueueRestoredSound( CBaseFlex *actor, char const *soundname, soundlevel_t soundlevel, float time_in_past );
void OnClientActive( CBasePlayer *player );
void RemoveActorFromScenes( CBaseFlex *pActor, bool bInstancedOnly, bool bNonIdleOnly, const char *pszThisSceneOnly );
void RemoveScenesInvolvingActor( CBaseFlex *pActor );
void PauseActorsScenes( CBaseFlex *pActor, bool bInstancedOnly );
bool IsInInterruptableScenes( CBaseFlex *pActor );
void ResumeActorsScenes( CBaseFlex *pActor, bool bInstancedOnly );
void QueueActorsScenesToResume( CBaseFlex *pActor, bool bInstancedOnly );
bool IsRunningScriptedScene( CBaseFlex *pActor, bool bIgnoreInstancedScenes );
bool IsRunningScriptedSceneAndNotPaused( CBaseFlex *pActor, bool bIgnoreInstancedScenes );
bool IsRunningScriptedSceneWithSpeech( CBaseFlex *pActor, bool bIgnoreInstancedScenes );
bool IsRunningScriptedSceneWithSpeechAndNotPaused( CBaseFlex *pActor, bool bIgnoreInstancedScenes );
private:
struct CRestoreSceneSound
{
CRestoreSceneSound()
{
actor = NULL;
soundname[ 0 ] = '\0';
soundlevel = SNDLVL_NORM;
time_in_past = 0.0f;
}
CHandle< CBaseFlex > actor;
char soundname[ 128 ];
soundlevel_t soundlevel;
float time_in_past;
};
CUtlVector< CHandle< CSceneEntity > > m_ActiveScenes;
CUtlVector< CRestoreSceneSound > m_QueuedSceneSounds;
};
//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CSceneManager )
DEFINE_UTLVECTOR( m_ActiveScenes, FIELD_EHANDLE ),
// DEFINE_FIELD( m_QueuedSceneSounds, CUtlVector < CRestoreSceneSound > ), // Don't save/restore this, it's created and used by OnRestore only
END_DATADESC()
#ifdef DISABLE_DEBUG_HISTORY
#define LocalScene_Printf Scene_Printf
#else
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pFormat -
// ... -
// Output : static void
//-----------------------------------------------------------------------------
void LocalScene_Printf( const char *pFormat, ... )
{
va_list marker;
char msg[8192];
va_start(marker, pFormat);
Q_vsnprintf(msg, sizeof(msg), pFormat, marker);
va_end(marker);
Scene_Printf( "%s", msg );
ADD_DEBUG_HISTORY( HISTORY_SCENE_PRINT, UTIL_VarArgs( "(%0.2f) %s", gpGlobals->curtime, msg ) );
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
// Input : *filename -
// **buffer -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CopySceneFileIntoMemory( char const *pFilename, void **pBuffer, int *pSize )
{
size_t bufSize = scenefilecache->GetSceneBufferSize( pFilename );
if ( bufSize > 0 )
{
*pBuffer = new byte[bufSize];
*pSize = bufSize;
return scenefilecache->GetSceneData( pFilename, (byte *)(*pBuffer), bufSize );
}
*pBuffer = 0;
*pSize = 0;
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void FreeSceneFileMemory( void *buffer )
{
delete[] (byte*) buffer;
}
//-----------------------------------------------------------------------------
// Binary compiled VCDs get their strings from a pool
//-----------------------------------------------------------------------------
class CChoreoStringPool : public IChoreoStringPool
{
public:
short FindOrAddString( const char *pString )
{
// huh?, no compilation at run time, only fetches
Assert( 0 );
return -1;
}
bool GetString( short stringId, char *buff, int buffSize )
{
// fetch from compiled pool
const char *pString = scenefilecache->GetSceneString( stringId );
if ( !pString )
{
V_strncpy( buff, "", buffSize );
return false;
}
V_strncpy( buff, pString, buffSize );
return true;
}
};
CChoreoStringPool g_ChoreoStringPool;
//-----------------------------------------------------------------------------
// Purpose: Singleton scene manager. Created by first placed scene or recreated it it's deleted for some unknown reason
// Output : CSceneManager
//-----------------------------------------------------------------------------
CSceneManager *GetSceneManager()
{
// Create it if it doesn't exist
static CHandle< CSceneManager > s_SceneManager;
if ( s_SceneManager == NULL )
{
s_SceneManager = ( CSceneManager * )CreateEntityByName( "scene_manager" );
Assert( s_SceneManager );
if ( s_SceneManager )
{
s_SceneManager->Spawn();
}
}
Assert( s_SceneManager );
return s_SceneManager;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *player -
//-----------------------------------------------------------------------------
void SceneManager_ClientActive( CBasePlayer *player )
{
Assert( GetSceneManager() );
if ( GetSceneManager() )
{
GetSceneManager()->OnClientActive( player );
}
}
//-----------------------------------------------------------------------------
// Purpose: FIXME, need to deal with save/restore
//-----------------------------------------------------------------------------
class CSceneEntity : public CPointEntity, public IChoreoEventCallback
{
friend class CInstancedSceneEntity;
public:
enum
{
SCENE_ACTION_UNKNOWN = 0,
SCENE_ACTION_CANCEL,
SCENE_ACTION_RESUME,
};
enum
{
SCENE_BUSYACTOR_DEFAULT = 0,
SCENE_BUSYACTOR_WAIT,
SCENE_BUSYACTOR_INTERRUPT,
SCENE_BUSYACTOR_INTERRUPT_CANCEL,
};
DECLARE_CLASS( CSceneEntity, CPointEntity );
DECLARE_SERVERCLASS();
CSceneEntity( void );
~CSceneEntity( void );
// From IChoreoEventCallback
virtual void StartEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
virtual void EndEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
virtual void ProcessEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
virtual bool CheckEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
virtual int UpdateTransmitState();
virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
void SetRecipientFilter( IRecipientFilter *filter );
virtual void Activate();
virtual void Precache( void );
virtual void Spawn( void );
virtual void UpdateOnRemove( void );
virtual void OnRestore();
virtual void OnLoaded();
DECLARE_DATADESC();
virtual void OnSceneFinished( bool canceled, bool fireoutput );
virtual void DoThink( float frametime );
virtual void PauseThink( void );
bool IsPlayingBack() const { return m_bIsPlayingBack; }
bool IsPaused() const { return m_bPaused; }
bool IsMultiplayer() const { return m_bMultiplayer; }
bool IsInterruptable();
virtual void ClearInterrupt();
virtual void CheckInterruptCompletion();
virtual bool InterruptThisScene( CSceneEntity *otherScene );
void RequestCompletionNotification( CSceneEntity *otherScene );
virtual void NotifyOfCompletion( CSceneEntity *interruptor );
void AddListManager( CSceneListManager *pManager );
void ClearActivatorTargets( void );
void SetBreakOnNonIdle( bool bBreakOnNonIdle ) { m_bBreakOnNonIdle = bBreakOnNonIdle; }
bool ShouldBreakOnNonIdle( void ) { return m_bBreakOnNonIdle; }
// Inputs
void InputStartPlayback( inputdata_t &inputdata );
void InputPausePlayback( inputdata_t &inputdata );
void InputResumePlayback( inputdata_t &inputdata );
void InputCancelPlayback( inputdata_t &inputdata );
void InputCancelAtNextInterrupt( inputdata_t &inputdata );
void InputPitchShiftPlayback( inputdata_t &inputdata );
void InputTriggerEvent( inputdata_t &inputdata );
// If the scene is playing, finds an actor in the scene who can respond to the specified concept token
void InputInterjectResponse( inputdata_t &inputdata );
// If this scene is waiting on an actor, give up and quit trying.
void InputStopWaitingForActor( inputdata_t &inputdata );
virtual void StartPlayback( void );
virtual void PausePlayback( void );
virtual void ResumePlayback( void );
virtual void CancelPlayback( void );
virtual void PitchShiftPlayback( float fPitch );
virtual void QueueResumePlayback( void );
bool ValidScene() const;
// Scene load/unload
static CChoreoScene *LoadScene( const char *filename, IChoreoEventCallback *pCallback );
void UnloadScene( void );
struct SpeakEventSound_t
{
CUtlSymbol m_Symbol;
float m_flStartTime;
};
static bool SpeakEventSoundLessFunc( const SpeakEventSound_t& lhs, const SpeakEventSound_t& rhs );
bool GetSoundNameForPlayer( CChoreoEvent *event, CBasePlayer *player, char *buf, size_t buflen, CBaseEntity *pActor );
void BuildSortedSpeakEventSoundsPrefetchList(
CChoreoScene *scene,
CUtlSymbolTable& table,
CUtlRBTree< SpeakEventSound_t >& soundnames,
float timeOffset );
void PrefetchSpeakEventSounds( CUtlSymbolTable& table, CUtlRBTree< SpeakEventSound_t >& soundnames );
// Event handlers
virtual void DispatchStartExpression( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchEndExpression( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartFlexAnimation( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchEndFlexAnimation( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartGesture( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchEndGesture( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartLookAt( CChoreoScene *scene, CBaseFlex *actor, CBaseEntity *actor2, CChoreoEvent *event );
virtual void DispatchEndLookAt( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartMoveTo( CChoreoScene *scene, CBaseFlex *actor, CBaseEntity *actor2, CChoreoEvent *event );
virtual void DispatchEndMoveTo( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartSpeak( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event, soundlevel_t iSoundlevel );
virtual void DispatchEndSpeak( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartFace( CChoreoScene *scene, CBaseFlex *actor, CBaseEntity *actor2, CChoreoEvent *event );
virtual void DispatchEndFace( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchEndSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartSubScene( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchStartInterrupt( CChoreoScene *scene, CChoreoEvent *event );
virtual void DispatchEndInterrupt( CChoreoScene *scene, CChoreoEvent *event );
virtual void DispatchStartGeneric( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchEndGeneric( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
// NPC can play interstitial vcds (such as responding to the player doing something during a scene)
virtual void DispatchStartPermitResponses( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
virtual void DispatchEndPermitResponses( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
// Global events
virtual void DispatchProcessLoop( CChoreoScene *scene, CChoreoEvent *event );
virtual void DispatchPauseScene( CChoreoScene *scene, const char *parameters );
virtual void DispatchStopPoint( CChoreoScene *scene, const char *parameters );
virtual float EstimateLength( void );
void CancelIfSceneInvolvesActor( CBaseEntity *pActor );
bool InvolvesActor( CBaseEntity *pActor ); // NOTE: returns false if scene hasn't loaded yet
void GenerateSoundScene( CBaseFlex *pActor, const char *soundname );
virtual float GetPostSpeakDelay() { return 1.0; }
bool HasUnplayedSpeech( void );
bool HasFlexAnimation( void );
void SetCurrentTime( float t, bool forceClientSync );
void InputScriptPlayerDeath( inputdata_t &inputdata );
// Data
public:
string_t m_iszSceneFile;
string_t m_iszResumeSceneFile;
EHANDLE m_hWaitingForThisResumeScene;
bool m_bWaitingForResumeScene;
string_t m_iszTarget1;
string_t m_iszTarget2;
string_t m_iszTarget3;
string_t m_iszTarget4;
string_t m_iszTarget5;
string_t m_iszTarget6;
string_t m_iszTarget7;
string_t m_iszTarget8;
EHANDLE m_hTarget1;
EHANDLE m_hTarget2;
EHANDLE m_hTarget3;
EHANDLE m_hTarget4;
EHANDLE m_hTarget5;
EHANDLE m_hTarget6;
EHANDLE m_hTarget7;
EHANDLE m_hTarget8;
CNetworkVar( bool, m_bIsPlayingBack );
CNetworkVar( bool, m_bPaused );
CNetworkVar( bool, m_bMultiplayer );
CNetworkVar( float, m_flForceClientTime );
float m_flCurrentTime;
float m_flFrameTime;
bool m_bCancelAtNextInterrupt;
float m_fPitch;
bool m_bAutomated;
int m_nAutomatedAction;
float m_flAutomationDelay;
float m_flAutomationTime;
// A pause from an input requires another input to unpause (it's a hard pause)
bool m_bPausedViaInput;
// Waiting for the actor to be able to speak.
bool m_bWaitingForActor;
// Waiting for a point at which we can interrupt our actors
bool m_bWaitingForInterrupt;
bool m_bInterruptedActorsScenes;
bool m_bBreakOnNonIdle;
public:
virtual CBaseFlex *FindNamedActor( int index );
virtual CBaseFlex *FindNamedActor( CChoreoActor *pChoreoActor );
virtual CBaseFlex *FindNamedActor( const char *name );
virtual CBaseEntity *FindNamedEntity( const char *name, CBaseEntity *pActor = NULL, bool bBaseFlexOnly = false, bool bUseClear = false );
CBaseEntity *FindNamedTarget( string_t iszTarget, bool bBaseFlexOnly = false );
virtual CBaseEntity *FindNamedEntityClosest( const char *name, CBaseEntity *pActor = NULL, bool bBaseFlexOnly = false, bool bUseClear = false, const char *pszSecondary = NULL );
private:
CUtlVector< CHandle< CBaseFlex > > m_hActorList;
CUtlVector< CHandle< CBaseEntity > > m_hRemoveActorList;
private:
inline void SetRestoring( bool bRestoring );
// Prevent derived classed from using this!
virtual void Think( void ) {};
void ClearSceneEvents( CChoreoScene *scene, bool canceled );
void ClearSchedules( CChoreoScene *scene );
float GetSoundSystemLatency( void );
void PrecacheScene( CChoreoScene *scene );
CChoreoScene *GenerateSceneForSound( CBaseFlex *pFlexActor, const char *soundname );
bool CheckActors();
void PrefetchAnimBlocks( CChoreoScene *scene );
bool ShouldNetwork() const;
// Set if we tried to async the scene but the FS returned that the data was not loadable
bool m_bSceneMissing;
CChoreoScene *m_pScene;
CNetworkVar( int, m_nSceneStringIndex );
static const ConVar *m_pcvSndMixahead;
COutputEvent m_OnStart;
COutputEvent m_OnCompletion;
COutputEvent m_OnCanceled;
COutputEvent m_OnTrigger1;
COutputEvent m_OnTrigger2;
COutputEvent m_OnTrigger3;
COutputEvent m_OnTrigger4;
COutputEvent m_OnTrigger5;
COutputEvent m_OnTrigger6;
COutputEvent m_OnTrigger7;
COutputEvent m_OnTrigger8;
COutputEvent m_OnTrigger9;
COutputEvent m_OnTrigger10;
COutputEvent m_OnTrigger11;
COutputEvent m_OnTrigger12;
COutputEvent m_OnTrigger13;
COutputEvent m_OnTrigger14;
COutputEvent m_OnTrigger15;
COutputEvent m_OnTrigger16;
int m_nInterruptCount;
bool m_bInterrupted;
CHandle< CSceneEntity > m_hInterruptScene;
bool m_bCompletedEarly;
bool m_bInterruptSceneFinished;
CUtlVector< CHandle< CSceneEntity > > m_hNotifySceneCompletion;
CUtlVector< CHandle< CSceneListManager > > m_hListManagers;
bool m_bRestoring;
bool m_bGenerated;
string_t m_iszSoundName;
CHandle< CBaseFlex > m_hActor;
EHANDLE m_hActivator;
int m_BusyActor;
int m_iPlayerDeathBehavior;
CRecipientFilter *m_pRecipientFilter;
public:
void SetBackground( bool bIsBackground );
bool IsBackground( void );
};
LINK_ENTITY_TO_CLASS( logic_choreographed_scene, CSceneEntity );
LINK_ENTITY_TO_CLASS( scripted_scene, CSceneEntity );
IMPLEMENT_SERVERCLASS_ST_NOBASE( CSceneEntity, DT_SceneEntity )
SendPropInt(SENDINFO(m_nSceneStringIndex),MAX_CHOREO_SCENES_STRING_BITS,SPROP_UNSIGNED),
SendPropBool(SENDINFO(m_bIsPlayingBack)),
SendPropBool(SENDINFO(m_bPaused)),
SendPropBool(SENDINFO(m_bMultiplayer)),
SendPropFloat(SENDINFO(m_flForceClientTime)),
SendPropUtlVector(
SENDINFO_UTLVECTOR( m_hActorList ),
MAX_ACTORS_IN_SCENE, // max elements
SendPropEHandle( NULL, 0 ) ),
END_SEND_TABLE()
BEGIN_DATADESC( CSceneEntity )
// Keys
DEFINE_KEYFIELD( m_iszSceneFile, FIELD_STRING, "SceneFile" ),
DEFINE_KEYFIELD( m_iszResumeSceneFile, FIELD_STRING, "ResumeSceneFile" ),
DEFINE_FIELD( m_hWaitingForThisResumeScene, FIELD_EHANDLE ),
DEFINE_FIELD( m_bWaitingForResumeScene, FIELD_BOOLEAN ),
DEFINE_KEYFIELD( m_iszTarget1, FIELD_STRING, "target1" ),
DEFINE_KEYFIELD( m_iszTarget2, FIELD_STRING, "target2" ),
DEFINE_KEYFIELD( m_iszTarget3, FIELD_STRING, "target3" ),
DEFINE_KEYFIELD( m_iszTarget4, FIELD_STRING, "target4" ),
DEFINE_KEYFIELD( m_iszTarget5, FIELD_STRING, "target5" ),
DEFINE_KEYFIELD( m_iszTarget6, FIELD_STRING, "target6" ),
DEFINE_KEYFIELD( m_iszTarget7, FIELD_STRING, "target7" ),
DEFINE_KEYFIELD( m_iszTarget8, FIELD_STRING, "target8" ),
DEFINE_KEYFIELD( m_BusyActor, FIELD_INTEGER, "busyactor" ),
DEFINE_FIELD( m_hTarget1, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget2, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget3, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget4, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget5, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget6, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget7, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTarget8, FIELD_EHANDLE ),
DEFINE_FIELD( m_bIsPlayingBack, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bPaused, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flCurrentTime, FIELD_FLOAT ), // relative, not absolute time
DEFINE_FIELD( m_flForceClientTime, FIELD_FLOAT ),
DEFINE_FIELD( m_flFrameTime, FIELD_FLOAT ), // last frametime
DEFINE_FIELD( m_bCancelAtNextInterrupt, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fPitch, FIELD_FLOAT ),
DEFINE_FIELD( m_bAutomated, FIELD_BOOLEAN ),
DEFINE_FIELD( m_nAutomatedAction, FIELD_INTEGER ),
DEFINE_FIELD( m_flAutomationDelay, FIELD_FLOAT ),
DEFINE_FIELD( m_flAutomationTime, FIELD_FLOAT ), // relative, not absolute time
DEFINE_FIELD( m_bPausedViaInput, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bWaitingForActor, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bWaitingForInterrupt, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bInterruptedActorsScenes, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bBreakOnNonIdle, FIELD_BOOLEAN ),
DEFINE_UTLVECTOR( m_hActorList, FIELD_EHANDLE ),
DEFINE_UTLVECTOR( m_hRemoveActorList, FIELD_EHANDLE ),
// DEFINE_FIELD( m_pScene, FIELD_XXXX ) // Special processing used for this
// These are set up in the constructor
// DEFINE_FIELD( m_pcvSndMixahead, FIELD_XXXXX ),
// DEFINE_FIELD( m_bRestoring, FIELD_BOOLEAN ),
DEFINE_FIELD( m_nInterruptCount, FIELD_INTEGER ),
DEFINE_FIELD( m_bInterrupted, FIELD_BOOLEAN ),
DEFINE_FIELD( m_hInterruptScene, FIELD_EHANDLE ),
DEFINE_FIELD( m_bCompletedEarly, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bInterruptSceneFinished, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bGenerated, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iszSoundName, FIELD_STRING ),
DEFINE_FIELD( m_hActor, FIELD_EHANDLE ),
DEFINE_FIELD( m_hActivator, FIELD_EHANDLE ),
// DEFINE_FIELD( m_bSceneMissing, FIELD_BOOLEAN ),
DEFINE_UTLVECTOR( m_hNotifySceneCompletion, FIELD_EHANDLE ),
DEFINE_UTLVECTOR( m_hListManagers, FIELD_EHANDLE ),
DEFINE_FIELD( m_bMultiplayer, FIELD_BOOLEAN ),
// DEFINE_FIELD( m_nSceneStringIndex, FIELD_INTEGER ),
// DEFINE_FIELD( m_pRecipientFilter, IRecipientFilter* ), // Multiplayer only
// Inputs
DEFINE_INPUTFUNC( FIELD_VOID, "Start", InputStartPlayback ),
DEFINE_INPUTFUNC( FIELD_VOID, "Pause", InputPausePlayback ),
DEFINE_INPUTFUNC( FIELD_VOID, "Resume", InputResumePlayback ),
DEFINE_INPUTFUNC( FIELD_VOID, "Cancel", InputCancelPlayback ),
DEFINE_INPUTFUNC( FIELD_VOID, "CancelAtNextInterrupt", InputCancelAtNextInterrupt ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "PitchShift", InputPitchShiftPlayback ),
DEFINE_INPUTFUNC( FIELD_STRING, "InterjectResponse", InputInterjectResponse ),
DEFINE_INPUTFUNC( FIELD_VOID, "StopWaitingForActor", InputStopWaitingForActor ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "Trigger", InputTriggerEvent ),
DEFINE_KEYFIELD( m_iPlayerDeathBehavior, FIELD_INTEGER, "onplayerdeath" ),
DEFINE_INPUTFUNC( FIELD_VOID, "ScriptPlayerDeath", InputScriptPlayerDeath ),
// Outputs
DEFINE_OUTPUT( m_OnStart, "OnStart"),
DEFINE_OUTPUT( m_OnCompletion, "OnCompletion"),
DEFINE_OUTPUT( m_OnCanceled, "OnCanceled"),
DEFINE_OUTPUT( m_OnTrigger1, "OnTrigger1"),
DEFINE_OUTPUT( m_OnTrigger2, "OnTrigger2"),
DEFINE_OUTPUT( m_OnTrigger3, "OnTrigger3"),
DEFINE_OUTPUT( m_OnTrigger4, "OnTrigger4"),
DEFINE_OUTPUT( m_OnTrigger5, "OnTrigger5"),
DEFINE_OUTPUT( m_OnTrigger6, "OnTrigger6"),
DEFINE_OUTPUT( m_OnTrigger7, "OnTrigger7"),
DEFINE_OUTPUT( m_OnTrigger8, "OnTrigger8"),
DEFINE_OUTPUT( m_OnTrigger9, "OnTrigger9"),
DEFINE_OUTPUT( m_OnTrigger10, "OnTrigger10"),
DEFINE_OUTPUT( m_OnTrigger11, "OnTrigger11"),
DEFINE_OUTPUT( m_OnTrigger12, "OnTrigger12"),
DEFINE_OUTPUT( m_OnTrigger13, "OnTrigger13"),
DEFINE_OUTPUT( m_OnTrigger14, "OnTrigger14"),
DEFINE_OUTPUT( m_OnTrigger15, "OnTrigger15"),
DEFINE_OUTPUT( m_OnTrigger16, "OnTrigger16"),
END_DATADESC()
const ConVar *CSceneEntity::m_pcvSndMixahead = NULL;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CSceneEntity::CSceneEntity( void )
{
m_bWaitingForActor = false;
m_bWaitingForInterrupt = false;
m_bInterruptedActorsScenes = false;
m_bIsPlayingBack = false;
m_bPaused = false;
m_bMultiplayer = false;
m_fPitch = 1.0f;
m_iszSceneFile = NULL_STRING;
m_iszResumeSceneFile = NULL_STRING;
m_hWaitingForThisResumeScene = NULL;
m_bWaitingForResumeScene = false;
SetCurrentTime( 0.0f, false );
m_bCancelAtNextInterrupt = false;
m_bAutomated = false;
m_nAutomatedAction = SCENE_ACTION_UNKNOWN;
m_flAutomationDelay = 0.0f;
m_flAutomationTime = 0.0f;
m_bPausedViaInput = false;
ClearInterrupt();
m_pScene = NULL;
m_bCompletedEarly = false;
if ( !m_pcvSndMixahead )
m_pcvSndMixahead = cvar->FindVar( "snd_mixahead" );
m_BusyActor = SCENE_BUSYACTOR_DEFAULT;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CSceneEntity::~CSceneEntity( void )
{
delete m_pRecipientFilter;
m_pRecipientFilter = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Resets time such that the client version of the .vcd is also updated, if appropriate
// Input : t -
// forceClientSync - forces new timestamp down to client .dll via networking
//-----------------------------------------------------------------------------
void CSceneEntity::SetCurrentTime( float t, bool bForceClientSync )
{
m_flCurrentTime = t;
if ( gpGlobals->maxClients == 1 || bForceClientSync )
{
m_flForceClientTime = t;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CSceneEntity::UpdateOnRemove( void )
{
UnloadScene();
BaseClass::UpdateOnRemove();
if ( GetSceneManager() )
{
GetSceneManager()->RemoveSceneEntity( this );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *actor -
// *soundname -
// Output : CChoreoScene
//-----------------------------------------------------------------------------
CChoreoScene *CSceneEntity::GenerateSceneForSound( CBaseFlex *pFlexActor, const char *soundname )
{
float duration = CBaseEntity::GetSoundDuration( soundname, pFlexActor ? STRING( pFlexActor->GetModelName() ) : NULL );
if( duration <= 0.0f )
{
Warning( "CSceneEntity::GenerateSceneForSound: Couldn't determine duration of %s\n", soundname );
return NULL;
}
CChoreoScene *scene = new CChoreoScene( this );
if ( !scene )
{
Warning( "CSceneEntity::GenerateSceneForSound: Failed to allocated new scene!!!\n" );
}
else
{
scene->SetPrintFunc( LocalScene_Printf );
CChoreoActor *actor = scene->AllocActor();
CChoreoChannel *channel = scene->AllocChannel();
CChoreoEvent *event = scene->AllocEvent();
Assert( actor );
Assert( channel );
Assert( event );
if ( !actor || !channel || !event )
{
Warning( "CSceneEntity::GenerateSceneForSound: Alloc of actor, channel, or event failed!!!\n" );
delete scene;
return NULL;
}
// Set us up the actorz
actor->SetName( "!self" ); // Could be pFlexActor->GetName()?
actor->SetActive( true );
// Set us up the channelz
channel->SetName( STRING( m_iszSceneFile ) );
channel->SetActor( actor );
// Add to actor
actor->AddChannel( channel );
// Set us up the eventz
event->SetType( CChoreoEvent::SPEAK );
event->SetName( soundname );
event->SetParameters( soundname );
event->SetStartTime( 0.0f );
event->SetUsingRelativeTag( false );
event->SetEndTime( duration );
event->SnapTimes();
// Add to channel
channel->AddEvent( event );
// Point back to our owners
event->SetChannel( channel );
event->SetActor( actor );
}
return scene;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CSceneEntity::Activate()
{
if ( m_bGenerated && !m_pScene )
{
m_pScene = GenerateSceneForSound( m_hActor, STRING( m_iszSoundName ) );
}
BaseClass::Activate();
if ( GetSceneManager() )
{
GetSceneManager()->AddSceneEntity( this );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : float
//-----------------------------------------------------------------------------
float CSceneEntity::GetSoundSystemLatency( void )
{
if ( m_pcvSndMixahead )
{
return m_pcvSndMixahead->GetFloat();
}
// Assume 100 msec sound system latency
return SOUND_SYSTEM_LATENCY_DEFAULT;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *scene -
//-----------------------------------------------------------------------------
void CSceneEntity::PrecacheScene( CChoreoScene *scene )
{
Assert( scene );
// Iterate events and precache necessary resources
for ( int i = 0; i < scene->GetNumEvents(); i++ )
{
CChoreoEvent *event = scene->GetEvent( i );
if ( !event )
continue;
// load any necessary data
switch (event->GetType() )
{
default:
break;
case CChoreoEvent::SPEAK:
{
// Defined in SoundEmitterSystem.cpp
// NOTE: The script entries associated with .vcds are forced to preload to avoid
// loading hitches during triggering
PrecacheScriptSound( event->GetParameters() );
if ( event->GetCloseCaptionType() == CChoreoEvent::CC_MASTER &&
event->GetNumSlaves() > 0 )
{
char tok[ CChoreoEvent::MAX_CCTOKEN_STRING ];
if ( event->GetPlaybackCloseCaptionToken( tok, sizeof( tok ) ) )
{
PrecacheScriptSound( tok );
}
}
}
break;
case CChoreoEvent::SUBSCENE:
{
// Only allow a single level of subscenes for now
if ( !scene->IsSubScene() )
{
CChoreoScene *subscene = event->GetSubScene();
if ( !subscene )
{
subscene = LoadScene( event->GetParameters(), this );
subscene->SetSubScene( true );
event->SetSubScene( subscene );
// Now precache it's resources, if any
PrecacheScene( subscene );
}
}
}
break;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CSceneEntity::Precache( void )
{
if ( m_bGenerated )
return;
if ( m_iszSceneFile == NULL_STRING )
return;
if ( m_iszResumeSceneFile != NULL_STRING )
{
PrecacheInstancedScene( STRING( m_iszResumeSceneFile ) );
}
PrecacheInstancedScene( STRING( m_iszSceneFile ) );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pActor -
// *soundname -