#include "angband.h" #include "ui-event.h" #include "player/types.h" #include "externs.h" static double max_wait_us = 30000000; static struct timeval prev_time; static ang_file *logfile; void writelog(ui_event_data ke) { u32b delta; struct timeval cur_time; if (logfile == NULL) return; gettimeofday(&cur_time, 0); if (prev_time.tv_sec == 0) delta = 0; else { /* avoid integer overflow */ double ddelta = 1000000.0*(cur_time.tv_sec-prev_time.tv_usec) + cur_time.tv_usec - prev_time.tv_usec; if (ddelta > max_wait_us) ddelta = max_wait_us ; delta = ddelta; } prev_time = cur_time; fwrite_l(logfile, delta); fwrite_l(logfile, (u32b) ke.type); fwrite_b(logfile, ke.mousex); fwrite_b(logfile, ke.mousey); fwrite_b(logfile, (byte) ke.key); fwrite_s(logfile, (u16b) ke.index); } ui_event_data readlog(void) { u32b delta; int err; ui_event_data ke; err = fread_l(logfile, &delta); err |= fread_l(logfile, (u32b*) &ke.type); err |= fread_b(logfile, &ke.mousex); err |= fread_b(logfile, &ke.mousey); err |= fread_b(logfile, (byte*) &ke.key); err |= fread_s(logfile, (u16b*) &ke.index); if (err) { plog("Thththat's all folks!"); quit(0); } } void cmd_start_logging(void) { char name[84]; char dirname[1024]; char fname[1024]; int i; ang_file *fprf; ui_event_data ke = { EVT_RESIZE, Term->wid, Term->hgt, '\xff', 0 }; const dump_func prefs[] = { autoinsc_dump, squelch_dump, option_dump, keymap_dump }; strnfmt(name, sizeof name, "%s.bmv", op_ptr->full_name); get_file(name, dirname, sizeof dirname); mkdir(dirname, 0x733); p_ptr->no_score |= NOSCORE_MOVIE; save_game(); path_build(fname, sizeof fname, dirname, "save"); copy_file(savefile, fname); p_ptr->no_score &= ~NOSCORE_MOVIE; save_game(); path_build(fname, sizeof fname, dirname, "pref"); fprf = file_open(fname, MODE_WRITE, FTYPE_TEXT); for (i = 0; i < N_ELEMENTS(prefs); i++) { prefs[i](fprf); } file_close(fprf); path_build(fname, sizeof fname, dirname, "log"); logfile = file_open(fname, MODE_WRITE, FTYPE_RAW); writelog(ke); } void cmd_stop_logging(void) { file_close(logfile); logfile = NULL; } void start_reading() { char dirname[1024]; char filename[1024]; p_ptr->no_score |= NOSCORE_REPLAY; my_strcpy(dirname, savefile, strrchr(savefile, *PATH_SEP)-savefile); path_build(filename, sizeof filename, dirname, "pref"); process_pref_file(filename); path_build(filename, sizeof filename, dirname, "log"); logfile = file_open(filename, MODE_READ, FTYPE_RAW); }