summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-03-04 00:51:18 +0100
committeraura <nw@moneybot.cc>2026-03-04 00:51:18 +0100
commit890bea19359649695df1b618a41ce580cf3dfbda (patch)
tree8bc10ae4e613b0ad57fae9a68cec38c7d59cf067 /src/game.cpp
parent61aea7311c2e1af78fd9da544499f2198f2da1dd (diff)
parentbe91342733fd56d1e7bafe72e82a8ac4dc67b79d (diff)
Merge branch 'ui-rework'
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 663681f..2179255 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -18,6 +18,7 @@
#include "render/gl_batch.h"
#include "util.h"
+static void game_realtime_resize_repaint( void* userdata );
GAME_DATA* game_init( GL_DATA* gl ) {
GAME_DATA* game = (GAME_DATA*)malloc( sizeof( GAME_DATA ) );
@@ -45,6 +46,8 @@ GAME_DATA* game_init( GL_DATA* gl ) {
game->state.ingame = 1;
#endif
+ gl_set_resize_repaint_callback( gl, game_realtime_resize_repaint, game );
+
return game;
}
@@ -52,7 +55,7 @@ void game_create_batches( GAME_DATA *game ) {
game->render.batch_3d = gl_batch_create( game->gl, game->shaders.gl3d, &gl_3d_batch_setup );
}
-#ifdef DEBUG
+#if defined(DEBUG) && !IS_EDITOR
void game_draw_fpsoverlay( GAME_DATA* game ) {
GL_DATA* gl = game->gl;
char buf[256];
@@ -116,14 +119,65 @@ void game_draw( GAME_DATA* game ) {
world_draw( game, objl->world, window, winsize );
}
+static void game_realtime_resize_repaint( void* userdata ) {
+ GAME_DATA* game = (GAME_DATA*)userdata;
+ if( !game || !game->gl )
+ return;
+
+ GL_DATA* gl = game->gl;
+ GL_SHADER_PROGRAM* gl2d = game->shaders.gl2d;
+
+ if( !assets_on_frame( game ) )
+ return;
+
+ gl_sync_window_size( gl );
+
+#if IS_EDITOR
+ if( game->editor && game->editor->wnd ) {
+ if( game->editor->wnd->w != gl->canvas_size[0]
+ || game->editor->wnd->h != gl->canvas_size[1] ) {
+ editor_resize( game->editor, gl->canvas_size[0], gl->canvas_size[1] );
+ }
+ }
+#endif
+
+ gl_beginframe( gl );
+ gl_2d_frect( gl2d, s_tl(), s_br(), { 0.f, 0.f, 0.f, 1.f } );
+
+ if( game->state.ingame )
+ game_draw( game );
+
+ gui_draw( game );
+
+#if defined(DEBUG) && !IS_EDITOR
+ game_draw_fpsoverlay( game );
+#endif
+
+ SDL_GL_SwapWindow( gl->window );
+}
+
void game_main_loop( GAME_DATA* game ) {
GL_DATA* gl = game->gl;
GL_SHADER_PROGRAM* gl2d = game->shaders.gl2d;
+ if( !OK( gl_poll_events( gl ) ) )
+ exit( 0 );
+
if( !assets_on_frame( game ) )
return;
+ gl_sync_window_size( gl );
gl_beginframe( gl );
+
+#if IS_EDITOR
+ if( game->editor && game->editor->wnd ) {
+ if( game->editor->wnd->w != gl->canvas_size[0]
+ || game->editor->wnd->h != gl->canvas_size[1] ) {
+ editor_resize( game->editor, gl->canvas_size[0], gl->canvas_size[1] );
+ }
+ }
+#endif
+
gl_2d_frect( gl2d, s_tl(), s_br(), { 0.f, 0.f, 0.f, 1.f } );
player_input( game, objl->pl );
@@ -134,7 +188,7 @@ void game_main_loop( GAME_DATA* game ) {
gui_onframe( game );
-#ifdef DEBUG
+#if defined(DEBUG) && !IS_EDITOR
game_draw_fpsoverlay( game );
#endif