Compare commits

..

No commits in common. "b700113b8820e53e0b7b18b31e3e6a098d56181f" and "d09b991771f7cc796fdff7ad03915ffec61b72ce" have entirely different histories.

View File

@ -12,6 +12,7 @@
#define NS_PER_S 1000000000
struct timespec finish, delta;
int pausedTime = 0;
bool timerActive = false;
bool paused = false;
bool alive = true;
@ -76,9 +77,10 @@ void sendInt(int sock, int value);
void sendValue(int sock, char* name);
void sendString(int sock, char* str);
void process_socket_input(int sock);
void addPauseTime();
void subtractPauseTime();
void set_metadata(char *key, char *value);
void save_metadata_to_file(char *token, char *token2);
void reset_timer();
int current_ms();
//basic timer commands
@ -90,11 +92,9 @@ void undo();
void redo();
void pause_timer();
void resume();
void reset();
//convenient combination commands
void start_split_stop();
void start_reset();
void start_split();
void split_stop();
void start_stop();
@ -157,6 +157,7 @@ void add_event(enum event_type t)
void reset_timer()
{
pausedTime = 0;
runMarker = 0;
runMarker2 = 0;
}
@ -184,16 +185,6 @@ void stop()
runUnsaved = true;
}
//Identical function to stop() but with a RESET event
void reset()
{
if (!timerActive) return;
timerActive = false;
add_event(RESET);
finish = run[runMarker - 1].time;
runUnsaved = true;
}
void start_split_stop()
{
if (!timerActive) {
@ -225,12 +216,6 @@ void start_stop()
else stop();
}
void start_reset()
{
if (!timerActive) start();
else reset();
}
void split()
{
if (!timerActive) return;
@ -243,6 +228,32 @@ void skip()
add_event(SKIP);
}
void addPauseTime()
{
int pauseEvent = 0;
for (int i = runMarker - 2; i >= 1; i--) {
if (run[i].type == PAUSE) {
pauseEvent = i;
break;
}
}
sub_timespec(run[pauseEvent].time, run[runMarker - 1].time, &delta);
pausedTime += timespecToMS(delta);
}
void subtractPauseTime()
{
int pauseEvent = 0;
for (int i = runMarker - 1; i >= i; i--) {
if (run[i].type == PAUSE) {
pauseEvent = i;
break;
}
}
sub_timespec(run[pauseEvent].time, run[runMarker].time, &delta);
pausedTime -= timespecToMS(delta);
}
void undo()
{
if (runMarker > 0) {
@ -257,6 +268,7 @@ void undo()
paused = false;
if (run[runMarker].type == RESUME) {
paused = true;
subtractPauseTime();
}
hasUndoneAtLeastOnce = true;
}
@ -278,6 +290,7 @@ void redo()
paused = true;
if (run[runMarker - 1].type == RESUME) {
paused = false;
addPauseTime();
}
}
if (runMarker == runMarker2) {
@ -307,6 +320,7 @@ void resume()
if (paused) {
add_event(RESUME);
paused = false;
addPauseTime();
}
}
@ -474,12 +488,12 @@ int current_ms()
{
if (timerActive)
clock_gettime(CLOCK_REALTIME, &finish);
//if (paused) {
// sub_timespec(run[0].time, run[runMarker - 1].time, &delta);
//} else {
if (paused) {
sub_timespec(run[0].time, run[runMarker - 1].time, &delta);
} else {
sub_timespec(run[0].time, finish, &delta);
//}
return timespecToMS(delta);
}
return timespecToMS(delta) - pausedTime;
}
void sendInt(int sock, int value)
@ -586,8 +600,6 @@ void process_socket_input(int sock)
start();
} else if (!strcmp(token, "stop")) {
stop();
} else if (!strcmp(token, "reset")) {
reset();
} else if (!strcmp(token, "kill")) {
alive = false;
} else if (!strcmp(token, "split")) {
@ -610,8 +622,6 @@ void process_socket_input(int sock)
pause_resume();
} else if (!strcmp(token, "start-stop")) {
start_stop();
} else if (!strcmp(token, "start-reset")) {
start_reset();
} else if (!strcmp(token, "start-split")) {
start_split();
} else if (!strcmp(token, "split-stop")) {
@ -624,24 +634,6 @@ void process_socket_input(int sock)
token = strtok(NULL, " ");
if (!strcmp(token, "current_time")) {
sendInt(sock, current_ms());
} else if (!strcmp(token, "current_time_with_pause")) {
int running_pause = 0;
struct timespec p, r;
bool tracking_pause = false;
for (int i = 0; i < runMarker; i++) {
if (run[i].type == PAUSE) {
sub_timespec(run[0].time, run[i].time, &p);
tracking_pause = true;
}
if (run[i].type == RESUME) {
sub_timespec(run[0].time, run[i].time, &r);
running_pause += timespecToMS(r) - timespecToMS(p);
tracking_pause = false;
} else if (i == runMarker - 1 && tracking_pause) {
running_pause += current_ms() - timespecToMS(p);
}
}
sendInt(sock, current_ms() - running_pause);
} else if (!strcmp(token, "run_count")) {
sendInt(sock, run_count);
} else if (!strcmp(token, "segment_count")) {
@ -688,35 +680,6 @@ void process_socket_input(int sock)
struct timespec t;
sub_timespec(run[0].time, run[x].time, &t);
sendInt(sock, timespecToMS(t));
} else if (!strcmp(token, "event_time_with_pause")) {
token = strtok(NULL, " ");
int x;
if (!strcmp(token, "last"))
x = runMarker - 1;
else if (!strcmp(token, "first"))
x = 0;
else
x = atoi(token);
int running_pause = 0;
struct timespec p, r;
bool tracking_pause = false;
for (int i = 0; i < x; i++) {
if (run[i].type == PAUSE) {
sub_timespec(run[0].time, run[i].time, &p);
tracking_pause = true;
}
if (run[i].type == RESUME) {
sub_timespec(run[0].time, run[i].time, &r);
running_pause += timespecToMS(r) - timespecToMS(p);
tracking_pause = false;
} else if (i == x - 1 && tracking_pause) {
sub_timespec(run[0].time, run[x].time, &r);
running_pause += timespecToMS(r) - timespecToMS(p);
}
}
struct timespec t;
sub_timespec(run[0].time, run[x].time, &t);
sendInt(sock, timespecToMS(t) - running_pause);
} else if (!strcmp(token, "event_type")) {
token = strtok(NULL, " ");
int x;