Compare commits

..

No commits in common. "fd8bbadb1e4f749b10ea0c24279bf3964714eed9" and "c24f51638043c01a373cc66b48a84752e1d2c146" have entirely different histories.

3 changed files with 27 additions and 131 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
Run
Category
Any%
Route
Magic Swordless
Start

View File

@ -74,22 +74,8 @@ int main(int argc, char *argv[]) {
commandcode = 12;
} else if (!strcmp(argv[1], "save")) {
commandcode = 13;
} else if (!strcmp(argv[1], "runs")) {
} else if (!strcmp(argv[1], "count")) {
commandcode = 14;
} else if (!strcmp(argv[1], "segments")) {
commandcode = 15;
} else if (!strcmp(argv[1], "start-split-stop")) {
commandcode = 16;
} else if (!strcmp(argv[1], "pause-resume")) {
commandcode = 17;
} else if (!strcmp(argv[1], "start-stop")) {
commandcode = 18;
} else if (!strcmp(argv[1], "start-split")) {
commandcode = 19;
} else if (!strcmp(argv[1], "split-stop")) {
commandcode = 20;
} else if (!strcmp(argv[1], "undo-redo")) {
commandcode = 21;
} else {
perror("No valid command given");
exit(1);
@ -107,7 +93,7 @@ int main(int argc, char *argv[]) {
//bzero(buffer,256);
//read an int response
if (commandcode < 11 || commandcode == 14 || commandcode == 15) {
if (commandcode < 11 || commandcode == 14) {
int x = -1;
n = read(sockfd, &x, sizeof(int));

View File

@ -16,7 +16,6 @@ int pausedTime = 0;
bool timerActive = false;
bool paused = false;
bool alive = true;
bool hasUndoneAtLeastOnce = false;
bool runUnsaved = false;
int timerOffset = 0;
enum event_type {
@ -36,12 +35,9 @@ struct segment {
char *longname;
char *description;
};
struct route {
char *name;
struct segment *segments;
int segment_count;
};
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;
@ -57,9 +53,6 @@ char **names, **values;
int valuecount;
struct segment *segments;
int segment_count = 0;
struct route *routes;
int route_count = 0;
struct route current_route;
//functions
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td);
@ -67,6 +60,16 @@ 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();
@ -76,26 +79,6 @@ void sendTime(int sock);
void sendValue(int sock, char* name);
void sendInt(int sock, int value);
void doprocessing (int sock);
void addPauseTime();
void subtractPauseTime();
//basic timer commands
void start();
void split();
void stop();
void skip();
void undo();
void redo();
void pause_timer();
void resume();
//convenient combination commands
void start_split_stop();
void start_split();
void split_stop();
void start_stop();
void pause_resume();
void undo_redo();
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
@ -150,27 +133,19 @@ void add_event(enum event_type t)
runMarker2 = runMarker;
}
void reset_timer()
{
runMarker = 0;
runMarker2 = 0;
}
void start()
{
if (timerActive) return;
//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
//if they accidentally hit the stop button
appendRunToFile();
reset_timer();
//TODO: Clear the run data first
timerActive = true;
add_event(START);
}
void stop()
{
if (!timerActive) return;
timerActive = false;
add_event(STOP);
//this makes sure the time clients recieve from time
@ -179,46 +154,13 @@ void stop()
runUnsaved = true;
}
void start_split_stop()
{
if (!timerActive) {
start();
} else {
if (runMarker < current_route.segment_count) {
split();
} else {
stop();
}
}
}
void start_split()
{
if (!timerActive) start();
else split();
}
void split_stop()
{
if (runMarker < current_route.segment_count) split();
else stop();
}
void start_stop()
{
if (!timerActive) start();
else stop();
}
void split()
{
if (!timerActive) return;
add_event(SPLIT);
}
void skip()
{
if (!timerActive) return;
add_event(SKIP);
}
@ -250,7 +192,6 @@ void subtractPauseTime()
void undo()
{
if (!timerActive) return;
if (runMarker > 0) {
runMarker--;
if (run[runMarker].type == STOP)
@ -263,13 +204,11 @@ void undo()
paused = true;
subtractPauseTime();
}
hasUndoneAtLeastOnce = true;
}
}
void redo()
{
if (!timerActive) return;
if (runMarker < runMarker2) {
runMarker++;
if (run[runMarker - 1].type == STOP)
@ -282,21 +221,12 @@ void redo()
paused = false;
addPauseTime();
}
} else {
hasUndoneAtLeastOnce = false;
}
}
void undo_redo()
{
if (hasUndoneAtLeastOnce) redo();
else undo();
}
//this isnt just called pause() because that would overlap with <unistd.h>
void pause_timer()
{
if (!timerActive) return;
if (!paused) {
add_event(PAUSE);
paused = true;
@ -305,7 +235,6 @@ void pause_timer()
void resume()
{
if (!timerActive) return;
if (paused) {
add_event(RESUME);
paused = false;
@ -313,12 +242,6 @@ void resume()
}
}
void pause_resume()
{
if (paused) resume();
else pause_timer();
}
void appendRunToFile()
{
if (!runUnsaved)
@ -332,9 +255,13 @@ void appendRunToFile()
fp = fopen(save_path, "a+");
fprintf(fp, "%s\n", "Run");
if (current_route.name != NULL) {
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.name);
fprintf(fp, "\t\t%s\n", current_route);
}
int i = 0;
@ -393,12 +320,13 @@ void timespecToRFC3339(struct timespec t, char buf[])
void loadFiles()
{
FILE* fp;
//TODO: for now we're just looking for the metadata values
char buff[255];
char buff2[255];
for (int i = 0; i < files; i++) {
printf("loading file: \"%s\"\n", filePaths[i]);
fp = fopen(filePaths[i], "r+");
fp = fopen(filePaths[i], "r");
while(1) {
if (!fgets(buff, 255, fp))
break;
@ -408,6 +336,7 @@ void loadFiles()
char *s = NULL;
char *l = NULL;
char *d = NULL;
//"\t\tStory 12\n\0"
for (int x = 0; x < 3; x++) {
if (!fgets(buff2, 255, fp))
break;
@ -591,27 +520,6 @@ void doprocessing (int sock)
} else if (commandcode == 14) {
printf("Recieved request for run count\n");
sendInt(sock, run_count);
} else if (commandcode == 15) {
printf("Recieved request for segment count\n");
sendInt(sock, segment_count);
} else if (commandcode == 16) {
printf("Recieved start_split_stop command\n");
start_split_stop();
} else if (commandcode == 17) {
printf("Recieved pause_resume command\n");
pause_resume();
} else if (commandcode == 18) {
printf("Recieved start-stop command\n");
start_stop();
} else if (commandcode == 19) {
printf("Recieved start-split command\n");
start_split();
} else if (commandcode == 20) {
printf("Recieved split-stop command\n");
split_stop();
} else if (commandcode == 21) {
printf("Recieved undo-redo command\n");
undo_redo();
} else {
printf("Recieved invalid command code, ignoring...\n");
}