Skip to content

Commit

Permalink
Move SIGINT handling out of SDL ui.c
Browse files Browse the repository at this point in the history
It's now living in renderer.c for the time being. That file is super
ugly too, though, so I'll have to do something about that. At least
sigint handling isn't coupled to SDL glue code for no reason anymore :^)
  • Loading branch information
vkoskiv committed Oct 28, 2023
1 parent 3430f13 commit 3f2fb22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
20 changes: 20 additions & 0 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@
#define paused_msec 100
#define active_msec 16

static bool g_aborted = false;

void sigHandler(int sig) {
if (sig == 2) { //SIGINT
logr(plain, "\n");
logr(info, "Received ^C, aborting render without saving\n");
g_aborted = true;
}
}


void *renderThread(void *arg);
void *renderThreadInteractive(void *arg);

/// @todo Use defaultSettings state struct for this.
/// @todo Clean this up, it's ugly.
struct texture *renderFrame(struct renderer *r) {
//Check for CTRL-C
if (registerHandler(sigint, sigHandler)) {
logr(warning, "Unable to catch SIGINT\n");
}
struct camera camera = r->scene->cameras[r->prefs.selected_camera];
struct texture *output = newTexture(char_p, camera.width, camera.height, 3);

Expand Down Expand Up @@ -124,6 +139,11 @@ struct texture *renderFrame(struct renderer *r) {
//where a worker node disconnects during a render, so maybe fix that next.
while (r->state.isRendering) {
getKeyboardInput(r);

if (g_aborted) {
r->state.saveImage = false;
r->state.renderAborted = true;
}

//Gather and maintain this average constantly.
if (!r->state.threadStates[0].paused) {
Expand Down
26 changes: 0 additions & 26 deletions src/utils/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ struct window {
unsigned height;
};

// FIXME: Move the sig handling elsewhere, no reason for it to be tied to this SDL stuff
static bool g_aborted = false;

//FIXME: This won't work on linux, it'll just abort the execution.
//Take a look at the docs for sigaction() and implement that.
void sigHandler(int sig) {
if (sig == 2) { //SIGINT
logr(plain, "\n");
logr(info, "Received ^C, aborting render without saving\n");
g_aborted = true;
}
}

#ifdef CRAY_SDL_ENABLED

static void setWindowIcon(SDL_Window *window) {
Expand Down Expand Up @@ -197,18 +184,6 @@ void printDuration(uint64_t ms) {
}

void getKeyboardInput(struct renderer *r) {
if (g_aborted) {
r->state.saveImage = false;
r->state.renderAborted = true;
}
static bool sigRegistered = false;
//Check for CTRL-C
if (!sigRegistered) {
if (registerHandler(sigint, sigHandler)) {
logr(warning, "Unable to catch SIGINT\n");
}
sigRegistered = true;
}
#ifdef CRAY_SDL_ENABLED
SDL_Event event;
while (SDL_PollEvent(&event)) {
Expand Down Expand Up @@ -327,7 +302,6 @@ static void updateFrames(struct renderer *r) {
#endif

void win_update(struct window *w, struct renderer *r, struct texture *t) {
if (g_aborted) r->state.renderAborted = true;
#ifdef CRAY_SDL_ENABLED
if (!w) return;
//Render frames
Expand Down

0 comments on commit 3f2fb22

Please sign in to comment.