-/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
+/* Copyright (C) 2021-2023 Harry Godden (hgn) - All Rights Reserved */
/*
*/
-#ifndef VG_STATIC
- #define VG_STATIC
+#ifdef VG_RELEASE
+ #define VG_STATIC static
+#else
+ #define VG_STATIC
#endif
/* API */
enum engine_status status = vg.engine_status;
SDL_AtomicUnlock( &vg.sl_context );
- if( status != k_engine_status_running )
- {
- while(1)
- {
+ if( status != k_engine_status_running ){
+ while(1) {
VG_SYNC_LOG( "[%d] No longer running...\n");
SDL_Delay(1000);
}
{
SDL_AtomicLock( &vg.sl_context );
- if( vg.thread_id_main == SDL_GetThreadID(NULL) )
- {
+ if( vg.thread_id_main == SDL_GetThreadID(NULL) ){
SDL_AtomicUnlock( &vg.sl_context );
return k_thread_purpose_main;
}
- else
- {
+ else{
SDL_AtomicUnlock( &vg.sl_context );
return k_thread_purpose_loader;
}
{
/* We dont want to do anything if this is the main thread */
- if( vg_thread_purpose() == k_thread_purpose_loader )
- {
+ if( vg_thread_purpose() == k_thread_purpose_loader ){
VG_SYNC_LOG( "[%d] vg_acquire_thread_sync()\n" );
_vg_ensure_engine_running();
SDL_AtomicLock( &vg.sl_context );
- if( vg.context_ownership_depth == 0 )
- {
+ if( vg.context_ownership_depth == 0 ){
vg.context_ownership_depth ++;
vg.exec_context = 1;
SDL_AtomicUnlock( &vg.sl_context );
SDL_GL_MakeCurrent( vg.window, vg.gl_context );
VG_SYNC_LOG( "[%d] granted\n" );
}
- else
- {
+ else{
vg.context_ownership_depth ++;
VG_SYNC_LOG( "[%d] granted\n" );
SDL_AtomicUnlock( &vg.sl_context );
*/
VG_STATIC void vg_release_thread_sync(void)
{
- if( vg_thread_purpose() == k_thread_purpose_loader )
- {
+ if( vg_thread_purpose() == k_thread_purpose_loader ){
VG_SYNC_LOG( "[%d] vg_release_thread_sync()\n" );
SDL_AtomicLock( &vg.sl_context );
vg.context_ownership_depth --;
- if( vg.context_ownership_depth == 0 )
- {
+ if( vg.context_ownership_depth == 0 ){
SDL_AtomicUnlock( &vg.sl_context );
VG_SYNC_LOG( "[%d] Releasing context.\n" );
SDL_GL_MakeCurrent( NULL, NULL );
{
SDL_AtomicLock( &vg.sl_context );
- if( vg.exec_context != 0 )
- {
+ if( vg.exec_context != 0 ){
VG_SYNC_LOG( "[%d] _vg_run_synced() (%d).\n", vg.exec_context );
vg.exec_context = 0;
SDL_AtomicUnlock( &vg.sl_context );
VG_SYNC_LOG( "[%d] Re-engaging.\n" );
SDL_GL_MakeCurrent( vg.window, vg.gl_context );
}
- else
- {
+ else{
VG_SYNC_LOG( "[%d] Nothing to do.\n" );
SDL_AtomicUnlock( &vg.sl_context );
}
int fail = 0;
GLenum err;
- while( (err = glGetError()) != GL_NO_ERROR )
- {
+ while( (err = glGetError()) != GL_NO_ERROR ){
vg_error( "(%s) OpenGL Error: #%d\n", src_info, err );
fail = 1;
}
/* SDL event loop */
SDL_Event event;
- while( SDL_PollEvent( &event ) )
- {
- if( event.type == SDL_KEYDOWN )
- {
+ while( SDL_PollEvent( &event ) ){
+ if( event.type == SDL_KEYDOWN ){
console_proc_key( event.key.keysym );
}
- else if( event.type == SDL_MOUSEWHEEL )
- {
+ else if( event.type == SDL_MOUSEWHEEL ){
vg.mouse_wheel[0] += event.wheel.preciseX;
vg.mouse_wheel[1] += event.wheel.preciseY;
}
{
vg_input_controller_event( &event );
}
- else if( event.type == SDL_MOUSEMOTION )
- {
+ else if( event.type == SDL_MOUSEMOTION ){
vg.mouse_delta[0] += event.motion.xrel;
vg.mouse_delta[1] += event.motion.yrel;
}
- else if( event.type == SDL_WINDOWEVENT )
- {
- if( event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED )
- {
+ else if( event.type == SDL_WINDOWEVENT ){
+ if( event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED ){
int w, h;
SDL_GL_GetDrawableSize( vg.window, &w, &h );
- if( !w || !h )
- {
+ if( !w || !h ){
vg_warn( "Got a invalid framebuffer size: "
"%dx%d... ignoring\n", w, h );
}
- else
- {
+ else{
vg.window_x = w;
vg.window_y = h;
vg_framebuffer_resize(w,h);
}
}
- else if( event.window.event == SDL_WINDOWEVENT_CLOSE )
- {
+ else if( event.window.event == SDL_WINDOWEVENT_CLOSE ){
vg.window_should_close = 1;
}
}
- else if( event.type == SDL_TEXTINPUT )
- {
+ else if( event.type == SDL_TEXTINPUT ){
console_proc_utf8( event.text.text );
}
}
vg.fixed_iterations = 0;
vg_lines.allow_input = 1;
- while( vg.accumulator >= (VG_TIMESTEP_FIXED-0.00125) )
- {
+ while( vg.accumulator >= (VG_TIMESTEP_FIXED-0.00125) ){
vg_update_fixed();
vg_lines.allow_input = 0;
vg.accumulator = VG_MAX( 0.0, vg.accumulator );
vg.fixed_iterations ++;
- if( vg.fixed_iterations == 8 )
- {
+ if( vg.fixed_iterations == 8 ){
break;
}
}
{
vg_profile_begin( &vg_prof_render );
- if( vg.is_loaded )
- {
+ if( vg.is_loaded ){
/* render */
vg.engine_stage = k_engine_stage_rendering;
vg_render();
(ui_rect){ 4, 4, 250, 0 }, 0
);
- if( vg_profiler )
- {
-
+ if( vg_profiler ){
char perf[128];
snprintf( perf, 127,
vg.accumulator = 0.75f * (1.0f/60.0f);
int post_start = 0;
- while(1)
- {
+ while(1){
_vg_process_events();
if( vg.window_should_close )
vg.time_delta = vg.frame_delta * vg.time_rate;
vg.time += vg.time_delta;
- if( vg.is_loaded )
- {
- if( !post_start )
- {
+ if( vg.is_loaded ){
+ if( !post_start ){
vg_start();
post_start = 1;
}
}
- else
- {
+ else{
_vg_loader_render();
}
VG_STATIC void _vg_process_launch_opts_internal( int argc, char *argv[] )
{
char *arg;
- while( vg_argp( argc, argv ) )
- {
- if( (arg = vg_opt_arg( 'w' )) )
- {
+ while( vg_argp( argc, argv ) ){
+ if( (arg = vg_opt_arg( 'w' )) ){
vg.window_x = atoi( arg );
}
- if( (arg = vg_opt_arg( 'h' )) )
- {
+ if( (arg = vg_opt_arg( 'h' )) ){
vg.window_y = atoi( arg );
}
- if( (arg = vg_long_opt_arg( "samples" )) )
- {
+ if( (arg = vg_long_opt_arg( "samples" )) ){
vg.samples = VG_MAX( 0, VG_MIN( 8, atoi( arg ) ) );
}
- if( vg_long_opt( "use-libc-malloc" ) )
- {
+ if( vg_long_opt( "use-libc-malloc" ) ){
vg_mem.use_libc_malloc = 1;
}
- if( vg_long_opt( "high-performance" ) )
- {
+ if( vg_long_opt( "high-performance" ) ){
vg.quality_profile = k_quality_profile_low;
}
/*
* OpenGL loading
*/
- if( (vg.gl_context = SDL_GL_CreateContext(vg.window) ))
- {
+ if( (vg.gl_context = SDL_GL_CreateContext(vg.window) )){
SDL_GL_GetDrawableSize( vg.window, &vg.window_x, &vg.window_y );
vg_success( "Window created (%dx%d)\n", vg.window_x, vg.window_y );
}
- else
- {
+ else{
vg_error( "SDL_GL_CreateContext failed: %s\n", SDL_GetError() );
SDL_Quit();
exit(0);
}
- if( !gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress) )
- {
+ if( !gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress) ) {
vg_error( "Glad Failed to initialize\n" );
SDL_GL_DeleteContext( vg.gl_context );
SDL_Quit();
vg_info( "Setting swap interval\n" );
- if( SDL_GL_SetSwapInterval( -1 ) == -1 )
- {
+ if( SDL_GL_SetSwapInterval( -1 ) == -1 ){
vg_warn( "Adaptive Vsync not supported\n" );
- if( SDL_GL_SetSwapInterval( 1 ) == -1 )
- {
+ if( SDL_GL_SetSwapInterval( 1 ) == -1 ){
vg_fatal_exit_loop( "Cannot enable Vsync! You might be overriding it"
" in your graphics control panel.\n" );
}
vg_success( "Using adaptive Vsync\n" );
SDL_DisplayMode dispmode;
- if( !SDL_GetWindowDisplayMode( vg.window, &dispmode ) )
- {
- if( dispmode.refresh_rate )
- {
+ if( !SDL_GetWindowDisplayMode( vg.window, &dispmode ) ){
+ if( dispmode.refresh_rate ){
vg.refresh_rate = dispmode.refresh_rate;
vg_info( "Refresh rate: %d\n", dispmode.refresh_rate );
}
size = backtrace( array, 20 );
strings = backtrace_symbols( array, size );
- if( strings != NULL )
- {
+ if( strings != NULL ){
vg_error( "---------------- gnu backtrace -------------\n" );
for( int i=0; i<size; i++ )
vg_error( "Fatal error: %s\n", error );
SDL_AtomicLock( &vg.sl_context );
- if( vg.engine_status == k_engine_status_none )
- {
+ if( vg.engine_status == k_engine_status_none ){
SDL_AtomicUnlock( &vg.sl_context );
/* TODO: Correct shutdown before other systems */
exit(0);
}
- else
- {
+ else{
SDL_AtomicUnlock( &vg.sl_context );
vg_acquire_thread_sync();
SDL_AtomicUnlock( &vg.sl_context );
/* Notify other thread for curtosey */
- if( vg_thread_purpose() == k_thread_purpose_main )
- {
+ if( vg_thread_purpose() == k_thread_purpose_main ){
SDL_AtomicLock( &vg.sl_context );
if( vg.exec_context != 0 )
vg_audio_free();
- while(1)
- {
+ while(1){
_vg_process_events();
if( vg.window_should_close )
break;