mirror of
https://github.com/paxed/dgamelaunch.git
synced 2025-07-29 16:45:35 +02:00
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:
parent
baa776486f
commit
e31ca985ee
15
ttyplay.c
15
ttyplay.c
@ -151,6 +151,7 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
|
|||||||
while (ttyread (fp, h, buf, 1) == READ_EOF)
|
while (ttyread (fp, h, buf, 1) == READ_EOF)
|
||||||
{
|
{
|
||||||
struct timeval w = { 0, 100000 };
|
struct timeval w = { 0, 100000 };
|
||||||
|
fflush(stdout);
|
||||||
select (0, NULL, NULL, NULL, &w);
|
select (0, NULL, NULL, NULL, &w);
|
||||||
clearerr (fp);
|
clearerr (fp);
|
||||||
if (counter++ > (20 * 60 * 10))
|
if (counter++ > (20 * 60 * 10))
|
||||||
@ -233,11 +234,8 @@ ttyplay (FILE * fp, double speed, ReadFunc read_func,
|
|||||||
int r = READ_EOF;
|
int r = READ_EOF;
|
||||||
struct timeval prev;
|
struct timeval prev;
|
||||||
|
|
||||||
setbuf (stdout, NULL);
|
|
||||||
setbuf (fp, NULL);
|
|
||||||
|
|
||||||
/* for dtype's attempt to get the last clrscr and playback from there */
|
/* for dtype's attempt to get the last clrscr and playback from there */
|
||||||
if (offset)
|
if (offset != -1)
|
||||||
{
|
{
|
||||||
fseek (fp, offset, SEEK_SET);
|
fseek (fp, offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
@ -336,6 +334,7 @@ set_seek_offset_clrscr (FILE * fp)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0 /* not used anymore */
|
||||||
void
|
void
|
||||||
ttyskipall (FILE * fp)
|
ttyskipall (FILE * fp)
|
||||||
{
|
{
|
||||||
@ -344,6 +343,7 @@ ttyskipall (FILE * fp)
|
|||||||
*/
|
*/
|
||||||
ttyplay (fp, 0, ttyread, ttynowrite, ttynowait, 0);
|
ttyplay (fp, 0, ttyread, ttynowrite, ttynowait, 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
ttyplayback (FILE * fp, double speed, ReadFunc read_func, WaitFunc wait_func)
|
ttyplayback (FILE * fp, double speed, ReadFunc read_func, WaitFunc wait_func)
|
||||||
@ -358,13 +358,16 @@ ttypeek (FILE * fp, double speed)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ttyskipall (fp);
|
setvbuf (fp, NULL, _IOFBF, 0);
|
||||||
set_seek_offset_clrscr (fp);
|
set_seek_offset_clrscr (fp);
|
||||||
if (seek_offset_clrscr)
|
if (seek_offset_clrscr)
|
||||||
{
|
{
|
||||||
ttyplay (fp, 0, ttyread, ttywrite, ttynowait, 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);
|
} while (r == READ_RESTART);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user