Making watching more efficient:

* Don't uselessly read the ttyrec file at the start.
* Toggle the ttyrec file between buffered and non-buffered. Non-buffered I/O
  via stdio can be very inefficient.
* Keep stdout buffered, and flush it when waiting for a key or more ttyrec
  data.

Tested somewhat on my FreeBSD 4 machine.


git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@331 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Jilles Tjoelker 2004-08-22 22:32:10 +00:00
parent baa776486f
commit e31ca985ee
1 changed files with 9 additions and 6 deletions

View File

@ -151,6 +151,7 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
while (ttyread (fp, h, buf, 1) == READ_EOF)
{
struct timeval w = { 0, 100000 };
fflush(stdout);
select (0, NULL, NULL, NULL, &w);
clearerr (fp);
if (counter++ > (20 * 60 * 10))
@ -233,11 +234,8 @@ ttyplay (FILE * fp, double speed, ReadFunc read_func,
int r = READ_EOF;
struct timeval prev;
setbuf (stdout, NULL);
setbuf (fp, NULL);
/* for dtype's attempt to get the last clrscr and playback from there */
if (offset)
if (offset != -1)
{
fseek (fp, offset, SEEK_SET);
}
@ -336,6 +334,7 @@ set_seek_offset_clrscr (FILE * fp)
}
#if 0 /* not used anymore */
void
ttyskipall (FILE * fp)
{
@ -344,6 +343,7 @@ ttyskipall (FILE * fp)
*/
ttyplay (fp, 0, ttyread, ttynowrite, ttynowait, 0);
}
#endif
void
ttyplayback (FILE * fp, double speed, ReadFunc read_func, WaitFunc wait_func)
@ -358,13 +358,16 @@ ttypeek (FILE * fp, double speed)
do
{
ttyskipall (fp);
setvbuf (fp, NULL, _IOFBF, 0);
set_seek_offset_clrscr (fp);
if (seek_offset_clrscr)
{
ttyplay (fp, 0, ttyread, ttywrite, ttynowait, seek_offset_clrscr);
}
r = ttyplay (fp, speed, ttypread, ttywrite, ttynowait, 0);
clearerr (fp);
setvbuf (fp, NULL, _IONBF, 0);
fflush (stdout);
r = ttyplay (fp, speed, ttypread, ttywrite, ttynowait, -1);
} while (r == READ_RESTART);
}