-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcl_demo.h
244 lines (197 loc) · 8.23 KB
/
cl_demo.h
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
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef CL_DEMO_H
#define CL_DEMO_H
#ifdef _WIN32
#pragma once
#endif
#include "demofile.h"
#include "cl_demoactionmanager.h"
#include "netmessages_signon.h"
struct DemoCommandQueue
{
DemoCommandQueue()
{
tick = 0;
}
int tick;
democmdinfo_t info;
int filepos;
};
struct DemoCustomDataCallbackMapping_t
{
pfnDemoCustomDataCallback pCallback;
CUtlString name;
};
struct DemoHighlightEntry_t
{
int nSeekToTick;
int nFastForwardToTick;
int nPlayToTick;
int nActualFirstEventTick;
int nActualLastEventTick;
int nNumEvents;
uint32 unAccountID;
};
class CDemoPlayer : public IDemoPlayer
{
public: // IDemoPlayer interface implementation:
CDemoPlayer();
~CDemoPlayer();
bool StartPlayback( const char *filename, bool bAsTimeDemo, CDemoPlaybackParameters_t const *pPlaybackParameters, int nStartingTick = -1 ) ;
bool StartBroadcastPlayback( int nStartingTick );
virtual bool IsPlayingBack( void ) const OVERRIDE; // true if demo loaded and playing back
virtual bool IsPlaybackPaused( void ) const OVERRIDE; // true if playback paused
virtual bool IsPlayingTimeDemo( void ) const OVERRIDE; // true if playing back in timedemo mode
CDemoPlaybackParameters_t const * GetDemoPlaybackParameters() OVERRIDE;
void PausePlayback( float seconds );
void SkipToTick( int tick, bool bRelative, bool bPause );
void SkipToImportantTick( const DemoImportantTick_t *pTick );
void ResumePlayback( void );
void StopPlayback( void );
void RestartPlayback( void );
int GetPlaybackStartTick( void );
int GetPlaybackTick( void );
virtual int GetPlaybackDeltaTick( void ) ;
virtual int GetPacketTick( void ) ;
float GetPlaybackTimeScale( void );
int GetTotalTicks( void );
virtual bool IsSkipping( void ) const OVERRIDE; // true, if demo player skipping trough packets
// true if demoplayer can skip backwards
virtual bool CanSkipBackwards( void ) const OVERRIDE { return false; }
void SetPlaybackTimeScale( float timescale );
void InterpolateViewpoint(); // override viewpoint
netpacket_t *ReadPacket( void );
void ResetDemoInterpolation( void );
void SetPacketReadSuspended( bool bSuspendPacketReading );
virtual IDemoStream* GetDemoStream() OVERRIDE { return &m_DemoFile; }
public: // other public functions
void MarkFrame( float flFPSVariability );
void SetBenchframe( int tick, const char *filename );
void ResyncDemoClock( void );
bool CheckPausedPlayback( void );
void WriteTimeDemoResults( void );
bool ParseAheadForInterval( int curtick, int intervalticks );
void InterpolateDemoCommand( int nSlot, int targettick, DemoCommandQueue& prev, DemoCommandQueue& next );
void SetImportantEventData( const KeyValues *pData ) OVERRIDE;
void GetImportantGameEventIDs();
void ScanForImportantTicks( void );
int FindNextImportantTick( int nCurrentTick, const char *pEventName = NULL ) OVERRIDE; // -1 = no next important tick
int FindPreviousImportantTick( int nCurrentTick, const char *pEventName = NULL ) OVERRIDE; // -1 = no previous important tick
int FindNextImportantTickByXuidAndEvent( int nCurrentTick, const CSteamID &steamID, const char *pKeyWithXuid, const char *pEventName = NULL ); // -1 = no next important tick
int FindPreviousImportantTickByXuidAndEvent( int nCurrentTick, const CSteamID &steamID, const char *pKeyWithXuid, const char *pEventName = NULL ); // -1 = no next important tick
int FindNextImportantTickByXuid( int nCurrentTick, const CSteamID &steamID ); // -1 = no next important tick
const DemoImportantTick_t *GetImportantTick( int nIndex ) OVERRIDE;
const DemoImportantGameEvent_t *GetImportantGameEvent( const char *pszEventName ) OVERRIDE;
void ListImportantTicks( void ) OVERRIDE;
void SetHighlightXuid( uint64 xuid, bool bLowlights ) OVERRIDE;
void ListHighlightData( void ) OVERRIDE;
bool ScanDemo( const char *filename, const char* pszMode ) OVERRIDE;
protected:
bool OverrideView( democmdinfo_t& info );
void BuildHighlightList( void );
public:
CDemoFile m_DemoFile;
int m_nStartTick; // For synchronizing playback during timedemo.
int m_nPreviousTick;
netpacket_t m_DemoPacket; // last read demo packet
bool m_bPlayingBack; // true if demo playback
bool m_bPlaybackPaused; // true if demo is paused right now
float m_flAutoResumeTime; // how long do we pause demo playback
float m_flPlaybackRateModifier;
int m_nSkipToTick; // skip to tick ASAP, -1 = off
bool m_bPacketReadSuspended;
int m_nTickToPauseOn;
CDemoPlaybackParameters_t const *m_pPlaybackParameters;
// view origin/angle interpolation:
CUtlVector< DemoCommandQueue > m_DestCmdInfo;
democmdinfo_t m_LastCmdInfo;
bool m_bInterpolateView;
bool m_bResetInterpolation;
// timedemo stuff:
bool m_bTimeDemo; // ture if in timedemo mode
int m_nTimeDemoStartFrame; // host_tickcount at start
double m_flTimeDemoStartTime; // Sys_FloatTime() at second frame of timedemo
float m_flTotalFPSVariability; // Frame rate variability
int m_nTimeDemoCurrentFrame; // last frame we read a packet
int m_nPacketTick;
// benchframe stuff
int m_nSnapshotTick;
char m_SnapshotFilename[MAX_OSPATH];
CUtlVector< DemoCustomDataCallbackMapping_t > m_CustomDataCallbackMap; //maps callbacks in the file to callbacks in the dll when reading
// important tick stuff
CUtlVector< DemoImportantGameEvent_t > m_ImportantGameEvents;
CUtlVector< DemoImportantTick_t > m_ImportantTicks;
KeyValues *m_pImportantEventData;
private:
int m_nRestartFilePos;
bool m_bSavedInterpolateState;
CSteamID m_highlightSteamID;
int m_nHighlightPlayerIndex;
bool m_bDoHighlightScan;
CUtlVector< DemoHighlightEntry_t > m_highlights;
int m_nCurrentHighlight;
bool m_bLowlightsMode;
bool m_bScanMode;
char m_szScanMode[ 64 ];
};
class CDemoRecorder : public IDemoRecorder
{
public:
~CDemoRecorder();
CDemoRecorder();
CDemoFile *GetDemoFile( void );
int GetRecordingTick( void );
void StartRecording( const char *filename, bool bContinuously );
void SetSignonState( SIGNONSTATE state );
bool IsRecording( void );
void PauseRecording( void );
void ResumeRecording( void );
void StopRecording( const CGameInfo *pGameInfo = NULL );
void RecordCommand( const char *cmdstring ); // record a console command
void RecordUserInput( int cmdnumber ); // record a user input command
void RecordMessages( bf_read &data, int bits ); // add messages to current packet
void RecordPacket( void ); // packet finished, write all recorded stuff to file
void RecordServerClasses( ServerClass *pClasses ); // packet finished, write all recorded stuff to file
void RecordStringTables();
void RecordCustomData( int iCallbackIndex, const void *pData, size_t iDataLength ); //record a chunk of custom data
void ResetDemoInterpolation( void );
protected:
void ResyncDemoClock( void );
void StartupDemoFile( void );
void StartupDemoHeader( void );
void CloseDemoFile( void );
void GetClientCmdInfo( democmdinfo_t& info );
void WriteDemoCvars( void );
void WriteBSPDecals( void );
void WriteSplitScreenPlayers( void );
void WriteMessages( bf_write &message );
bool ComputeNextIncrementalDemoFilename( char *name, int namesize );
public:
CDemoFile m_DemoFile;
// For synchronizing playback during timedemo.
int m_nStartTick; // host_tickcount when starting recoring
// Name of demo file we are appending onto.
char m_szDemoBaseName[ MAX_OSPATH ];
// For demo file handle
bool m_bIsDemoHeader; // true, if m_hDemoFile is the header file
bool m_bCloseDemoFile; // if true, demo file will be closed ASAP
bool m_bRecording; // true if recording
bool m_bContinuously; // start new record after each
int m_nDemoNumber; // demo count, increases each changelevel
int m_nFrameCount; // # of demo frames in this segment.
bf_write m_MessageData; // temp buffer for all network messages
bool m_bResetInterpolation;
};
extern CDemoPlayer *g_pClientDemoPlayer;
extern CDemoRecorder *g_pClientDemoRecorder;
struct RegisteredDemoCustomDataCallbackPair_t
{
pfnDemoCustomDataCallback pCallback;
string_t szSaveID;
};
extern CUtlVector<RegisteredDemoCustomDataCallbackPair_t> g_RegisteredDemoCustomDataCallbacks;
#endif // CL_DEMO_H