added saving previous run to file on new run start
This commit is contained in:
parent
f5e5c506af
commit
d3f7a25a64
@ -147,6 +147,8 @@ applicable, or by default is matched with the last set of metadata declared by
|
||||
the time of the run directive
|
||||
|
||||
Run
|
||||
Category
|
||||
Any%
|
||||
Route
|
||||
Magic Swordless
|
||||
Start
|
||||
@ -163,7 +165,7 @@ Run
|
||||
3121111
|
||||
Pause
|
||||
421397
|
||||
Unpause
|
||||
Resume
|
||||
2016-10-23 11:16:04.175Z
|
||||
Stop (The last event in a run is always a Stop)
|
||||
123111
|
||||
|
101
src2/server.c
101
src2/server.c
@ -30,6 +30,8 @@ struct run_event {
|
||||
struct timespec time;
|
||||
};
|
||||
|
||||
char* current_category = NULL;
|
||||
char* current_route = NULL;
|
||||
struct run_event *run;
|
||||
//Enough to hold a sm64 16 star, can realloc later
|
||||
int runMaxLength = 12;
|
||||
@ -37,11 +39,37 @@ int runMarker = 0;
|
||||
int runMarker2 = 0;
|
||||
|
||||
//save file stuff
|
||||
char *default_file_name = "untitled.quest";
|
||||
int files = 0;
|
||||
char **filePaths = NULL;
|
||||
char **names, **values;
|
||||
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)
|
||||
{
|
||||
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,
|
||||
//the reason to do this here is it gives the runner a chance to undo
|
||||
//if they accidentally hit the stop button
|
||||
if (run[runMarker - 1].type == STOP)
|
||||
appendRunToFile();
|
||||
//TODO: Clear the run data first
|
||||
timerActive = true;
|
||||
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()
|
||||
{
|
||||
FILE* fp;
|
||||
|
13
src2/tui.c
13
src2/tui.c
@ -31,6 +31,17 @@ struct color bl = {224, 34, 34}; //Behind, and losing time segment color
|
||||
|
||||
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 chars = 4;
|
||||
@ -112,7 +123,7 @@ void initScreen()
|
||||
t.c_lflag &= (~ECHO & ~ICANON);
|
||||
tcsetattr(1, TCSANOW, &t);
|
||||
//TODO:Figure out why i did this
|
||||
dup(0);
|
||||
//dup(0);
|
||||
fcntl(0, F_SETFL, O_NONBLOCK);
|
||||
printf("\033[?1049h\n"); //Switch to TUI mode (alternate buffer)
|
||||
printf("\033[?25l\n"); //Hide text cursor
|
||||
|
Loading…
Reference in New Issue
Block a user