diff options
| author | aura <nw@moneybot.cc> | 2026-08-11 19:10:16 +0200 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-08-11 19:10:16 +0200 |
| commit | 17c07b5f884453130d8be3a6d91d730d80d4f8ae (patch) | |
| tree | 6ec11e5e5f7f0be9ed899196c2897aa76a907de2 /src/game.cpp | |
| parent | 1aa17de9188790f049c0edc4281597cb4e535627 (diff) | |
| parent | 0a9d7ce6a0764a87766ebb23cc1ece4c26c8c678 (diff) | |
Merge remote-tracking branch 'origin/day'
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
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<STR> 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<STR> cmdline ) { + quit = 1; + return 1; } |
