summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorkasull <qsullian@gmail.com>2026-03-01 20:18:08 -0500
committerkasull <qsullian@gmail.com>2026-03-01 20:18:08 -0500
commit413ef78504278d37080b9b59a652e4bbd5e2a0fc (patch)
tree67be817cf765725dd2d08c14b2d0ce8c12b20997 /src/game.cpp
parent71dd7fcccb45a54d85ae23a95a8a8905ed21fe15 (diff)
editor ui rework
add responsive editor relayout for window resize rework header with back/save, view mode buttons, and 2d view type selector add clipped, scrollable assets and contextual tool panels simplify tool button wiring and repeated layout logic simplify 2d top-down editor internals and shared grid update hooks
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