1.1 --- a/src/context.c Wed Nov 08 23:17:07 2023 +0100 1.2 +++ b/src/context.c Wed Nov 15 22:51:40 2023 +0100 1.3 @@ -81,3 +81,59 @@ 1.4 asc_context.flags = 0; 1.5 asc_dprintf("Ascension context destroyed."); 1.6 } 1.7 + 1.8 +static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { 1.9 + for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { 1.10 + if (asc_context.windows[i].id == id) { 1.11 + asc_context.windows[i].dimensions.width = width; 1.12 + asc_context.windows[i].dimensions.height = height; 1.13 + asc_mat4f_ortho(asc_context.windows[i].projection, 0, (float) width, (float) height, 0); 1.14 + return; 1.15 + } 1.16 + } 1.17 +} 1.18 + 1.19 +bool asc_loop_next(void) { 1.20 + // dispatch SDL events 1.21 + SDL_Event event; 1.22 + while (SDL_PollEvent(&event)) { 1.23 + switch (event.type) { 1.24 + case SDL_QUIT: 1.25 + asc_set_flag(&asc_context.flags, ASC_FLAG_QUIT); 1.26 + break; 1.27 + case SDL_WINDOWEVENT: { 1.28 + if (event.window.event == SDL_WINDOWEVENT_RESIZED) 1.29 + asc_event_window_resized( 1.30 + event.window.windowID, 1.31 + event.window.data1, 1.32 + event.window.data2 1.33 + ); 1.34 + break; 1.35 + } 1.36 + case SDL_KEYDOWN: 1.37 + // TODO: remove this code and implement key press map instead 1.38 + if (event.key.keysym.sym == SDLK_ESCAPE) 1.39 + return false; 1.40 + break; 1.41 + case SDL_KEYUP: 1.42 + // TODO: implement key press map 1.43 + break; 1.44 + } 1.45 + } 1.46 + 1.47 + // sync the windows 1.48 + for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { 1.49 + if (asc_context.windows[i].id > 0) { 1.50 + asc_window_sync(&asc_context.windows[i]); 1.51 + } 1.52 + } 1.53 + 1.54 + // compute frame time 1.55 + static Uint32 ticks; 1.56 + Uint32 ticks_elapsed = SDL_GetTicks() - ticks; 1.57 + ticks = SDL_GetTicks(); 1.58 + asc_context.elapsed_millis = ticks_elapsed; 1.59 + asc_context.elapsed = (float) ticks_elapsed / 1000.0f; 1.60 + 1.61 + return !asc_test_flag(asc_context.flags, ASC_FLAG_QUIT); 1.62 +}