splitting

main
sandyx 1 year ago
parent 5ade49b72f
commit 224e4b17d0

@ -9,7 +9,7 @@ BUILD=build
C_FILES := $(shell find $(SRC) -name '*.c') C_FILES := $(shell find $(SRC) -name '*.c')
O_FILES += $(patsubst $(SRC)/%.c, $(BUILD)/%.o, $(C_FILES)) O_FILES += $(patsubst $(SRC)/%.c, $(BUILD)/%.o, $(C_FILES))
CFLAGS := -O0 -march=native CFLAGS := -O0 -march=native -std=gnu99
INCLUDE := INCLUDE :=
LIB := -lraylib LIB := -lraylib

@ -0,0 +1,13 @@
#version 330 core
uniform vec3 color1;
uniform vec3 color2;
void main() {
vec2 st = gl_PointCoord;
float mixval = distance(st, vec2(0, 1));
vec3 color = mix(color1, color2, mixval);
gl_FragColor = vec4(color, 0.5);
}

@ -0,0 +1,6 @@
#version 330 core
layout (location = 0) in vec3 aPos;
void main() {
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}

@ -10,20 +10,30 @@ void ctrl_pause(GHTimer *timer) {
} }
} }
void ctrl_start(GHTimer *timer) { void ctrl_start(ctrl_binder *cb) {
if (timer->running) {
if (splits != NULL) { if (cb->timer_rta->running) {
//splits_next(); if (cb->rec_sl != NULL) {
cb->live_sl->list[cb->current_segment]->realtime = ghtimer_time(cb->timer_rta);
cb->current_segment++;
} else { } else {
ghtimer_stop(timer); //stop or reset, save splits ghtimer_stop(cb->timer_rta); //stop or reset, save splits
} }
//pause timer if last split //pause timer if last split
if (splits == NULL) { if (false) {
ghtimer_pause(timer); ghtimer_pause(cb->timer_rta);
return; return;
} }
} else { } else {
ghtimer_start(timer); ghtimer_start(cb->timer_rta);
} }
} }
ctrl_binder *create_ctrl_binder(GHTimer *rta, segment_list *sl) {
ctrl_binder *binder = calloc(1, sizeof(ctrl_binder));
binder->timer_rta = rta;
binder->rec_sl = sl;
binder->live_sl = sl;
return binder;
}

@ -2,10 +2,19 @@
#define CTRL_H #define CTRL_H
#include "timer.h" #include "timer.h"
#include "splits.h"
#include <stdlib.h>
//controller binds the timer to the splits //controller binds the timer to the splits
//and to the input handler //and to the input handler
//and to the autosplitter //and to the autosplitter
void ctrl_start(GHTimer *timer); typedef struct ctrl_binder {
GHTimer *timer_rta, *timer_igt;
segment_list *rec_sl, *live_sl;
int current_segment;
} ctrl_binder;
ctrl_binder *create_ctrl_binder(GHTimer *rta, segment_list *sl);
void ctrl_start(ctrl_binder *cb);
void ctrl_pause(GHTimer *timer); void ctrl_pause(GHTimer *timer);
#endif #endif

@ -1,10 +1,21 @@
#include <raylib.h> #include <raylib.h>
#include "timer.h" #include "timer.h"
#include "timer_renderer.h"
#include "segment_renderer.h"
#include "controller.h" #include "controller.h"
//#include "scanner.h" //#include "scanner.h"
#include "splits.h" #include "splits.h"
#include <stdio.h> #include <stdio.h>
#if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330
#else
#define GLSL_VERSION 100
#endif
int windowWidth = 420;
int windowHeight = 640;
GHTimer timer = {0}; GHTimer timer = {0};
char timer_string[50]; char timer_string[50];
@ -24,34 +35,39 @@ void control(void) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
InitWindow(420, 640, "Ghost"); //size of window can be determined by height of all components visible
InitWindow(windowWidth, windowHeight, "Ghost");
SetTargetFPS(60); SetTargetFPS(60);
segment_list segments = open_splits_file("test/splits.ghs"); segment_list segments = open_splits_file("test/splits.ghs");
printf("%d\n" , segments.cnt);
timer_renderer *tr = create_timer_renderer(&timer, 500.0f, 40.0f);
segment_renderer *sr = create_segment_renderer(&segments, 0.0f, 0.0f);
ctrl_binder *cb = create_ctrl_binder(&timer, &segments);
ghtimer_start(&timer); //ghtimer_start(&timer);
//set_control_func(control);
//set_pid(17329); font = LoadFontEx("/usr/share/fonts/CozetteVector.ttf", 400, 0, 0);
GenTextureMipmaps(&font.texture);
font = LoadFontEx("/usr/share/fonts/CozetteVector.ttf", 400, 0, NULL); float fontSize = (float)font.baseSize;
printf("%s\n", "yes");
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
ghtimer_tick(&timer); ghtimer_tick(&timer);
ghtimer_timestring(&timer, timer_string);
if (IsKeyPressed(KEY_P)) { if (IsKeyPressed(KEY_P)) {
ctrl_pause(&timer); printf("p\n");
ctrl_start(cb);
} }
//remote_state = watch_memory((void *)0x7ffc517105f4, 0); ClearBackground(RAYWHITE);
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); render_timer(tr);
DrawTextEx(font, timer_string , (Vector2){200.0f, 550.0f}, (float)font.baseSize / 4, 2, BLACK); render_segments(sr);
render_splits(&segments);
EndDrawing(); EndDrawing();
} }
CloseWindow();
} }

@ -0,0 +1,51 @@
#ifndef SEGMENT_RENDERER_H
#define SEGMENT_RENDERER_H
#include <raylib.h>
#include <stdlib.h>
#include "timer.h"
#include "splits.h"
#define FMT_SIZE 64
extern Font font;
//need to implement scrolling when total_splits > visible
typedef struct segment_renderer {
float pos;
float height;
segment_list *seglist;
int count;
int current;
char strfmt[FMT_SIZE];
} segment_renderer;
segment_renderer *create_segment_renderer(segment_list *sl, float y, float h) {
segment_renderer *sr = calloc(1, sizeof(segment_renderer));
sr->pos = y;
sr->height = h;
sr->seglist = sl;
sr->count = sl->cnt;
return sr;
}
void set_segment_count(segment_renderer *sr, int c) {
sr->count = c;
}
inline void destroy_segment_renderer(segment_renderer *sr) {
free(sr);
}
void render_segments(segment_renderer *sr) {
for (int i = 0; i < sr->count; i++) {
DrawTextEx(font, sr->seglist->list[i]->name, (Vector2){10, 30 * i}, (float)font.baseSize/16, 2, BLACK);
//if (sr->current < i) {
//DrawTextEx(font, time_unparse(sr->strfmt, FMT_SIZE, &sr->seglist->list[i]->realtime), (Vector2){200, 30 * i}, (float)font.baseSize/16, 2, BLACK);
//}
DrawTextEx(font, time_unparse(sr->strfmt, FMT_SIZE, &sr->seglist->list[i]->realtime), (Vector2){200, 30 * i}, (float)font.baseSize/16, 2, BLACK);
}
}
#endif

@ -1,6 +1,7 @@
#include "splits.h" #include "splits.h"
#include "parser.h" #include "parser.h"
#include "timer.h" #include "timer.h"
#include <math.h>
#include <raylib.h> #include <raylib.h>
extern Font font; extern Font font;
@ -31,15 +32,17 @@ struct timespec parse_time(char *str) {
char *time_unparse(char *buffer, size_t len, struct timespec *ts) { char *time_unparse(char *buffer, size_t len, struct timespec *ts) {
struct tm *t = gmtime(&ts->tv_sec); struct tm *t = gmtime(&ts->tv_sec);
if (t->tm_hour == 0) { if (t->tm_hour == 0 && t->tm_min != 0) {
strftime(buffer, len, "%M:%S.", gmtime(&ts->tv_sec)); strftime(buffer, len, "%M:%S.", gmtime(&ts->tv_sec));
} else if (t->tm_min == 0) { } else if (t->tm_hour == 0 && t->tm_min == 0) {
strftime(buffer, len, "%S.", gmtime(&ts->tv_sec)); strftime(buffer, len, "%S.", gmtime(&ts->tv_sec));
} else { } else {
strftime(buffer, len, "%T.", gmtime(&ts->tv_sec)); strftime(buffer, len, "%T.", gmtime(&ts->tv_sec));
} }
snprintf(&buffer[strlen(buffer)], len, "%.02ld", ts->tv_nsec / 10000000); double ns = timespec_to_double(*ts);
ns = ns - (long)ns;
snprintf(&buffer[strlen(buffer)], len, "%.2ld", (long)(ns*100));
return buffer; return buffer;
} }
@ -125,16 +128,16 @@ segment_list open_splits_file(const char *path) {
return segments; return segments;
} }
/*
void render_splits(segment_list *segments) { void render_splits(segment_list *segments) {
char buffer[100]; char buffer[100];
for (int i = 0; i < segments->cnt; i++) { for (int i = 0; i < segments->cnt; i++) {
DrawTextEx(font, segments->list[i]->name, (Vector2){10, 30 * i}, (float)font.baseSize/16, 2, BLACK); DrawTextEx(font, segments->list[i]->name, (Vector2){10, 30 * i}, (float)font.baseSize/16, 2, BLACK);
DrawTextEx(font, time_unparse(buffer, 100, &segments->list[i]->realtime), (Vector2){200, 30 * i}, (float)font.baseSize/16, 2, BLACK); DrawTextEx(font, time_unparse(buffer, 100, &segments->list[i]->realtime), (Vector2){200, 30 * i}, (float)font.baseSize/16, 2, BLACK);
} }
} }
*/
//probably need a thing to free all the segments //probably need a thing to free all the segments

@ -1,4 +1,5 @@
#include "timer.h" #include "timer.h"
#include <stdlib.h>
struct timespec subts(struct timespec t1, struct timespec t2) { struct timespec subts(struct timespec t1, struct timespec t2) {
return (struct timespec) { return (struct timespec) {
@ -19,14 +20,14 @@ double timespec_to_double(struct timespec ts) {
} }
GHTimer ghtimer_init(void) { GHTimer *ghtimer_init(void) {
GHTimer timer = {0}; GHTimer *timer = calloc(1, sizeof(GHTimer));
timer.running = false; timer->running = false;
timer.paused = false; timer->paused = false;
clock_gettime(CLOCK_REALTIME, &timer.pause_start); clock_gettime(CLOCK_REALTIME, &timer->pause_start);
clock_gettime(CLOCK_REALTIME, &timer.start); clock_gettime(CLOCK_REALTIME, &timer->start);
timer.pause_current = timer.pause_start; timer->pause_current = timer->pause_start;
timer.current = timer.start; timer->current = timer->start;
return timer; return timer;
} }

@ -0,0 +1,48 @@
#ifndef TIMER_RENDERER_H
#define TIMER_RENDERER_H
#include <raylib.h>
#include <stdlib.h>
#include "timer.h"
//this is just a thing to bind some extra data to the timer
//so that i dont have to put pos and height in the timer
extern Font font;
extern int windowWidth;
extern int windowHeight;
extern char *time_unparse(char *buffer, size_t len, struct timespec *ts);
#define FMT_SIZE 64
typedef struct timer_renderer {
GHTimer *timer;
//Font font;
float pos; //pos
float height; //height
char strfmt[FMT_SIZE];
} timer_renderer;
timer_renderer *create_timer_renderer(GHTimer *t, float y, float h) {
timer_renderer *tr = calloc(1, sizeof(timer_renderer));
tr->timer = t;
tr->pos = y;
tr->height = h;
return tr;
}
void set_timer_pos(timer_renderer *tr, float y) {
tr->pos = y;
}
//maybe just destroy_renderer() or just free()
inline void destroy_timer_renderer(timer_renderer *tr) {
free(tr);
}
void render_timer(timer_renderer *tr) {
struct timespec ts = ghtimer_time(tr->timer);
time_unparse(tr->strfmt, FMT_SIZE, &ts);
DrawTextEx(font, tr->strfmt , (Vector2){20.0f, tr->pos}, (float)font.baseSize / 4, 2, BLACK);
}
#endif

@ -10,13 +10,13 @@ end
segment segment
name: Segment 2 name: Segment 2
gametime: 00:02:00.57 gametime: 00:02:00.57
realtime: 00:04:00.42 realtime: 00:04:00.72
best: 00:01:00.00 best: 00:01:00.00
end end
segment segment
name: Segment 3 name: Segment 3
gametime: 00:03:00.50 gametime: 00:03:00.50
realtime: 06:06:00.00 realtime: 06:06:00.82
best: 00:01:00.00 best: 00:01:00.00
end end

Loading…
Cancel
Save