summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2011-04-28 19:29:04 +0400
committerAndrey Nazarov <skuller@skuller.net>2011-04-28 19:29:04 +0400
commitfaa6751024703c49cb98765a50bbc5ebb03d9d3d (patch)
tree8e89742ea6de34c1de80fa4ec80c7bfdaabfedb7 /src/common.c
parent615b6634d3bcf632b57b5504759a3034284576a1 (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.c49
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