added saving previous run to file on new run start

This commit is contained in:
Lexi Quinn 2023-07-20 01:18:44 +10:00
parent f5e5c506af
commit d3f7a25a64
3 changed files with 116 additions and 2 deletions

View File

@ -147,6 +147,8 @@ applicable, or by default is matched with the last set of metadata declared by
the time of the run directive the time of the run directive
Run Run
Category
Any%
Route Route
Magic Swordless Magic Swordless
Start Start
@ -163,7 +165,7 @@ Run
3121111 3121111
Pause Pause
421397 421397
Unpause Resume
2016-10-23 11:16:04.175Z 2016-10-23 11:16:04.175Z
Stop (The last event in a run is always a Stop) Stop (The last event in a run is always a Stop)
123111 123111

View File

@ -30,6 +30,8 @@ struct run_event {
struct timespec time; struct timespec time;
}; };
char* current_category = NULL;
char* current_route = NULL;
struct run_event *run; struct run_event *run;
//Enough to hold a sm64 16 star, can realloc later //Enough to hold a sm64 16 star, can realloc later
int runMaxLength = 12; int runMaxLength = 12;
@ -37,11 +39,37 @@ int runMarker = 0;
int runMarker2 = 0; int runMarker2 = 0;
//save file stuff //save file stuff
char *default_file_name = "untitled.quest";
int files = 0; int files = 0;
char **filePaths = NULL; char **filePaths = NULL;
char **names, **values; char **names, **values;
int valuecount; int valuecount;
//functions
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td);
void offset_timespec(int milliseconds, struct timespec* t);
int timespecToMS(struct timespec t);
void extend_run();
void add_event(enum event_type t);
void start();
void stop();
void split();
void skip();
void addPauseTime();
void subtractPauseTime();
void undo();
void redo();
void pause_timer();
void resume();
void appendRunToFile();
void timespecToRFC3339(struct timespec t, char buf[]);
void loadFiles();
void addFile(char *path);
void sendTime(int sock);
void sendValue(int sock, char* name);
void doprocessing (int sock);
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td) void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
{ {
td->tv_nsec = t2.tv_nsec - t1.tv_nsec; td->tv_nsec = t2.tv_nsec - t1.tv_nsec;
@ -99,6 +127,8 @@ void start()
//TODO: Save the old run to the file before the new one starts, //TODO: Save the old run to the file before the new one starts,
//the reason to do this here is it gives the runner a chance to undo //the reason to do this here is it gives the runner a chance to undo
//if they accidentally hit the stop button //if they accidentally hit the stop button
if (run[runMarker - 1].type == STOP)
appendRunToFile();
//TODO: Clear the run data first //TODO: Clear the run data first
timerActive = true; timerActive = true;
add_event(START); add_event(START);
@ -201,6 +231,77 @@ void resume()
} }
} }
void appendRunToFile()
{
char* save_path = NULL;
if (files <= 0)
save_path = default_file_name;
else
save_path = filePaths[0];
FILE* fp;
fp = fopen(save_path, "a+");
fprintf(fp, "%s\n", "Run");
if (current_category != NULL) {
fprintf(fp, "\t%s\n", "Category");
fprintf(fp, "\t\t%s\n", current_category);
}
if (current_route != NULL) {
fprintf(fp, "\t%s\n", "Route");
fprintf(fp, "\t\t%s\n", current_route);
}
int i = 0;
bool done = false;
while (!done) {
if (run[i].type == STOP) {
done = true;
}
switch (run[i].type) {
case START:
fprintf(fp, "\t%s\n", "Start");
break;
case SPLIT:
fprintf(fp, "\t%s\n", "Split");
break;
case SKIP:
fprintf(fp, "\t%s\n", "Skip");
break;
case PAUSE:
fprintf(fp, "\t%s\n", "Pause");
break;
case RESUME:
fprintf(fp, "\t%s\n", "Resume");
break;
case STOP:
fprintf(fp, "\t%s\n", "Stop");
break;
}
if (i == 0) {
char buf[25];
timespecToRFC3339(run[i].time, buf);
fprintf(fp, "\t\t%s\n", buf);
}
else {
sub_timespec(run[i - 1].time, run[i].time, &delta);
fprintf(fp, "\t\t%d\n", timespecToMS(delta));
}
i++;
}
fprintf(fp, "\n");
fclose(fp);
}
void timespecToRFC3339(struct timespec t, char buf[])
{
const int tmpsize = 21;
struct tm tm;
gmtime_r(&t.tv_sec, &tm);
strftime(buf, tmpsize, "%Y-%m-%d %H:%M:%S.", &tm);
sprintf(buf + tmpsize - 1, "%03luZ", (t.tv_nsec / 1000000));
}
void loadFiles() void loadFiles()
{ {
FILE* fp; FILE* fp;

View File

@ -31,6 +31,17 @@ struct color bl = {224, 34, 34}; //Behind, and losing time segment color
int w, h; int w, h;
//functions
void timestring(char *str, int ms);
void printbig(int x, int y, int ms);
int timestringDigits(int ms);
void resize(int i);
void initScreen();
void resetScreen();
void die(int i);
void processColorString(struct color *c, char* s);
int timestringDigits(int ms) int timestringDigits(int ms)
{ {
int chars = 4; int chars = 4;
@ -112,7 +123,7 @@ void initScreen()
t.c_lflag &= (~ECHO & ~ICANON); t.c_lflag &= (~ECHO & ~ICANON);
tcsetattr(1, TCSANOW, &t); tcsetattr(1, TCSANOW, &t);
//TODO:Figure out why i did this //TODO:Figure out why i did this
dup(0); //dup(0);
fcntl(0, F_SETFL, O_NONBLOCK); fcntl(0, F_SETFL, O_NONBLOCK);
printf("\033[?1049h\n"); //Switch to TUI mode (alternate buffer) printf("\033[?1049h\n"); //Switch to TUI mode (alternate buffer)
printf("\033[?25l\n"); //Hide text cursor printf("\033[?25l\n"); //Hide text cursor