From 2973df584978d9aae6f164ce0204179c8a28b3ae Mon Sep 17 00:00:00 2001 From: 2lag <96544487+2lag@users.noreply.github.com> Date: Sat, 8 Aug 2026 17:33:36 +0200 Subject: console, textbox changes, some other shit --- src/game.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 7b526ae..a9cffec 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3,6 +3,7 @@ #include "game.h" #include "SDL_keycode.h" +#include "SDL_mouse.h" #include "game/physics/movement.h" #include "game/world/bsp.h" #include "game/world/draw.h" @@ -17,24 +18,30 @@ #include "game/world/map.h" #include "gui.h" +#include "gui/base.h" #include "render/gl_batch.h" #include "util.h" +#include "util/console.h" #include "util/input.h" #include "util/profiler.h" #include "util/time.h" -CVAR* g_timescale = var_new( "g_timescale", 1.f ); +CVAR* g_timescale = var_new( "g_timescale", "game timescale", 1.f ); +I32 game_quit( CVAR* self, LIST cmdline ); +CVAR* g_quit = var_new( "quit", "quit the game", &game_quit ); +U8 quit = 0; static void game_realtime_resize_repaint( void* userdata ); GAME_DATA* game_init( GL_DATA* gl ) { - GAME_DATA* game = (GAME_DATA*)malloc( sizeof( GAME_DATA ) ); - memset( game, 0, sizeof(GAME_DATA) ); + GAME_DATA* game = new GAME_DATA{}; game->gl = gl; + console_capture_stdout_begin( &game->console ); + profiler_init(); - VEC2 screensize = { (F32)gl->canvas_size[0], (F32)gl->canvas_size[1] }; + VEC2 screensize = { gl->canvas_size[0], gl->canvas_size[1] }; game->shaders.gl2d = gl_2d_init( gl, screensize, "2d" ); game->shaders.gl3d = gl_3d_init( gl, screensize, "3d" ); @@ -172,6 +179,8 @@ U8 game_main_loop( GAME_DATA* game ) { _profiled if( !OK( gl_poll_events( gl ) ) ) return 1; + console_pump_stdout( &game->console ); + if( !assets_on_frame( game ) ) return 0; @@ -205,7 +214,7 @@ U8 game_main_loop( GAME_DATA* game ) { _profiled if( !OK( gl_endframe( gl ) ) ) return 1; - return input_is_key_down( SDLK_ESCAPE ); + return quit; } void game_on_tick( GAME_DATA* game ) { _profiled @@ -224,14 +233,30 @@ void game_on_tick( GAME_DATA* game ) { _profiled } void game_destroy( GAME_DATA *game ) { + if( !game ) + return; + + console_capture_stdout_end( &game->console ); + gui_shutdown(); + game->console_window = 0; #if IS_EDITOR - editor_destroy( game->editor ); + if( game->editor ) { + editor_destroy( game->editor ); + game->editor = 0; + } #endif if( game->state.map ) map_free( game, game->state.map ); + assets_destroy( game ); gl_batch_destroy( game->render.batch_2d ); gl_batch_destroy( game->render.batch_3d ); gl_destroy( game->gl ); - free( game ); + game->gl = 0; + delete game; +} + +I32 game_quit( CVAR* self, LIST cmdline ) { + quit = 1; + return 1; } -- cgit v1.2.3