diff options
author | Andrey Nazarov <skuller@skuller.net> | 2011-04-28 19:29:04 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2011-04-28 19:29:04 +0400 |
commit | faa6751024703c49cb98765a50bbc5ebb03d9d3d (patch) | |
tree | 8e89742ea6de34c1de80fa4ec80c7bfdaabfedb7 /src/common.c | |
parent | 615b6634d3bcf632b57b5504759a3034284576a1 (diff) |
Enhance demo seeking time specification.
Extend syntax to allow for minutes, seconds and tenths of second to be
specified. Allow for absolute positioning within demo file.
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 8a0e859..adb384e 100644 --- a/src/common.c +++ b/src/common.c @@ -1470,6 +1470,55 @@ void Com_PlayerToEntityState( const player_state_t *ps, entity_state_t *es ) { es->angles[ROLL] = 0; } +#if USE_CLIENT || USE_MVD_CLIENT +/* +================ +Com_ParseTimespec + +Parses time/frame specification for seeking in demos. +Does not check for integer overflow... +================ +*/ +qboolean Com_ParseTimespec( const char *s, int *frames ) { + unsigned long c1, c2, c3; + char *p; + + c1 = strtoul( s, &p, 10 ); + if( !*p ) { + *frames = c1 * 10; // sec + return qtrue; + } + + if( *p == '.' ) { + c2 = strtoul( p + 1, &p, 10 ); + if( *p ) + return qfalse; + *frames = c1 * 10 + c2; // sec.frac + return qtrue; + } + + if( *p == ':' ) { + c2 = strtoul( p + 1, &p, 10 ); + if( !*p ) { + *frames = c1 * 600 + c2 * 10; // min:sec + return qtrue; + } + + if( *p == '.' ) { + c3 = strtoul( p + 1, &p, 10 ); + if( *p ) + return qfalse; + *frames = c1 * 600 + c2 * 10 + c3; // min:sec.frac + return qtrue; + } + + return qfalse; + } + + return qfalse; +} +#endif + /* ================ Com_HashString |