diff options
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/game.cpp b/src/game.cpp index b356917..a0452db 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,3 +1,4 @@ +#include <stdint.h> #include <unistd.h> #include "game.h" @@ -17,6 +18,8 @@ #include "gui.h" #include "render/gl_batch.h" #include "util.h" +#include "util/profiler.h" +#include "util/time.h" CVAR* g_timescale = var_new( "g_timescale", 1.f ); @@ -27,10 +30,11 @@ GAME_DATA* game_init( GL_DATA* gl ) { memset( game, 0, sizeof(GAME_DATA) ); game->gl = gl; + profiler_init(); + VEC2 screensize = { (F32)gl->canvas_size[0], (F32)gl->canvas_size[1] }; game->shaders.gl2d = gl_2d_init( gl, screensize, "2d" ); - game->shaders.gl2d_texcoord = gl_2d_init( gl, screensize, "2d_texcoord" ); game->shaders.gl3d = gl_3d_init( gl, screensize, "3d" ); game_create_batches( game ); @@ -121,7 +125,7 @@ void game_draw( GAME_DATA* game ) { world_draw( game, objl->world, window, winsize ); } -static void game_realtime_resize_repaint( void* userdata ) { +void game_realtime_resize_repaint( void* userdata ) { GAME_DATA* game = (GAME_DATA*)userdata; if( !game || !game->gl ) return; @@ -158,15 +162,15 @@ static void game_realtime_resize_repaint( void* userdata ) { SDL_GL_SwapWindow( gl->window ); } -void game_main_loop( GAME_DATA* game ) { +U8 game_main_loop( GAME_DATA* game ) { _profiled GL_DATA* gl = game->gl; GL_SHADER_PROGRAM* gl2d = game->shaders.gl2d; if( !OK( gl_poll_events( gl ) ) ) - exit( 0 ); + return 1; if( !assets_on_frame( game ) ) - return; + return 0; gl_sync_window_size( gl ); gl_beginframe( gl ); @@ -189,18 +193,29 @@ void game_main_loop( GAME_DATA* game ) { } gui_onframe( game ); + profiler_draw_tree( game->assets.jpn12 ); + #if defined(DEBUG) && !IS_EDITOR game_draw_fpsoverlay( game ); #endif if( !OK( gl_endframe( gl ) ) ) - exit( 0 ); + return 1; + + return 0; } -void game_on_tick( GAME_DATA* game ) { +void game_on_tick( GAME_DATA* game ) { _profiled U64 tick = u_tick(); - if( tick - game->state.last_tick > (U64)(TICK_INTERVAL * 10000) * (1.f / var_getf( g_timescale )) ) { + U64 ticks = TICK_INTERVAL * TICK_RESOLUTION; + F32 ts = var_getf( g_timescale ); + if( ts != 1.f && ts > 0.f ) + ticks *= (1.f / ts); + else if( !ts ) + ticks = INT64_MAX; + + if( tick - game->state.last_tick > ticks ) { player_move( game, objl->pl ); game->state.last_tick = tick; } |
