trying to read commands from std while displaying things, fixes
This commit is contained in:
parent
a32e44f45f
commit
dc791e3481
5 changed files with 43 additions and 9 deletions
35
glonkers.c
35
glonkers.c
|
|
@ -1,10 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-util.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <pthread.h>
|
||||
#include "renderer.h"
|
||||
|
||||
//int main() {
|
||||
|
|
@ -79,7 +81,34 @@ double time_since_start() {
|
|||
(now.tv_nsec - program_start.tv_nsec) / 1e9;
|
||||
}
|
||||
|
||||
_Atomic bool running = true;
|
||||
|
||||
void intHandler(int dummy) {
|
||||
printf("exiting\n");
|
||||
running = false;
|
||||
fclose(stdin);
|
||||
}
|
||||
|
||||
bool reload_shader = false;
|
||||
|
||||
/// reads stdin on a separate thread.
|
||||
void *read_stdin(void *ptr) {
|
||||
char buff[10];
|
||||
while (running) {
|
||||
fgets(buff, 10, stdin);
|
||||
if (strcmp(buff, "r\n") == 0) {
|
||||
printf("reloading shader\n");
|
||||
reload_shader = true;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
signal(SIGINT, intHandler);
|
||||
pthread_t stdin_thread;
|
||||
pthread_create( &stdin_thread, NULL, read_stdin, NULL);
|
||||
|
||||
init_timer();
|
||||
|
||||
printf("Good Morning 🍵\n");
|
||||
|
|
@ -109,7 +138,6 @@ int main(int argc, char *argv[]) {
|
|||
Renderer renderer = new_renderer();
|
||||
|
||||
SDL_Event e;
|
||||
int running = 1;
|
||||
int w, h;
|
||||
while (running) {
|
||||
while (SDL_PollEvent(&e)) {
|
||||
|
|
@ -128,9 +156,12 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
double time = time_since_start();
|
||||
render(&renderer, w, h, time, shader_path);
|
||||
render(&renderer, w, h, time, shader_path, reload_shader);
|
||||
if (reload_shader) reload_shader = false;
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
pthread_join(stdin_thread, NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue