diff options
author | Andrey Nazarov <skuller@skuller.net> | 2011-04-28 19:18:13 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2011-04-28 19:18:13 +0400 |
commit | 615b6634d3bcf632b57b5504759a3034284576a1 (patch) | |
tree | fc0fe8b43548aec83611471c22434de4e5361492 /src | |
parent | 737d0ff453834e027af9e46b59f6fc8436bf0908 (diff) |
Consolidate various demo initializations into single function.
Diffstat (limited to 'src')
-rw-r--r-- | src/cl_demo.c | 55 | ||||
-rw-r--r-- | src/cl_ents.c | 5 | ||||
-rw-r--r-- | src/cl_local.h | 2 |
3 files changed, 42 insertions, 20 deletions
diff --git a/src/cl_demo.c b/src/cl_demo.c index b387007..4ae67cd 100644 --- a/src/cl_demo.c +++ b/src/cl_demo.c @@ -644,9 +644,10 @@ static void update_status( void ) { if( cls.demo.file_size ) { off_t pos = FS_Tell( cls.demo.playback ); - if( pos > cls.demo.file_offset ) { + if( pos > cls.demo.file_offset ) cls.demo.file_percent = ( pos - cls.demo.file_offset ) * 100 / cls.demo.file_size; - } + else + cls.demo.file_percent = 0; } } @@ -672,7 +673,6 @@ CL_PlayDemo_f static void CL_PlayDemo_f( void ) { char name[MAX_OSPATH]; qhandle_t f; - ssize_t len, ofs; int type; if( Cmd_Argc() < 2 ) { @@ -721,20 +721,6 @@ static void CL_PlayDemo_f( void ) { Cbuf_Execute( &cl_cmdbuf ); parse_next_message(); } - - memcpy( cl.baseconfigstrings, cl.configstrings, sizeof( cl.baseconfigstrings ) ); - - len = FS_Length( f ); - ofs = FS_Tell( f ); - if( len > 0 && ofs > 0 ) { - cls.demo.file_offset = ofs; - cls.demo.file_size = len - ofs; - } - - if( com_timedemo->integer ) { - cls.demo.time_frames = 0; - cls.demo.time_start = Sys_Milliseconds(); - } } static void CL_Demo_c( genctx_t *ctx, int argnum ) { @@ -853,6 +839,41 @@ static demosnap_t *find_snapshot( int framenum ) { return prev; } +/* +==================== +CL_FirstDemoFrame + +Called after the first valid frame is parsed from the demo. +==================== +*/ +void CL_FirstDemoFrame( void ) { + ssize_t len, ofs; + + Com_DPrintf( "[%d] first frame\n", cl.frame.number ); + cls.demo.first_frame = cl.frame.number; + + // save base configstrings + memcpy( cl.baseconfigstrings, cl.configstrings, sizeof( cl.baseconfigstrings ) ); + + // obtain file length and offset of the first frame + len = FS_Length( cls.demo.playback ); + ofs = FS_Tell( cls.demo.playback ); + if( len > 0 && ofs > 0 ) { + cls.demo.file_offset = ofs; + cls.demo.file_size = len - ofs; + } + + // begin timedemo + if( com_timedemo->integer ) { + cls.demo.time_frames = 0; + cls.demo.time_start = Sys_Milliseconds(); + } + + // force initial snapshot + cls.demo.last_snapshot = INT_MIN; + CL_EmitDemoSnapshot(); +} + static void CL_Seek_f( void ) { demosnap_t *snap; int i, j, ret, index, frames, dest, prev; diff --git a/src/cl_ents.c b/src/cl_ents.c index 2b22547..e0752aa 100644 --- a/src/cl_ents.c +++ b/src/cl_ents.c @@ -175,9 +175,8 @@ static void CL_SetActiveState( void ) { } if( cls.demo.playback ) { - // force initial snapshot - cls.demo.last_snapshot = INT_MIN; - CL_EmitDemoSnapshot(); + // init some demo things + CL_FirstDemoFrame(); } else { // set initial cl.predicted_origin and cl.predicted_angles VectorScale( cl.frame.ps.pmove.origin, 0.125f, cl.predicted_origin ); diff --git a/src/cl_local.h b/src/cl_local.h index 5c4db2e..bdfa4a5 100644 --- a/src/cl_local.h +++ b/src/cl_local.h @@ -370,6 +370,7 @@ typedef struct client_static_s { unsigned frames_written; unsigned frames_dropped; unsigned messages_dropped; + int first_frame; int last_snapshot; int last_frame; int file_size; @@ -771,6 +772,7 @@ void CL_DemoFrame( int msec ); qboolean CL_WriteDemoMessage( sizebuf_t *buf ); void CL_EmitDemoFrame( void ); void CL_EmitDemoSnapshot( void ); +void CL_FirstDemoFrame( void ); void CL_Stop_f( void ); demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info ); |