From: hgn Date: Thu, 3 Jul 2025 00:57:14 +0000 (+0100) Subject: Correctness- Single use func(audio mixer), console registration order, some stray... X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=7409d097f31d098c583ef8ecc8caee4cedb9e16a;p=vg.git Correctness- Single use func(audio mixer), console registration order, some stray instructions, try to satisfy API requirements --- diff --git a/vg_audio.c b/vg_audio.c index 69000b0..4fec43b 100644 --- a/vg_audio.c +++ b/vg_audio.c @@ -223,70 +223,6 @@ static struct audio_lfo_state *get_audio_lfo_state( audio_channel_id lfo_id ) return &_vg_audio.lfos[ lfo_id-1 ].state; } -static void audio_channel_wake( audio_channel_id id ) -{ - audio_channel *channel = get_audio_channel( id ); - VG_ASSERT( channel->stage == k_channel_stage_active ); - - struct audio_channel_state *channel_state = get_audio_channel_state( id ); - VG_ASSERT( channel_state->activity == k_channel_activity_wake ); - - u32 format = channel->clip->flags & AUDIO_FLAG_FORMAT; - if( format == k_audio_format_vorbis ) - { - /* Setup vorbis decoder */ - u8 *buf = (u8*)_vg_audio.decoding_buffer, - *loc = &buf[AUDIO_DECODE_SIZE*id]; - - stb_vorbis_alloc alloc = { - .alloc_buffer = (char *)loc, - .alloc_buffer_length_in_bytes = AUDIO_DECODE_SIZE - }; - - int err; - stb_vorbis *decoder = stb_vorbis_open_memory( channel->clip->any_data, channel->clip->size, &err, &alloc ); - - if( !decoder ) - { - vg_error( "stb_vorbis_open_memory failed on '%s' (%d)\n", channel->clip->path, err ); - channel_state->activity = k_channel_activity_error; - } - else - { - channel_state->loaded_clip_length = stb_vorbis_stream_length_in_samples( decoder ); - channel_state->decoder_handle.vorbis = decoder; - channel_state->activity = k_channel_activity_playing; - } - } - else if( format == k_audio_format_bird ) - { - u8 *buf = (u8*)_vg_audio.decoding_buffer; - struct synth_bird *loc = (void *)&buf[AUDIO_DECODE_SIZE*id]; - - memcpy( loc, channel->clip->any_data, channel->clip->size ); - synth_bird_reset( loc ); - - channel_state->decoder_handle.bird = loc; - channel_state->loaded_clip_length = synth_bird_get_length_in_samples( loc ); - channel_state->activity = k_channel_activity_playing; - } - else if( format == k_audio_format_stereo ) - { - channel_state->loaded_clip_length = channel->clip->size / 2; - channel_state->activity = k_channel_activity_playing; - } - else if( format == k_audio_format_gen ) - { - channel_state->loaded_clip_length = 0xffffffff; - channel_state->activity = k_channel_activity_playing; - } - else - { - channel_state->loaded_clip_length = channel->clip->size; - channel_state->activity = k_channel_activity_playing; - } -} - static void audio_decode_uncompressed_mono( i16 *src, u32 count, f32 *dst ) { for( u32 i=0; itime ++; if( state->time >= controls->period_in_samples ) @@ -832,14 +767,10 @@ static f32 audio_lfo_get_sample( audio_channel_id lfo_id, struct audio_lfo_contr return (( 2.0f * controls->sqrt_polynomial_coefficient * t ) / /* --------------------------------------- */ - ( 1.0f + controls->polynomial_coefficient * t*t ) - - ) * (1.0f-fabsf(t)); + ( 1.0f + controls->polynomial_coefficient * t*t )) * (1.0f-fabsf(t)); } else - { return 0.0f; - } } static void audio_slew_i32( i32 *value, i32 target, i32 rate ) @@ -1056,10 +987,68 @@ static void _vg_audio_mixer( void *user, u8 *stream, int byte_count ) for( u32 i=0; iactivity == k_channel_activity_wake ) - audio_channel_wake( id ); + /* Wake up! */ + if( channel_state->activity == k_channel_activity_wake ) + { + audio_channel *channel = get_audio_channel( id ); + + u32 format = channel->clip->flags & AUDIO_FLAG_FORMAT; + if( format == k_audio_format_vorbis ) + { + /* Setup vorbis decoder */ + u8 *buf = (u8*)_vg_audio.decoding_buffer, + *loc = &buf[AUDIO_DECODE_SIZE*id]; + + stb_vorbis_alloc alloc = { + .alloc_buffer = (char *)loc, + .alloc_buffer_length_in_bytes = AUDIO_DECODE_SIZE + }; + + int err; + stb_vorbis *decoder = stb_vorbis_open_memory( channel->clip->any_data, channel->clip->size, &err, &alloc ); + + if( !decoder ) + { + vg_error( "stb_vorbis_open_memory failed on '%s' (%d)\n", channel->clip->path, err ); + channel_state->activity = k_channel_activity_error; + } + else + { + channel_state->loaded_clip_length = stb_vorbis_stream_length_in_samples( decoder ); + channel_state->decoder_handle.vorbis = decoder; + channel_state->activity = k_channel_activity_playing; + } + } + else if( format == k_audio_format_bird ) + { + u8 *buf = (u8*)_vg_audio.decoding_buffer; + struct synth_bird *loc = (void *)&buf[AUDIO_DECODE_SIZE*id]; + + memcpy( loc, channel->clip->any_data, channel->clip->size ); + synth_bird_reset( loc ); + + channel_state->decoder_handle.bird = loc; + channel_state->loaded_clip_length = synth_bird_get_length_in_samples( loc ); + channel_state->activity = k_channel_activity_playing; + } + else if( format == k_audio_format_stereo ) + { + channel_state->loaded_clip_length = channel->clip->size / 2; + channel_state->activity = k_channel_activity_playing; + } + else if( format == k_audio_format_gen ) + { + channel_state->loaded_clip_length = 0xffffffff; + channel_state->activity = k_channel_activity_playing; + } + else + { + channel_state->loaded_clip_length = channel->clip->size; + channel_state->activity = k_channel_activity_playing; + } + } } for( u32 i=0; idata ); } static int cmd_vg_audio( int argc, const char *argv[] ) { + vg_audio_lock(); if( _vg_audio.inspector_open ) { vg_error( "Only 1 audio inspector at a time.\n" ); + vg_audio_unlock(); return 0; } _vg_audio.inspector_open = 1; + vg_audio_unlock(); ui_px w = 800, h=8*18; struct vg_magi_panel *magi = _vg_magi_open( w,h, VG_MAGI_ALL ); magi->title = "Audio inspector"; @@ -1474,10 +1467,6 @@ void vg_audio_device_init(void) void vg_audio_init(void) { - _vg_audio.mutex = SDL_CreateMutex(); - if( _vg_audio.mutex == NULL ) - vg_fatal_error( "SDL2: %s\n", SDL_GetError() ); - _vg_profile_reg_set( &_vg_prof_audio ); _vg_audio.permanent_stack = vg_stack_make_substack( &vg.rtmem, VG_MB(32), "Permanent audio data" ); vg_stack_set_flags( _vg_audio.permanent_stack, VG_STACK_ALLOCATOR_METADATA ); @@ -1492,8 +1481,14 @@ void vg_audio_init(void) v3_copy( (v3f){1,0,0}, master_controls->listener_right_ear_direction ); v3_zero( master_controls->listener_velocity ); v3_zero( master_controls->listener_position ); - vg_dsp_init(); +} + +void vg_audio_begin(void) +{ + _vg_audio.mutex = SDL_CreateMutex(); + if( _vg_audio.mutex == NULL ) + vg_fatal_error( "SDL2: %s\n", SDL_GetError() ); vg_audio_device_init(); } diff --git a/vg_audio.h b/vg_audio.h index 3be329b..d7a11db 100644 --- a/vg_audio.h +++ b/vg_audio.h @@ -218,6 +218,7 @@ extern _vg_audio; void vg_audio_register(void); void vg_audio_device_init(void); +void vg_audio_begin(void); void vg_audio_init(void); void vg_audio_free(void); diff --git a/vg_build.h b/vg_build.h index 4026690..e49f3b7 100644 --- a/vg_build.h +++ b/vg_build.h @@ -21,7 +21,8 @@ struct vg_compiler_env { u32 optimization; bool debug_asan; - bool pdb; + bool thread_san; + bool no_pdb; enum platform { @@ -58,6 +59,7 @@ vg_test_env = { .optimization = 0, .debug_asan = 1, + .thread_san = 0, .platform = k_platform_linux, .arch = k_architecture_x86_64, .compiler = k_compiler_clang, @@ -67,6 +69,7 @@ vg_release_env = { .optimization = 3, .debug_asan = 0, + .thread_san = 0, .platform = k_platform_anyplatform, .arch = k_architecture_x86_64, .compiler = k_compiler_zigcc, @@ -271,10 +274,10 @@ vg_compiler_run( struct vg_project *project, } if( (env->compiler == k_compiler_clang) && env->debug_asan ) - { - vg_strcat( &cmd, " -rdynamic -fsanitize=address -fPIE " - "-fstack-protector-strong " ); - } + vg_strcat( &cmd, " -rdynamic -fsanitize=undefined -fsanitize=address -fPIE -fstack-protector-strong " ); + + if( (env->compiler == k_compiler_clang) && env->thread_san ) + vg_strcat( &cmd, " -rdynamic -fsanitize=thread -fPIE -fstack-protector-strong " ); vg_strcat( &cmd, conf->no_lto? " -fno-lto \\\n": " -flto \\\n" ); @@ -372,11 +375,9 @@ vg_compiler_run( struct vg_project *project, if( env->platform == k_platform_windows ) { - /* we currently dont want pdb pretty much ever. goodbye! */ - if( type == k_obj_type_exe ) { - if( !env->pdb ) + if( env->no_pdb ) vg_strcat( &cmd, " /pdb:/dev/null" ); vg_strcat( &cmd, " /SUBSYSTEM:windows" ); } @@ -481,9 +482,7 @@ vg_make_app( struct vg_project *proj, /* steamworks */ if( vg_conf->steam_api ) { - struct compile_result steam = - vg_compiler_run( &vg_proj, &denv, conf, "vg/vg_steam.c", - "vg_steam", k_obj_type_obj ); + struct compile_result steam = vg_compiler_run( &vg_proj, &denv, conf, "vg/vg_steam.c", "vg_steam", k_obj_type_obj ); vg_strcatf( &components, "%s ", steam.path ); if( env->platform == k_platform_linux ) diff --git a/vg_console.c b/vg_console.c index 7aa5352..9d18e84 100644 --- a/vg_console.c +++ b/vg_console.c @@ -13,6 +13,7 @@ struct vg_console vg_console; void vg_console_reg_var( const char *alias, void *ptr, enum vg_var_dtype type, u32 flags ) { #ifdef VG_ENGINE + VG_ASSERT( vg_console.registration_blocked==0 ); THREAD_1; #endif VG_ASSERT( vg_console.var_count < VG_ARRAY_LEN(vg_console.vars) ); @@ -30,7 +31,7 @@ void vg_console_reg_cmd( const char *alias, int (*function)(int argc, const char void (*poll_suggest)(int argc, const char *argv[]) ) { #ifdef VG_ENGINE - THREAD_1; + VG_ASSERT( vg_console.registration_blocked==0 ); #endif VG_ASSERT( vg_console.function_count < VG_ARRAY_LEN(vg_console.functions) ); @@ -672,6 +673,7 @@ void vg_console_init(void) #ifdef VG_ENGINE void vg_console_load_autos(void) { + vg_console.registration_blocked = 1; vg_console_exec( 2, (const char *[]){ "auto.conf", "silent" } ); } diff --git a/vg_console.h b/vg_console.h index 2c1d290..0117fb0 100644 --- a/vg_console.h +++ b/vg_console.h @@ -68,6 +68,8 @@ struct vg_console i32 enabled, cheats; bool auto_focus; #endif + + bool registration_blocked; } extern vg_console; diff --git a/vg_engine.c b/vg_engine.c index 2b17501..c7f7634 100644 --- a/vg_engine.c +++ b/vg_engine.c @@ -72,7 +72,6 @@ struct vg_profile_set static _vg_prof_gameloop = void vg_bake_shaders(void) { - vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile, NULL ); vg_async_call( &vg.main_tasks, vg_shaders_compile, NULL ); } @@ -109,7 +108,6 @@ static void vg_load_co( vg_coroutine *co ) if( co_step( co, 1 ) ) { /* internal */ - vg_loader_step( vg_framebuffer_init, NULL ); vg_loader_step( vg_render_init, NULL ); vg_loader_step( vg_input_init, vg_input_free ); vg_loader_step( vg_lines_init, NULL ); @@ -119,18 +117,18 @@ static void vg_load_co( vg_coroutine *co ) #ifndef VG_NO_AUDIO vg_loader_step( vg_audio_init, vg_audio_free ); #endif - vg_loader_step( vg_profiler_init, NULL ); - vg_loader_step( vg_mem_view_init, NULL ); /* client */ #ifdef VG_CUSTOM_SHADERS vg_auto_shader_register(); #endif - //vg_success( "Client loaded in %fs\n", vg.time_real ); } if( co_step( co, 0 ) ) { +#ifndef VG_NO_AUDIO + vg_audio_begin(); +#endif SDL_AtomicSet( &vg.engine_status, k_engine_status_running ); _vg_tower_set_flag( vg.sig_engine, 1 ); } @@ -286,28 +284,31 @@ static void _vg_gameloop_render(void) /* ui */ vg.engine_stage = k_engine_stage_ui; { - ui_prerender( &vg_ui.ctx ); - vg_ui_set_screen( vg.window_x, vg.window_y ); - ui_update_mouse( &vg_ui.ctx, (ui_px[2]){ vg.mouse_pos[0], vg.mouse_pos[1] }, vg.mouse_state ); - vg_framebuffer_ui( &vg_ui.ctx ); - - if( vg_console.enabled ) - { - ui_ignore_input_frames( &vg_ui.ctx, 10 ); - vg_gui( &vg_ui.ctx ); - ui_ignore_input_frames( &vg_ui.ctx, 0 ); - ui_capture_mouse( &vg_ui.ctx, 1 ); - vg_console_draw( &vg_ui.ctx ); - } - else vg_gui( &vg_ui.ctx ); + if( _vg_tower_clearence( _vg_tower_mask(vg.sig_engine)|_vg_tower_mask(vg.sig_client) ) ) + { + ui_prerender( &vg_ui.ctx ); + vg_ui_set_screen( vg.window_x, vg.window_y ); + ui_update_mouse( &vg_ui.ctx, (ui_px[2]){ vg.mouse_pos[0], vg.mouse_pos[1] }, vg.mouse_state ); + + if( vg_console.enabled ) + { + ui_ignore_input_frames( &vg_ui.ctx, 10 ); + vg_gui( &vg_ui.ctx ); + ui_ignore_input_frames( &vg_ui.ctx, 0 ); + ui_capture_mouse( &vg_ui.ctx, 1 ); + vg_console_draw( &vg_ui.ctx ); + } + else vg_gui( &vg_ui.ctx ); - if( vg.settings_open ) - vg_settings_gui( &vg_ui.ctx ); - - _vg_magi_render( &vg_ui.ctx ); + if( vg.settings_open ) + vg_settings_gui( &vg_ui.ctx ); + + vg_framebuffer_ui( &vg_ui.ctx ); + _vg_magi_render( &vg_ui.ctx ); - ui_postrender( &vg_ui.ctx, vg.time_frame_delta ); - vg_ui_post_update(); + ui_postrender( &vg_ui.ctx, vg.time_frame_delta ); + vg_ui_post_update(); + } } } @@ -405,10 +406,7 @@ static void _vg_crashscreen(void) ui_prerender( &vg_ui.ctx ); vg_ui_set_screen( vg.window_x, vg.window_y ); - ui_update_mouse( &vg_ui.ctx, - (ui_px[2]){ vg.mouse_pos[0], vg.mouse_pos[1] }, vg.mouse_state ); - - vg_framebuffer_ui( &vg_ui.ctx ); + ui_update_mouse( &vg_ui.ctx, (ui_px[2]){ vg.mouse_pos[0], vg.mouse_pos[1] }, vg.mouse_state ); vg_console.enabled = 1; ui_ignore_input_frames( &vg_ui.ctx, 10 ); @@ -430,10 +428,10 @@ static void _vg_gameloop(void) while(1) { vg.time_hp = SDL_GetPerformanceCounter(); - u64 udt = vg.time_hp - vg.time_hp_last; + u64 dt_hp = vg.time_hp - vg.time_hp_last; vg.time_hp_last = vg.time_hp; - double dt = (double)udt / (double)SDL_GetPerformanceFrequency(); + f64 dt = (f64)dt_hp / (f64)SDL_GetPerformanceFrequency(); vg.time_frame_delta += dt; while( vg_async_has_work( &vg.main_tasks ) ) @@ -518,18 +516,13 @@ static void _vg_init_window( const char *window_name ) strcpy( dest, exe_basepath ); SDL_free( exe_basepath ); vg.base_path = dest; - vg_info( "Basepath: %s\n", vg.base_path ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 3 ); - SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, - SDL_GL_CONTEXT_PROFILE_CORE ); - - SDL_GL_SetAttribute( SDL_GL_CONTEXT_RELEASE_BEHAVIOR, - SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH ); - + SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); + SDL_GL_SetAttribute( SDL_GL_CONTEXT_RELEASE_BEHAVIOR, SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH ); SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); @@ -577,9 +570,7 @@ static void _vg_init_window( const char *window_name ) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; vg_info( "CreateWindow( %d %d %u )\n", vg.window_x, vg.window_y, flags ); - - if((vg.window = SDL_CreateWindow( window_name, 0, 0, - vg.window_x, vg.window_y, flags ))) + if((vg.window = SDL_CreateWindow( window_name, 0, 0, vg.window_x, vg.window_y, flags ))) { if( vg.screen_mode == 2 ) SDL_SetWindowPosition( vg.window, video_mode.w-vg.window_x, 0 ); @@ -597,7 +588,8 @@ static void _vg_init_window( const char *window_name ) vg_info( "CreateContext\n" ); /* ????? */ - if( SDL_IsTextInputActive() ) SDL_StopTextInput(); + if( SDL_IsTextInputActive() ) + SDL_StopTextInput(); /* * OpenGL loading @@ -624,7 +616,6 @@ static void _vg_init_window( const char *window_name ) const unsigned char* glver = glGetString( GL_VERSION ); vg_success( "Load setup complete, OpenGL version: %s\n", glver ); - SDL_GL_SetSwapInterval(0); /* disable vsync while loading */ SDL_DisplayMode dispmode; @@ -738,13 +729,19 @@ void vg_run(void) vg_console_reg_var( "vg_vsync", &vg.vsync, k_var_dtype_i32, VG_VAR_PERSISTENT ); vg_console_reg_var( "vg_quality", &vg.quality_profile, k_var_dtype_i32, VG_VAR_PERSISTENT ); vg_console_reg_var( "vg_screen_mode", &vg.screen_mode, k_var_dtype_i32, VG_VAR_PERSISTENT ); - + vg_console_reg_cmd( "vg_settings", cmd_vg_settings_toggle, NULL ); rb_register_cvar(); - vg_audio_register(); + vg_framebuffer_register(); + vg_render_register(); + vg_input_register(); + vg_lines_register(); + vg_profiler_register(); + vg_mem_view_register(); + vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile, NULL ); + vg_console_load_autos(); - vg_console_reg_cmd( "vg_settings", cmd_vg_settings_toggle, NULL ); _vg_init_window( vg.window_name ); SDL_SetRelativeMouseMode(1); @@ -790,9 +787,7 @@ void vg_fatal_exit(void) SDL_AtomicSet( &vg.engine_status, k_engine_status_crashed ); if( vg_thread_purpose() == _thread_purpose_loader ) - { longjmp( vg.env_loader_exit, 1 ); - } else { /* TODO: This should also be able to go to the crash screen? */ diff --git a/vg_framebuffer.c b/vg_framebuffer.c index 95f94bb..7f838dc 100644 --- a/vg_framebuffer.c +++ b/vg_framebuffer.c @@ -377,8 +377,7 @@ void vg_framebuffer_ui( ui_context *ctx ) ui_fill( ctx, frame, 0xff000000 ); if( at->purpose == k_framebuffer_attachment_type_renderbuffer ) { - ui_text( ctx, frame, - "", 1, k_ui_align_middle_center, 0 ); + ui_text( ctx, frame, "", 1, k_ui_align_middle_center, 0 ); } else { @@ -540,7 +539,7 @@ static void vg_framebuffer_poll( int argc, char const *argv[] ) } } -void vg_framebuffer_init(void) +void vg_framebuffer_register(void) { //vg_console_reg_var( "blur_strength", &k_blur_strength, k_var_dtype_f32, 0 ); //vg_console_reg_var( "render_scale", &k_render_scale, @@ -551,8 +550,7 @@ void vg_framebuffer_init(void) //vg_console_reg_var( "blur_effect", &k_blur_effect, // k_var_dtype_i32, VG_VAR_PERSISTENT ); - vg_console_reg_cmd( "fb", vg_framebuffer_control, - vg_framebuffer_poll ); + vg_console_reg_cmd( "fb", vg_framebuffer_control, vg_framebuffer_poll ); } void vg_framebuffer_update_sizes(void) diff --git a/vg_framebuffer.h b/vg_framebuffer.h index 98bd7ed..fef287d 100644 --- a/vg_framebuffer.h +++ b/vg_framebuffer.h @@ -58,7 +58,7 @@ struct vg_framebuffer /* * Initialize framebuffer system */ -void vg_framebuffer_init(void); +void vg_framebuffer_register(void); /* * Get the current (automatically scaled or fixed) resolution of framebuffer diff --git a/vg_input.c b/vg_input.c index 581ea3a..8933e98 100644 --- a/vg_input.c +++ b/vg_input.c @@ -274,10 +274,14 @@ static void async_vg_input_init( void *_ ) } } +void vg_input_register(void) +{ + VG_VAR_F32( controller_deadzone, flags=VG_VAR_PERSISTENT ); +} + void vg_input_init(void) { THREAD_1; - VG_VAR_F32( controller_deadzone, flags=VG_VAR_PERSISTENT ); vg_async_call( &vg.main_tasks, async_vg_input_init, NULL ); } diff --git a/vg_input.h b/vg_input.h index 5c17d7e..bbb3f26 100644 --- a/vg_input.h +++ b/vg_input.h @@ -74,6 +74,7 @@ extern vg_input; u8 vg_getkey( SDL_Keycode kc ); void vg_process_inputs(void); +void vg_input_register(void); void vg_input_init(void); void vg_input_free(void); struct vg_controller *vg_active_controller(void); diff --git a/vg_lines.c b/vg_lines.c index 40eff0c..c74a3d5 100644 --- a/vg_lines.c +++ b/vg_lines.c @@ -80,14 +80,17 @@ static void async_vg_lines_init( void *_ ) glEnableVertexAttribArray( 1 ); } +void vg_lines_register(void) +{ + vg_console_reg_var( "vg_lines", &vg_lines.render, k_var_dtype_i32, VG_VAR_CHEAT ); +} + void vg_lines_init(void) { THREAD_1; - vg_lines.vertex_buffer = vg_stack_allocate( &vg.rtmem, VG_LINES_MAX_VERTS*sizeof(struct vg_lines_vert), - 8, "Debugging Lines" ); + vg_lines.vertex_buffer = vg_stack_allocate( &vg.rtmem, VG_LINES_MAX_VERTS*sizeof(struct vg_lines_vert), 8, "Debugging Lines" ); vg_async_call( &vg.main_tasks, async_vg_lines_init, NULL ); - vg_console_reg_var( "vg_lines", &vg_lines.render, k_var_dtype_i32, VG_VAR_CHEAT ); vg_shader_register( &_shader_lines ); } diff --git a/vg_lines.h b/vg_lines.h index 18dcdb9..ab22c3d 100644 --- a/vg_lines.h +++ b/vg_lines.h @@ -46,4 +46,5 @@ void vg_line_arrow( line_co co, line_co dir, float size, u32 colour ); void vg_line( line_co from, line_co to, u32 colour ); void vg_line2( line_co from, line_co to, u32 fc, u32 tc ); void vg_lines_drawall( void ); +void vg_lines_register(void); void vg_lines_init(void); diff --git a/vg_loader.c b/vg_loader.c index bbd134d..676a613 100644 --- a/vg_loader.c +++ b/vg_loader.c @@ -174,14 +174,12 @@ void _vg_loader_step( void( *fn_load )(void), void( *fn_free )(void), const char THREAD_1; u64 t0 = SDL_GetPerformanceCounter(); - vg.time_hp_last = vg.time_hp; // ??? - if( fn_load ) fn_load(); - u64 udt = SDL_GetPerformanceCounter() - t0; - double dt = (double)udt / (double)SDL_GetPerformanceFrequency(); - vg_info( "%s: %fs\n", alias, dt ); + u64 function_run_time = SDL_GetPerformanceCounter() - t0; + f64 run_time_seconds = (f64)function_run_time / (f64)SDL_GetPerformanceFrequency(); + vg_info( "%s: %fs\n", alias, run_time_seconds ); if( fn_free ) { @@ -193,10 +191,7 @@ void _vg_loader_step( void( *fn_load )(void), void( *fn_free )(void), const char } enum engine_status status = SDL_AtomicGet( &vg.engine_status ); - if( status == k_engine_status_crashed ) - { longjmp( vg.env_loader_exit, 1 ); - } } diff --git a/vg_mem.c b/vg_mem.c index 9a609a6..9d3a730 100644 --- a/vg_mem.c +++ b/vg_mem.c @@ -6,6 +6,7 @@ #include #include +#include void *vg_malloc( u64 size ) { @@ -148,8 +149,8 @@ void vg_stack_clear( vg_stack_allocator *stack ) void vg_stack_free( vg_stack_allocator *stack ) { - if( stack->flags & VG_STACK_ALLOCATOR_BUFFER_FROM_MALLOC ) - vg_free( stack->data ); + VG_ASSERT( stack->flags & VG_STACK_ALLOCATOR_BUFFER_FROM_MALLOC ); + vg_free( stack->data ); vg_zero_mem( stack, sizeof(vg_stack_allocator) ); } diff --git a/vg_mem.h b/vg_mem.h index f955a48..7a230c3 100644 --- a/vg_mem.h +++ b/vg_mem.h @@ -1,6 +1,7 @@ #pragma once #include "vg_platform.h" #include +#include #define VG_KB( X ) (X*1024) #define VG_MB( X ) (X*1024*1024) diff --git a/vg_mem_view.c b/vg_mem_view.c index 03c82f6..5159ac8 100644 --- a/vg_mem_view.c +++ b/vg_mem_view.c @@ -518,7 +518,7 @@ static void cmd_vg_mem_view_poll( int argc, const char *argv[] ) console_suggest_score_text( _vg_mem_named_buffers[i].name, term, 0 ); } -void vg_mem_view_init(void) +void vg_mem_view_register(void) { vg_console_reg_cmd( "vg_mem_view", cmd_vg_mem_view, cmd_vg_mem_view_poll ); } diff --git a/vg_mem_view.h b/vg_mem_view.h index 96421e6..29e793f 100644 --- a/vg_mem_view.h +++ b/vg_mem_view.h @@ -1,4 +1,4 @@ #pragma once #include "vg_ui/imgui.h" extern int vg_mem_view; -void vg_mem_view_init(void); +void vg_mem_view_register(void); diff --git a/vg_profiler.c b/vg_profiler.c index a4f2cca..aa7b16f 100644 --- a/vg_profiler.c +++ b/vg_profiler.c @@ -163,7 +163,7 @@ static void cmd_vg_profile_poll( int argc, const char *argv[] ) console_suggest_score_text( _vg_profiler.named_sets[i]->name,term,0 ); } -void vg_profiler_init(void) +void vg_profiler_register(void) { vg_console_reg_cmd( "vg_profile", cmd_vg_profile, cmd_vg_profile_poll ); } diff --git a/vg_profiler.h b/vg_profiler.h index d2a7f36..dd6d694 100644 --- a/vg_profiler.h +++ b/vg_profiler.h @@ -40,6 +40,6 @@ void vg_profile_end( struct vg_profile *profile ); void vg_profile_drawn( ui_context *ctx, struct vg_profile **profiles, u32 count, f64 budget, ui_rect panel, int dir, i32 normalize ); -void vg_profiler_init(void); +void vg_profiler_register(void); void _vg_profile_reg_set( struct vg_profile_set *set ); diff --git a/vg_render.c b/vg_render.c index eadd59f..ba631a8 100644 --- a/vg_render.c +++ b/vg_render.c @@ -68,16 +68,20 @@ static void vg_async_postprocess_init( void *userdata ) vg_compile_shader( &_shader_blit ); } +void vg_render_register(void) +{ + vg_console_reg_var( "render_scale", &_vg_render.scale, k_var_dtype_f32, VG_VAR_PERSISTENT ); + vg_console_reg_var( "blur_strength", &_vg_postprocess.blur_strength, k_var_dtype_f32, 0 ); + vg_console_reg_var( "blur_effect", &_vg_postprocess.blur_effect, k_var_dtype_i32, VG_VAR_PERSISTENT ); +} + void vg_render_init(void) { THREAD_1; vg_async_call( &vg.main_tasks, vg_async_postprocess_init, NULL ); - vg_console_reg_var( "render_scale", &_vg_render.scale, k_var_dtype_f32, VG_VAR_PERSISTENT ); #ifdef VG_3D - vg_console_reg_var( "blur_strength", &_vg_postprocess.blur_strength, k_var_dtype_f32, 0 ); - vg_console_reg_var( "blur_effect", &_vg_postprocess.blur_effect, k_var_dtype_i32, VG_VAR_PERSISTENT ); /* * Main framebuffer diff --git a/vg_render.h b/vg_render.h index 8f401ea..5da2ae4 100644 --- a/vg_render.h +++ b/vg_render.h @@ -27,6 +27,7 @@ struct vg_render } extern _vg_render; +void vg_render_register(void); void vg_render_init(void); void vg_render_fullscreen_quad(void); void vg_postprocess_to_screen( vg_framebuffer *fb ); diff --git a/vg_shader.c b/vg_shader.c index b368183..c536cee 100644 --- a/vg_shader.c +++ b/vg_shader.c @@ -25,8 +25,7 @@ static vg_shaders; * Compile OpenGL subshader from GLSL source. Type is subshader type. * If critical is set to 1, the program will fatal exit on compile failure. */ -static GLuint vg_compile_opengl_subshader( GLint type, - const char *src, bool critical ) +static GLuint vg_compile_opengl_subshader( GLint type, const char *src, bool critical ) { GLuint shader = glCreateShader( type ); diff --git a/vg_steam.c b/vg_steam.c index 3c51338..6a6599b 100644 --- a/vg_steam.c +++ b/vg_steam.c @@ -7,34 +7,24 @@ struct vg_steam vg_steam; vg_steam_async_call *vg_alloc_async_steam_api_call(void) { if( vg_steam.call_count == VG_ARRAY_LEN(vg_steam.calls) ) - { - vg_fatal_error( "Maximum concurrent API calls exceeded (%u)\n", - vg_steam.call_count ); - } + vg_fatal_error( "Maximum concurrent API calls exceeded (%u)\n", vg_steam.call_count ); return &vg_steam.calls[ vg_steam.call_count ++ ]; } void steam_register_callback( u32 id, void (*p_handler)( CallbackMsg_t *msg ) ) { - if( vg_steam.callback_handler_count == - VG_ARRAY_LEN(vg_steam.callback_handlers) ) - { - vg_fatal_error( "Too many steam callback handlers registered (%u)\n", - vg_steam.callback_handler_count ); - } + if( vg_steam.callback_handler_count == VG_ARRAY_LEN(vg_steam.callback_handlers) ) + vg_fatal_error( "Too many steam callback handlers registered (%u)\n", vg_steam.callback_handler_count ); - vg_steam_callback_handler *handler = - &vg_steam.callback_handlers[ vg_steam.callback_handler_count ++ ]; - + vg_steam_callback_handler *handler = &vg_steam.callback_handlers[ vg_steam.callback_handler_count ++ ]; handler->p_handler = p_handler; handler->callback_id = id; } void steamworks_process_api_call( HSteamPipe pipe, CallbackMsg_t *callback ) { - SteamAPICallCompleted_t *pCallCompleted = - (SteamAPICallCompleted_t *)callback->m_pubParam; + SteamAPICallCompleted_t *pCallCompleted = (SteamAPICallCompleted_t *)callback->m_pubParam; steamapi_bool bFailed; void *call_data = alloca( pCallCompleted->m_cubParam ); @@ -53,23 +43,22 @@ void steamworks_process_api_call( HSteamPipe pipe, CallbackMsg_t *callback ) * call identified by pCallCompleted->m_hAsyncCall */ - vg_info( "steamworks_event::api_call_completed( %lu )\n", - pCallCompleted->m_hAsyncCall ); + vg_info( "steamworks_event::api_call_completed( %lu )\n", pCallCompleted->m_hAsyncCall ); int j=0; - for( int i=0; im_hAsyncCall ){ + for( int i=0; im_hAsyncCall ) vg_steam.calls[j ++] = vg_steam.calls[i]; - } - else{ + else + { vg_steam_async_call *call = &vg_steam.calls[i]; call->p_handler( call_data, call->userdata ); } } - if( vg_steam.call_count == j ){ + if( vg_steam.call_count == j ) vg_error( "No tracker was register for API call\n" ); - } vg_steam.call_count = j; }