Compare commits
No commits in common. "1aa1ed514aef08f68291aada6c3ba04b6e75f0ae" and "9c7ccfe0b0ca1e96c146c7ea4ee14df550e51541" have entirely different histories.
1aa1ed514a
...
9c7ccfe0b0
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
TARGET = quest
|
||||
LIBS = -lm -luiohook -lcjson -lxcb -lXinerama -lX11
|
||||
LIBS = -lm -luiohook -lcjson
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall
|
||||
INSTALL_PATH = /usr/local
|
||||
|
@ -1,2 +0,0 @@
|
||||
{pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.callPackage ./derivation.nix {}
|
@ -1,23 +0,0 @@
|
||||
{ stdenv }:
|
||||
stdenv.mkDerivation rec {
|
||||
name = "quest-${version}";
|
||||
version = "0.7";
|
||||
|
||||
src = ./src2/.;
|
||||
|
||||
nativeBuildInputs = [ ];
|
||||
buildInputs = [ ];
|
||||
|
||||
buildPhase = ''
|
||||
gcc server.c -o quest-daemon
|
||||
gcc client.c -o quest-log
|
||||
gcc tui.c -o quest
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp quest-daemon $out/bin
|
||||
cp quest-log $out/bin
|
||||
cp quest $out/bin
|
||||
'';
|
||||
}
|
@ -102,9 +102,9 @@ Runs by themselves are simply a list of events that occured
|
||||
to this data, these more complicated directives are used to define segments
|
||||
that are played between splits and routes made up of these segments.
|
||||
Define all your possible segments first, followed by all routes.
|
||||
If no segments are defined, a single unnamed segment is to be assumed.
|
||||
If no segments are defined, a single unnamed segment is assumed.
|
||||
If no routes are defined, a single unnamed route that passes through all
|
||||
segments in the order of their definition is to be assumed.
|
||||
segments in the order of their definition is assumed.
|
||||
|
||||
Segment
|
||||
Shortname
|
||||
@ -141,14 +141,12 @@ Run Directives
|
||||
These directives are much more complicated and are not intended to be written
|
||||
by a human but rather by the timer software, they will make up the majority
|
||||
of a file as they are the run history which may be quite long.
|
||||
The data passed by these directives exists agnostic of segments, route, games,
|
||||
These data passed by these directives exists agnostic of segments, route, games,
|
||||
or categories, rather they are either explicitly matched with metadata that is
|
||||
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
|
||||
@ -165,7 +163,7 @@ Run
|
||||
3121111
|
||||
Pause
|
||||
421397
|
||||
Resume
|
||||
Unpause
|
||||
2016-10-23 11:16:04.175Z
|
||||
Stop (The last event in a run is always a Stop)
|
||||
123111
|
||||
|
@ -22,7 +22,6 @@ struct pastseg *pastRuns;
|
||||
int segCount;
|
||||
int currSeg = -1;
|
||||
char currentTime[10];
|
||||
int *route;
|
||||
|
||||
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
|
||||
{
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
struct segment
|
||||
{
|
||||
int id;
|
||||
char *name;
|
||||
int ms;
|
||||
bool isSkipped;
|
||||
@ -50,7 +49,6 @@ extern struct segment *bestsegs;
|
||||
extern struct segment *wrrun;
|
||||
extern struct segment *segments;
|
||||
extern struct timespec notif;
|
||||
extern int *route;
|
||||
|
||||
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td);
|
||||
void add_timespec(struct timespec t1, struct timespec t2, struct timespec* td);
|
||||
|
@ -72,8 +72,6 @@ int main(int argc, char *argv[]) {
|
||||
commandcode = 11;
|
||||
} else if (!strcmp(argv[1], "background")) {
|
||||
commandcode = 12;
|
||||
} else if (!strcmp(argv[1], "save")) {
|
||||
commandcode = 13;
|
||||
} else {
|
||||
perror("No valid command given");
|
||||
exit(1);
|
||||
|
167
src2/server.c
167
src2/server.c
@ -16,7 +16,6 @@ int pausedTime = 0;
|
||||
bool timerActive = false;
|
||||
bool paused = false;
|
||||
bool alive = true;
|
||||
bool runUnsaved = false;
|
||||
int timerOffset = 0;
|
||||
enum event_type {
|
||||
START,
|
||||
@ -31,8 +30,6 @@ 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;
|
||||
@ -40,38 +37,11 @@ int runMarker = 0;
|
||||
int runMarker2 = 0;
|
||||
|
||||
//save file stuff
|
||||
char *default_file_name = "untitled.quest";
|
||||
int run_count = 0;
|
||||
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;
|
||||
@ -129,7 +99,6 @@ 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
|
||||
appendRunToFile();
|
||||
//TODO: Clear the run data first
|
||||
timerActive = true;
|
||||
add_event(START);
|
||||
@ -142,7 +111,6 @@ void stop()
|
||||
//this makes sure the time clients recieve from time
|
||||
//requests match the time on the stop event
|
||||
finish = run[runMarker - 1].time;
|
||||
runUnsaved = true;
|
||||
}
|
||||
|
||||
void split()
|
||||
@ -233,81 +201,6 @@ void resume()
|
||||
}
|
||||
}
|
||||
|
||||
void appendRunToFile()
|
||||
{
|
||||
if (!runUnsaved)
|
||||
return;
|
||||
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);
|
||||
run_count++;
|
||||
runUnsaved = false;
|
||||
}
|
||||
|
||||
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;
|
||||
@ -316,31 +209,23 @@ void loadFiles()
|
||||
char buff2[255];
|
||||
|
||||
for (int i = 0; i < files; i++) {
|
||||
printf("loading file: \"%s\"\n", filePaths[i]);
|
||||
fp = fopen(filePaths[i], "r");
|
||||
|
||||
while(1) {
|
||||
if (!fgets(buff, 255, fp))
|
||||
break;
|
||||
if (buff[0] == '/' && buff[1] == '/' || buff[0] == '\n' || buff[0] == '\t')
|
||||
continue;
|
||||
if (!strcmp(buff, "Segment\n") || !strcmp(buff, "Route\n"))
|
||||
continue;
|
||||
if (!strcmp(buff, "Run\n")) {
|
||||
run_count++;
|
||||
continue;
|
||||
}
|
||||
if (!fgets(buff2, 255, fp))
|
||||
char *x = fgets(buff, 255, fp);
|
||||
if (buff[0] == '/' && buff[1] == '/' || buff[0] == '\n')
|
||||
continue;
|
||||
if (!strcmp(buff, "Segment") || !strcmp(buff, "Route") || x == NULL)
|
||||
break;
|
||||
fgets(buff2, 255, fp);
|
||||
if (buff2[0] == '\t') {
|
||||
valuecount++;
|
||||
|
||||
names = realloc(names, sizeof(char*) * valuecount);
|
||||
names[valuecount - 1] = malloc(strlen(buff));
|
||||
names[valuecount - 1] = malloc(strlen(buff) - 1);
|
||||
strncpy(names[valuecount - 1], buff, strlen(buff) - 1);
|
||||
names[valuecount - 1][strlen(buff)] = '\0';
|
||||
|
||||
values = realloc(values, sizeof(char*) * valuecount);
|
||||
values[valuecount - 1] = malloc(strlen(buff2) - 1);
|
||||
values[valuecount - 1] = malloc(strlen(buff2) - 2);
|
||||
strncpy(values[valuecount - 1], buff2 + 1, strlen(buff2) - 1);
|
||||
values[valuecount - 1][strlen(buff2)] = '\0';
|
||||
}
|
||||
@ -353,7 +238,6 @@ void loadFiles()
|
||||
for (int i = 0; i < valuecount; i++) {
|
||||
printf("%s | %s", names[i], values[i]);
|
||||
}
|
||||
printf("%d\n", run_count);
|
||||
}
|
||||
|
||||
//TODO: eventually file loading should support loading multiple files
|
||||
@ -451,9 +335,6 @@ void doprocessing (int sock)
|
||||
} else if (commandcode == 12) {
|
||||
printf("Recieved request for background color\n");
|
||||
sendValue(sock, "Background-Color");
|
||||
} else if (commandcode == 13) {
|
||||
printf("Recieved save command\n");
|
||||
appendRunToFile();
|
||||
} else {
|
||||
printf("Recieved invalid command code, ignoring...\n");
|
||||
}
|
||||
@ -492,19 +373,43 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Now start listening for the clients, here
|
||||
* process will go in sleep mode and will wait
|
||||
* for the incoming connection
|
||||
*/
|
||||
|
||||
listen(sockfd,5);
|
||||
clilen = sizeof(cli_addr);
|
||||
|
||||
printf("Ready!\n");
|
||||
while (alive) {
|
||||
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
|
||||
|
||||
if (newsockfd < 0) {
|
||||
perror("ERROR on accept");
|
||||
exit(1);
|
||||
}
|
||||
doprocessing(newsockfd);
|
||||
close(newsockfd);
|
||||
}
|
||||
|
||||
/* Create child process */
|
||||
//pid = fork();
|
||||
pid = 1;
|
||||
|
||||
if (pid < 0) {
|
||||
perror("ERROR on fork");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
/* This is the child process */
|
||||
//close(sockfd);
|
||||
//doprocessing(newsockfd);
|
||||
//exit(0);
|
||||
}
|
||||
else {
|
||||
doprocessing(newsockfd);
|
||||
close(newsockfd);
|
||||
}
|
||||
|
||||
} /* end of while */
|
||||
free(run);
|
||||
close(sockfd);
|
||||
}
|
||||
|
70
src2/tui.c
70
src2/tui.c
@ -31,17 +31,6 @@ 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;
|
||||
@ -64,7 +53,7 @@ int timestringDigits(int ms)
|
||||
void printbig(int x, int y, int ms)
|
||||
{
|
||||
char small[13];
|
||||
timestring(small, ms);
|
||||
timestring(&small, ms);
|
||||
if (w < strlen(small)) {
|
||||
printf("2smol\n");
|
||||
return;
|
||||
@ -78,19 +67,30 @@ void printbig(int x, int y, int ms)
|
||||
printf("\033[%d;%dH", y + sy, x); //go to position
|
||||
for (int cc = 0; cc < 12; cc++) { //then, for every character
|
||||
int c = small[cc]; //check what character we're on
|
||||
int mapcharacterwidth = (c >= 48 && c <= 57) ? 4 : 2;//if its a number, print 4 pixels, if its punctuation, print 2 pixels
|
||||
int mapoffset;
|
||||
if (c >= 48 && c <= 57)
|
||||
mapoffset = (c - 48) * 4;
|
||||
else if (c == 46)
|
||||
mapoffset = 42;
|
||||
else
|
||||
mapoffset = 40;
|
||||
for (int xx = 0; xx < mapcharacterwidth; xx++) {
|
||||
if (numbermap[sy][mapoffset + xx] == 'x')
|
||||
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
|
||||
if (numbermap[sy][mapoffset + xx] == '.')
|
||||
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
|
||||
if (c >= 48 && c <= 57) { //if its a number, print 4 pixels
|
||||
for (int xx = 0; xx < 4; xx++) {
|
||||
int xxx = c - 48;
|
||||
if (numbermap[sy][(xxx * 4) + xx] == 'x')
|
||||
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
|
||||
if (numbermap[sy][(xxx * 4) + xx] == '.')
|
||||
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
|
||||
}
|
||||
}
|
||||
if (c == 46 || c == 58) { //if its punctuation, print 2 pixels
|
||||
for (int xx = 0; xx < 2; xx++) {
|
||||
if (c == 46) {
|
||||
if (numbermap[sy][42 + xx] == 'x')
|
||||
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
|
||||
if (numbermap[sy][42 + xx] == '.')
|
||||
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
|
||||
}
|
||||
if (c == 58) {
|
||||
if (numbermap[sy][40 + xx] == 'x')
|
||||
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
|
||||
if (numbermap[sy][40 + xx] == '.')
|
||||
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,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
|
||||
@ -194,20 +194,18 @@ int main (int argc, char *argv[])
|
||||
|
||||
//Request foreground color from config file
|
||||
fp = popen("./result/bin/quest-log foreground", "r");
|
||||
if (fgets(path, sizeof(path), fp)) {
|
||||
if (strcmp(path, "DATA NOT PRESENT"))
|
||||
processColorString(&f, path);
|
||||
printf("\033[38;2;%d;%d;%dm", f.r, f.g, f.b);
|
||||
}
|
||||
fgets(path, sizeof(path), fp);
|
||||
if (strcmp(path, "DATA NOT PRESENT"))
|
||||
processColorString(&f, path);
|
||||
printf("\033[38;2;%d;%d;%dm", f.r, f.g, f.b);
|
||||
pclose(fp);
|
||||
|
||||
//Request background color from config file
|
||||
fp = popen("./result/bin/quest-log background", "r");
|
||||
if (fgets(path, sizeof(path), fp)) {
|
||||
if (strcmp(path, "DATA NOT PRESENT"))
|
||||
processColorString(&b, path);
|
||||
printf("\033[48;2;%d;%d;%dm", b.r, b.g, b.b);
|
||||
}
|
||||
fgets(path, sizeof(path), fp);
|
||||
if (strcmp(path, "DATA NOT PRESENT"))
|
||||
processColorString(&b, path);
|
||||
printf("\033[48;2;%d;%d;%dm", b.r, b.g, b.b);
|
||||
pclose(fp);
|
||||
|
||||
//Set fps from command line argument
|
||||
|
Loading…
x
Reference in New Issue
Block a user