X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg.h;h=4b8956a1989c7cd5ff7ba57d7b65712a606de78a;hb=76d234b7dc5e6500e8a54009b367e7620f11ef97;hp=f839f02e60e1848573d68c6a52df6467cd64ad36;hpb=984ae77a4c0b6b90ac2fea140d1a6a1230556ad2;p=vg.git diff --git a/vg.h b/vg.h index f839f02..4b8956a 100644 --- a/vg.h +++ b/vg.h @@ -67,7 +67,9 @@ #include "vg_m.h" #include "vg_io.h" #include "vg_log.h" +#ifndef VG_NO_STEAM #include "vg_steam.h" +#endif //#define VG_SYNC_DEBUG #ifdef VG_SYNC_DEBUG @@ -78,23 +80,23 @@ #endif /* API */ -VG_STATIC void vg_enter( int argc, char *argv[], const char *window_name ); +static void vg_enter( int argc, char *argv[], const char *window_name ); /* Thread 1 */ -VG_STATIC void vg_preload(void); -VG_STATIC void vg_load(void); +static void vg_preload(void); +static void vg_load(void); /* Main thread */ -VG_STATIC void vg_launch_opt(void); -VG_STATIC void vg_start(void); +static void vg_launch_opt(void); +static void vg_start(void); -VG_STATIC void vg_framebuffer_resize(int w, int h); -VG_STATIC void vg_pre_update(void); -VG_STATIC void vg_fixed_update(void); -VG_STATIC void vg_post_update(void); +static void vg_framebuffer_resize(int w, int h); +static void vg_pre_update(void); +static void vg_fixed_update(void); +static void vg_post_update(void); -VG_STATIC void vg_render(void); -VG_STATIC void vg_gui(void); +static void vg_render(void); +static void vg_gui(void); struct vg{ /* Engine sync */ @@ -141,6 +143,7 @@ struct vg{ /* Runtime */ double time, + time_real, time_delta, time_rate, @@ -171,7 +174,7 @@ struct vg{ float loader_ring; } -VG_STATIC vg = { .time_rate = 1.0 }; +static vg = { .time_rate = 1.0 }; const char *vg_get_basepath(void){ return vg.base_path; } @@ -185,7 +188,7 @@ enum vg_thread_purpose #include "vg_async.h" -VG_STATIC enum engine_status _vg_engine_status(void) +static enum engine_status _vg_engine_status(void) { SDL_AtomicLock( &vg.sl_status ); enum engine_status status = vg.engine_status; @@ -194,7 +197,7 @@ VG_STATIC enum engine_status _vg_engine_status(void) return status; } -VG_STATIC enum vg_thread_purpose vg_thread_purpose(void) +static enum vg_thread_purpose vg_thread_purpose(void) { SDL_AtomicLock( &vg.sl_status ); @@ -208,7 +211,7 @@ VG_STATIC enum vg_thread_purpose vg_thread_purpose(void) } } -VG_STATIC void vg_assert_thread( enum vg_thread_purpose required ){ +static void vg_assert_thread( enum vg_thread_purpose required ){ enum vg_thread_purpose purpose = vg_thread_purpose(); if( purpose != required ){ @@ -216,18 +219,20 @@ VG_STATIC void vg_assert_thread( enum vg_thread_purpose required ){ } } -VG_STATIC void _vg_opengl_sync_init(void) +static void _vg_opengl_sync_init(void) { vg.sem_loader = SDL_CreateSemaphore(1); } -VG_STATIC void vg_checkgl( const char *src_info ); +static void vg_checkgl( const char *src_info ); #define VG_STRINGIT( X ) #X #define VG_CHECK_GL_ERR() vg_checkgl( __FILE__ ":L" VG_STRINGIT(__LINE__) ) #include "vg_console.h" #include "vg_profiler.h" -#include "vg_audio.h" +#ifndef VG_NO_AUDIO + #include "vg_audio.h" +#endif #include "vg_shader.h" #include "vg_tex.h" #include "vg_input.h" @@ -237,11 +242,11 @@ VG_STATIC void vg_checkgl( const char *src_info ); #include "vg_opt.h" /* Diagnostic */ -VG_STATIC struct vg_profile vg_prof_update = {.name="update()"}, +static struct vg_profile vg_prof_update = {.name="update()"}, vg_prof_render = {.name="render()"}, vg_prof_swap = {.name="swap"}; -VG_STATIC void vg_checkgl( const char *src_info ) +static void vg_checkgl( const char *src_info ) { int fail = 0; @@ -255,12 +260,12 @@ VG_STATIC void vg_checkgl( const char *src_info ) vg_fatal_error( "OpenGL Error" ); } -VG_STATIC void async_vg_bake_shaders( void *payload, u32 size ) +static void async_vg_bake_shaders( void *payload, u32 size ) { vg_shaders_compile(); } -VG_STATIC void vg_bake_shaders(void) +static void vg_bake_shaders(void) { vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile, NULL ); vg_async_call( async_vg_bake_shaders, NULL, 0 ); @@ -282,14 +287,16 @@ void async_internal_complete( void *payload, u32 size ) SDL_AtomicUnlock( &vg.sl_status ); } -VG_STATIC void _vg_load_full( void *data ) +static void _vg_load_full( void *data ) { vg_preload(); /* internal */ vg_loader_step( vg_input_init, vg_input_free ); vg_loader_step( vg_lines_init, NULL ); +#ifndef VG_NO_AUDIO vg_loader_step( vg_audio_init, vg_audio_free ); +#endif vg_loader_step( vg_profiler_init, NULL ); vg_async_call( async_internal_complete, NULL, 0 ); @@ -298,7 +305,7 @@ VG_STATIC void _vg_load_full( void *data ) vg_load(); } -VG_STATIC void _vg_process_events(void) +static void _vg_process_events(void) { v2_zero( vg.mouse_wheel ); v2_zero( vg.mouse_delta ); @@ -386,7 +393,7 @@ VG_STATIC void _vg_process_events(void) vg.mouse_pos[1] += vg.mouse_delta[1]; } -VG_STATIC void _vg_gameloop_update(void) +static void _vg_gameloop_update(void) { vg_profile_begin( &vg_prof_update ); @@ -418,7 +425,7 @@ VG_STATIC void _vg_gameloop_update(void) vg_profile_end( &vg_prof_update ); } -VG_STATIC void _vg_gameloop_render(void) +static void _vg_gameloop_render(void) { vg_profile_begin( &vg_prof_render ); @@ -440,7 +447,9 @@ VG_STATIC void _vg_gameloop_render(void) else vg_gui(); /* vg tools */ +#ifndef VG_NO_AUDIO audio_debug_ui( vg.pv ); +#endif /* profiling */ int frame_target = vg.display_refresh_rate; @@ -466,7 +475,7 @@ VG_STATIC void _vg_gameloop_render(void) vg.samples, vg.fixed_iterations, (vg.time_fixed_accumulator/VG_TIMESTEP_FIXED)*100.0f, - vg.time, vg.time_delta, vg.time_rate, + vg.time_real, vg.time_delta, vg.time_rate, vg.time_fixed_extrapolate, vg.time_frame_delta, vg.time_spinning ); @@ -478,7 +487,7 @@ VG_STATIC void _vg_gameloop_render(void) vg_profile_end( &vg_prof_render ); } -VG_STATIC int vg_framefilter( double dt ) +static int vg_framefilter( double dt ) { if( (vg.fps_limit <= 0) && (vg.vsync_feature != k_vsync_feature_error) ){ /* turn on vsync if not enabled */ @@ -544,7 +553,7 @@ VG_STATIC int vg_framefilter( double dt ) return 0; } -VG_STATIC int _vg_crashscreen(void) +static int _vg_crashscreen(void) { #if 0 if( vg_getkey( SDLK_ESCAPE ) ) @@ -557,7 +566,7 @@ VG_STATIC int _vg_crashscreen(void) glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); glBlendEquation(GL_FUNC_ADD); - glClearColor( 0.15f + sinf(vg.time)*0.1f, 0.0f, 0.0f,1.0f ); + glClearColor( 0.15f + sinf(vg.time_real)*0.1f, 0.0f, 0.0f,1.0f ); glClear( GL_COLOR_BUFFER_BIT ); glViewport( 0,0, vg.window_x, vg.window_y ); @@ -566,7 +575,7 @@ VG_STATIC int _vg_crashscreen(void) return 0; } -VG_STATIC void _vg_gameloop(void){ +static void _vg_gameloop(void){ //vg.time_fixed_accumulator = 0.75f * (1.0f/60.0f); vg.time_hp = SDL_GetPerformanceCounter(); @@ -592,6 +601,7 @@ VG_STATIC void _vg_gameloop(void){ enum engine_status status = _vg_engine_status(); + vg.time_real += vg.time_frame_delta; vg.time_delta = vg.time_frame_delta * vg.time_rate; vg.time += vg.time_delta; @@ -625,7 +635,7 @@ VG_STATIC void _vg_gameloop(void){ } } -VG_STATIC void _vg_process_launch_opts_internal( int argc, char *argv[] ) +static void _vg_process_launch_opts_internal( int argc, char *argv[] ) { char *arg; while( vg_argp( argc, argv ) ){ @@ -653,7 +663,7 @@ VG_STATIC void _vg_process_launch_opts_internal( int argc, char *argv[] ) } } -VG_STATIC void _vg_init_window( const char *window_name ) +static void _vg_init_window( const char *window_name ) { vg_info( "SDL_INIT\n" ); @@ -662,7 +672,9 @@ VG_STATIC void _vg_init_window( const char *window_name ) exit(0); } +#ifndef VG_NO_AUDIO SDL_InitSubSystem( SDL_INIT_AUDIO ); +#endif SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER ); char *exe_basepath = SDL_GetBasePath(); @@ -804,7 +816,7 @@ VG_STATIC void _vg_init_window( const char *window_name ) #endif } -VG_STATIC void _vg_terminate(void) +static void _vg_terminate(void) { /* Shutdown */ _vg_console_write_persistent(); @@ -822,7 +834,7 @@ VG_STATIC void _vg_terminate(void) exit(0); } -VG_STATIC void vg_enter( int argc, char *argv[], const char *window_name ) +static void vg_enter( int argc, char *argv[], const char *window_name ) { vg_rand_seed( 461 ); _vg_process_launch_opts_internal( argc, argv ); @@ -851,7 +863,7 @@ VG_STATIC void vg_enter( int argc, char *argv[], const char *window_name ) _vg_terminate(); } -VG_STATIC void vg_fatal_error( const char *fmt, ... ) +static void vg_fatal_error( const char *fmt, ... ) { va_list args; va_start( args, fmt ); @@ -876,7 +888,7 @@ VG_STATIC void vg_fatal_error( const char *fmt, ... ) #else /* VG_GAME */ #include "vg_log.h" -VG_STATIC void vg_fatal_error( const char *fmt, ... ) +static void vg_fatal_error( const char *fmt, ... ) { va_list args; va_start( args, fmt );