From 24a76ef4393391ce719da4efc40f01ce968fc751 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 19 Dec 2000 20:33:06 +0000 Subject: [PATCH] don't seek while backing up over demotime. gzipped demos no longer slow down as the demo progresses (this will probably also be good for eventual dzip support). --- source/cl_demo.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/source/cl_demo.c b/source/cl_demo.c index e9285e3..b68f9ed 100644 --- a/source/cl_demo.c +++ b/source/cl_demo.c @@ -175,10 +175,17 @@ CL_GetDemoMessage (void) float demotime; byte c; usercmd_t *pcmd; + static int demotime_cached; + static float cached_demotime; // read the time from the packet - Qread (cls.demofile, &demotime, sizeof (demotime)); - demotime = LittleFloat (demotime); + if (demotime_cached) { + demotime = cached_demotime; + demotime_cached = 0; + } else { + Qread (cls.demofile, &demotime, sizeof (demotime)); + demotime = LittleFloat (demotime); + } // decide if it is time to grab the next message if (cls.timedemo) { @@ -187,8 +194,8 @@ CL_GetDemoMessage (void) else if (demotime > cls.td_lastframe) { cls.td_lastframe = demotime; // rewind back to time - Qseek (cls.demofile, Qtell (cls.demofile) - sizeof (demotime), - SEEK_SET); + demotime_cached = 1; + cached_demotime = demotime; return 0; // allready read this frame's message } if (!cls.td_starttime && cls.state == ca_active) { @@ -203,13 +210,13 @@ CL_GetDemoMessage (void) // too far back realtime = demotime - 1.0; // rewind back to time - Qseek (cls.demofile, Qtell (cls.demofile) - sizeof (demotime), - SEEK_SET); + demotime_cached = 1; + cached_demotime = demotime; return 0; } else if (realtime < demotime) { // rewind back to time - Qseek (cls.demofile, Qtell (cls.demofile) - sizeof (demotime), - SEEK_SET); + demotime_cached = 1; + cached_demotime = demotime; return 0; // don't need another message yet } } else