1 /* Copyright (C) 2021-2024 Mt.Zero Software - All Rights Reserved */
7 | | .---------------------------------------------------------.
8 |API| | vg_enter( int argc, char *argv[], const char *window_name |
9 | | '---------------------------------------------------------'
12 |IMP| vg_launch_opt(void) <--.
14 | | |'---------------'
16 | | |'-----------------------------------| 1 |------.
19 | | | |IMP| vg_preload(void)
22 | | | | |IMP| vg_load(void)
24 |IMP| | vg_framebuffer_resize(void) |
26 |IMP| | |.------------- vg_start(void) ---------------'
29 |IMP| | vg_pre_update(void)
32 | | | | | called 0x to 8x
34 |IMP| | '- vg_fixed_update(void)
39 |IMP| | vg_post_update(void)
42 |IMP| | vg_render(void)
48 |IMP| | vg_game_settings_init(void)
49 |IMP| | vg_game_settings_gui( ui_rect panel )
50 | | | | (optional: #define VG_GAME_SETTINGS)
60 const char *vg_get_basepath(void);
62 #include "vg_platform.h"
66 #include "dep/glad/glad.h"
67 #include "dep/sdl/include/SDL.h"
68 #include "vg_stdint.h"
70 void vg_register_exit( void( *funcptr
)(void), const char *name
);
79 //#define VG_SYNC_DEBUG
81 #define VG_SYNC_LOG(STR,...) \
82 vg_info(STR,SDL_GetThreadID(NULL),##__VA_ARGS__)
84 #define VG_SYNC_LOG(...)
88 static void vg_enter( int argc
, char *argv
[], const char *window_name
);
91 static void vg_preload(void);
92 static void vg_load(void);
95 static void vg_launch_opt(void);
96 static void vg_start(void);
98 static void vg_framebuffer_resize(int w
, int h
);
99 static void vg_pre_update(void);
100 static void vg_fixed_update(void);
101 static void vg_post_update(void);
103 static void vg_render(void);
104 static void vg_gui(void);
106 enum quality_profile
{
107 k_quality_profile_high
= 0,
108 k_quality_profile_low
= 1,
109 k_quality_profile_min
= 2
115 SDL_GLContext gl_context
;
116 const char *base_path
;
118 SDL_sem
*sem_loader
; /* allows only one loader at a time */
119 jmp_buf env_loader_exit
;
121 SDL_threadID thread_id_main
,
125 SDL_SpinLock sl_status
;
127 k_engine_status_none
,
128 k_engine_status_load_internal
,
129 k_engine_status_running
,
130 k_engine_status_crashed
134 /* Window information */
140 int display_refresh_rate
,
149 k_vsync_feature_disabled
=0,
150 k_vsync_feature_enabled
=1,
151 k_vsync_feature_enabled_adaptive
=2,
152 k_vsync_feature_error
=3
166 time_fixed_accumulator
,
167 time_fixed_extrapolate
,
170 u64 time_hp
, time_hp_last
, time_spinning
;
172 int fixed_iterations
;
176 k_engine_stage_update
,
177 k_engine_stage_update_fixed
,
178 k_engine_stage_rendering
,
197 static vg
= { .time_rate
= 1.0 };
198 const char *vg_get_basepath(void){
202 enum vg_thread_purpose
204 k_thread_purpose_nothing
,
205 k_thread_purpose_main
,
206 k_thread_purpose_loader
209 #include "vg_async.h"
211 static enum engine_status
_vg_engine_status(void)
213 SDL_AtomicLock( &vg
.sl_status
);
214 enum engine_status status
= vg
.engine_status
;
215 SDL_AtomicUnlock( &vg
.sl_status
);
220 static enum vg_thread_purpose
vg_thread_purpose(void)
222 SDL_AtomicLock( &vg
.sl_status
);
224 if( vg
.thread_id_main
== SDL_GetThreadID(NULL
) ){
225 SDL_AtomicUnlock( &vg
.sl_status
);
226 return k_thread_purpose_main
;
229 SDL_AtomicUnlock( &vg
.sl_status
);
230 return k_thread_purpose_loader
;
234 static void vg_assert_thread( enum vg_thread_purpose required
){
235 enum vg_thread_purpose purpose
= vg_thread_purpose();
237 if( purpose
!= required
){
238 vg_fatal_error( "thread_purpose must be %u not %u\n", required
, purpose
);
242 static void _vg_opengl_sync_init(void)
244 vg
.sem_loader
= SDL_CreateSemaphore(1);
247 static void vg_checkgl( const char *src_info
);
248 #define VG_STRINGIT( X ) #X
249 #define VG_CHECK_GL_ERR() vg_checkgl( __FILE__ ":L" VG_STRINGIT(__LINE__) )
251 #include "vg_console.h"
252 #include "vg_profiler.h"
254 #include "vg_audio.h"
256 #include "vg_shader.h"
258 #include "vg_input.h"
259 #include "vg_imgui.h"
260 #include "vg_lines.h"
261 #include "vg_rigidbody_view.h"
262 #include "vg_loader.h"
264 #include "vg_settings_menu.h"
267 static struct vg_profile vg_prof_update
= {.name
="update()"},
268 vg_prof_render
= {.name
="render()"},
269 vg_prof_swap
= {.name
="swap"};
271 static void vg_checkgl( const char *src_info
)
276 while( (err
= glGetError()) != GL_NO_ERROR
){
277 vg_error( "(%s) OpenGL Error: #%d\n", src_info
, err
);
282 vg_fatal_error( "OpenGL Error" );
285 static void async_vg_bake_shaders( void *payload
, u32 size
)
287 vg_shaders_compile();
290 static void vg_bake_shaders(void)
292 vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile
, NULL
);
293 vg_async_call( async_vg_bake_shaders
, NULL
, 0 );
296 void async_internal_complete( void *payload
, u32 size
)
298 vg_success( "Internal async setup complete\n" );
299 SDL_AtomicLock( &vg
.sl_status
);
301 if( vg
.engine_status
== k_engine_status_crashed
){
302 SDL_AtomicUnlock( &vg
.sl_status
);
306 vg
.engine_status
= k_engine_status_running
;
309 SDL_AtomicUnlock( &vg
.sl_status
);
312 static void _vg_load_full( void *data
){
314 vg_tex2d_replace_with_error( &vg
.tex_missing
);
315 vg_ui
.tex_bg
= vg
.tex_missing
;
318 vg_loader_step( vg_input_init
, vg_input_free
);
319 vg_loader_step( vg_lines_init
, NULL
);
320 vg_loader_step( vg_rb_view_init
, NULL
);
322 vg_loader_step( vg_audio_init
, vg_audio_free
);
324 vg_loader_step( vg_profiler_init
, NULL
);
326 vg_async_call( async_internal_complete
, NULL
, 0 );
331 vg_success( "Client loaded in %fs\n", vg
.time_real
);
334 static void _vg_process_events(void)
336 v2_zero( vg
.mouse_wheel
);
337 v2_zero( vg
.mouse_delta
);
344 while( SDL_PollEvent( &event
) ){
345 if( event
.type
== SDL_KEYDOWN
){
346 if( vg_console
.enabled
&&
347 (vg_ui
.focused_control_type
!= k_ui_control_modal
) ){
348 if( event
.key
.keysym
.sym
== SDLK_ESCAPE
||
349 event
.key
.keysym
.scancode
== SDL_SCANCODE_GRAVE
){
350 vg_console
.enabled
= 0;
353 else if( (event
.key
.keysym
.mod
& KMOD_CTRL
) &&
354 event
.key
.keysym
.sym
== SDLK_n
){
355 _console_suggest_next();
357 else if( (event
.key
.keysym
.mod
& KMOD_CTRL
) &&
358 event
.key
.keysym
.sym
== SDLK_p
){
359 _console_suggest_prev();
362 _ui_proc_key( event
.key
.keysym
);
366 if( event
.key
.keysym
.scancode
== SDL_SCANCODE_GRAVE
){
367 vg_console
.enabled
= 1;
370 _ui_proc_key( event
.key
.keysym
);
374 else if( event
.type
== SDL_MOUSEWHEEL
){
375 vg
.mouse_wheel
[0] += event
.wheel
.preciseX
;
376 vg
.mouse_wheel
[1] += event
.wheel
.preciseY
;
378 else if( event
.type
== SDL_CONTROLLERDEVICEADDED
||
379 event
.type
== SDL_CONTROLLERDEVICEREMOVED
)
381 vg_input_device_event( &event
);
383 else if( event
.type
== SDL_CONTROLLERAXISMOTION
||
384 event
.type
== SDL_CONTROLLERBUTTONDOWN
||
385 event
.type
== SDL_CONTROLLERBUTTONUP
)
387 vg_input_controller_event( &event
);
389 else if( event
.type
== SDL_MOUSEMOTION
){
390 vg
.mouse_delta
[0] += event
.motion
.xrel
;
391 vg
.mouse_delta
[1] += event
.motion
.yrel
;
393 else if( event
.type
== SDL_WINDOWEVENT
){
394 if( event
.window
.event
== SDL_WINDOWEVENT_SIZE_CHANGED
){
396 SDL_GL_GetDrawableSize( vg
.window
, &w
, &h
);
399 vg_warn( "Got a invalid framebuffer size: "
400 "%dx%d... ignoring\n", w
, h
);
406 vg_framebuffer_resize(w
,h
);
409 else if( event
.window
.event
== SDL_WINDOWEVENT_CLOSE
){
410 vg
.window_should_close
= 1;
413 else if( event
.type
== SDL_TEXTINPUT
){
414 ui_proc_utf8( event
.text
.text
);
418 SDL_GetMouseState( &vg
.mouse_pos
[0], &vg
.mouse_pos
[1] );
421 static void _vg_gameloop_update(void)
423 vg_profile_begin( &vg_prof_update
);
425 vg
.engine_stage
= k_engine_stage_update
;
428 /* Fixed update loop */
429 vg
.engine_stage
= k_engine_stage_update_fixed
;
431 vg
.fixed_iterations
= 0;
432 vg_lines
.enabled
= vg_lines
.render
;
433 vg
.time_fixed_accumulator
+= vg
.time_delta
;
435 while( vg
.time_fixed_accumulator
>= VG_TIMESTEP_FIXED
){
437 vg_lines
.enabled
= 0;
438 vg
.time_fixed_accumulator
-= VG_TIMESTEP_FIXED
;
440 vg
.fixed_iterations
++;
441 if( vg
.fixed_iterations
== 8 ){
445 vg_lines
.enabled
= vg_lines
.render
;
446 vg
.time_fixed_extrapolate
= vg
.time_fixed_accumulator
/ VG_TIMESTEP_FIXED
;
448 vg
.engine_stage
= k_engine_stage_update
;
450 vg_profile_end( &vg_prof_update
);
453 static void _vg_gameloop_render(void)
455 vg_profile_begin( &vg_prof_render
);
458 vg
.engine_stage
= k_engine_stage_rendering
;
462 vg
.engine_stage
= k_engine_stage_ui
;
465 if( vg_console
.enabled
){
466 vg_ui
.ignore_input_frames
= 10;
468 vg_ui
.ignore_input_frames
= 0;
469 vg_ui
.wants_mouse
= 1;
474 if( vg
.settings_open
)
479 audio_debug_ui( vg
.pv
);
484 int frame_target
= vg
.display_refresh_rate
;
485 if( vg
.fps_limit
> 0 ) frame_target
= vg
.fps_limit
;
487 (struct vg_profile
*[]){
488 &vg_prof_update
,&vg_prof_render
,&vg_prof_swap
}, 3,
489 (1.0f
/(float)frame_target
)*1000.0f
,
490 (ui_rect
){ 4, 4, 250, 0 }, 0, 0
496 "refresh: %d (%.1fms)\n"
498 "iterations: %d (acc: %.3fms%%)\n"
499 "time: real(%.2f) delta(%.2f) rate(%.2f)\n"
500 " extrap(%.2f) frame(%.2f) spin( "PRINTF_U64
" )\n",
501 vg
.window_x
, vg
.window_y
,
502 frame_target
, (1.0f
/(float)frame_target
)*1000.0f
,
505 (vg
.time_fixed_accumulator
/VG_TIMESTEP_FIXED
)*100.0f
,
506 vg
.time_real
, vg
.time_delta
, vg
.time_rate
,
507 vg
.time_fixed_extrapolate
, vg
.time_frame_delta
,
510 ui_text( (ui_rect
){258, 4+24+12+12,900,900},perf
,1,0,k_ui_align_left
);
515 vg_profile_end( &vg_prof_render
);
518 static void aaaaaaaaaaaaaaaaa( ui_rect r
){
519 int frame_target
= vg
.display_refresh_rate
;
520 if( !vg
.vsync
) frame_target
= vg
.fps_limit
;
523 (struct vg_profile
*[]){
524 &vg_prof_update
,&vg_prof_render
,&vg_prof_swap
}, 3,
525 (1.0f
/(f32
)frame_target
)*1500.0f
,
529 ui_fill( (ui_rect
){ r
[0], r
[1] + (r
[3]*2)/3, r
[2], 1 }, ui_colour(k_ui_fg
) );
532 static void vg_changevsync(void){
533 if( vg
.vsync
&& (vg
.vsync_feature
!= k_vsync_feature_error
) ){
534 /* turn on vsync if not enabled */
536 enum vsync_feature requested
= k_vsync_feature_enabled
;
537 if( vg
.vsync
< 0 ) requested
= k_vsync_feature_enabled_adaptive
;
539 if( vg
.vsync_feature
!= requested
){
540 vg_info( "Setting swap interval\n" );
542 int swap_interval
= 1;
543 if( requested
== k_vsync_feature_enabled_adaptive
)
546 if( SDL_GL_SetSwapInterval( swap_interval
) == -1 ){
547 if( requested
== k_vsync_feature_enabled
){
548 vg_error( "Vsync is not supported by your system\n" );
549 vg_warn( "You may be overriding it in your"
550 " graphics control panel.\n" );
553 vg_error( "Adaptive Vsync is not supported by your system\n" );
556 vg
.vsync_feature
= k_vsync_feature_error
;
558 /* TODO: Make popup to notify user that this happened */
561 vg_success( "Vsync enabled (%d)\n", requested
);
562 vg
.vsync_feature
= requested
;
567 if( vg
.vsync_feature
!= k_vsync_feature_disabled
){
568 SDL_GL_SetSwapInterval( 0 );
569 vg
.vsync_feature
= k_vsync_feature_disabled
;
574 static int vg_framefilter( double dt
){
575 if( vg
.fps_limit
< 24 ) vg
.fps_limit
= 24;
576 if( vg
.fps_limit
> 300 ) vg
.fps_limit
= 300;
578 double min_frametime
= 1.0/(double)vg
.fps_limit
;
579 if( vg
.time_frame_delta
< min_frametime
){
580 /* TODO: we can use high res nanosleep on Linux here */
581 double sleep_ms
= (min_frametime
-vg
.time_frame_delta
) * 1000.0;
582 u32 ms
= (u32
)floor( sleep_ms
);
585 if( !vg_loader_availible() )
600 static int _vg_crashscreen(void)
603 if( vg_getkey( SDLK_ESCAPE
) )
607 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
609 glDisable(GL_DEPTH_TEST
);
610 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
611 glBlendEquation(GL_FUNC_ADD
);
613 glClearColor( 0.15f
+ sinf(vg
.time_real
)*0.1f
, 0.0f
, 0.0f
,1.0f
);
614 glClear( GL_COLOR_BUFFER_BIT
);
615 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
622 static void _vg_gameloop(void){
623 //vg.time_fixed_accumulator = 0.75f * (1.0f/60.0f);
625 vg
.time_hp
= SDL_GetPerformanceCounter();
626 vg
.time_hp_last
= vg
.time_hp
;
630 vg
.time_hp
= SDL_GetPerformanceCounter();
631 u64 udt
= vg
.time_hp
- vg
.time_hp_last
;
632 vg
.time_hp_last
= vg
.time_hp
;
634 double dt
= (double)udt
/ (double)SDL_GetPerformanceFrequency();
636 vg
.time_frame_delta
+= dt
;
637 vg_run_async_checked();
639 if( vg_framefilter( dt
) )
644 enum engine_status status
= _vg_engine_status();
645 if( status
== k_engine_status_running
)
646 vg_profile_begin( &vg_prof_swap
);
648 SDL_GL_SwapWindow( vg
.window
);
650 if( status
== k_engine_status_running
)
651 vg_profile_end( &vg_prof_swap
);
653 vg
.time_real
+= vg
.time_frame_delta
;
654 vg
.time_delta
= vg
.time_frame_delta
* vg
.time_rate
;
655 vg
.time
+= vg
.time_delta
;
657 _vg_process_events();
659 if( vg
.window_should_close
)
662 if( status
== k_engine_status_crashed
){
663 if( _vg_crashscreen() )
667 if( status
== k_engine_status_running
){
668 _vg_gameloop_update();
669 _vg_gameloop_render();
676 if( vg
.loader_ring
> 0.01f
){
677 _vg_loader_render_ring( vg
.loader_ring
);
678 vg
.loader_ring
-= vg
.time_frame_delta
* 0.5f
;
681 vg
.time_frame_delta
= 0.0;
682 vg
.time_spinning
= 0;
686 static void _vg_process_launch_opts_internal( int argc
, char *argv
[] )
689 while( vg_argp( argc
, argv
) ){
690 if( (arg
= vg_opt_arg( 'w' )) ){
691 vg
.window_x
= atoi( arg
);
694 if( (arg
= vg_opt_arg( 'h' )) ){
695 vg
.window_y
= atoi( arg
);
698 if( (arg
= vg_long_opt_arg( "samples" )) ){
699 vg
.samples
= VG_MAX( 0, VG_MIN( 8, atoi( arg
) ) );
702 if( vg_long_opt( "use-libc-malloc" ) ){
703 vg_mem
.use_libc_malloc
= 1;
706 if( vg_long_opt( "high-performance" ) ){
707 vg
.quality_profile
= k_quality_profile_low
;
714 static void _vg_init_window( const char *window_name
)
716 vg_info( "SDL_INIT\n" );
718 if( SDL_Init( SDL_INIT_VIDEO
) != 0 ){
719 vg_error( "SDL_Init failed: %s\n", SDL_GetError() );
724 SDL_InitSubSystem( SDL_INIT_AUDIO
);
726 SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER
);
728 char *exe_basepath
= SDL_GetBasePath();
729 u32 len
= vg_align8( strlen(exe_basepath
)+1 );
730 char *dest
= vg_linear_alloc( vg_mem
.rtmemory
, len
);
731 strcpy( dest
, exe_basepath
);
732 SDL_free( exe_basepath
);
735 vg_info( "Basepath: %s\n", vg
.base_path
);
737 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER
, 1 );
738 SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION
, 3 );
739 SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION
, 3 );
740 SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK
,
741 SDL_GL_CONTEXT_PROFILE_CORE
);
743 SDL_GL_SetAttribute( SDL_GL_CONTEXT_RELEASE_BEHAVIOR
,
744 SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH
);
746 SDL_GL_SetAttribute( SDL_GL_RED_SIZE
, 8 );
747 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE
, 8 );
748 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE
, 8 );
749 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE
, 8 );
750 SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE
, 0 );
753 * Get monitor information
755 vg_info( "Getting display count\n" );
756 int display_count
= 0,
760 SDL_DisplayMode video_mode
;
761 if( SDL_GetDesktopDisplayMode( display_index
, &video_mode
) ){
762 vg_error( "SDL_GetDesktopDisplayMode failed: %s\n", SDL_GetError() );
767 vg
.display_refresh_rate
= video_mode
.refresh_rate
;
768 vg
.window_x
= video_mode
.w
;
769 vg
.window_y
= video_mode
.h
;
771 if( vg
.screen_mode
== 2 ){
777 SDL_SetHint( "SDL_VIDEO_X11_XINERAMA", "1" );
778 SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "0" );
779 SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "0" );
782 u32 flags
= SDL_WINDOW_OPENGL
| SDL_WINDOW_INPUT_GRABBED
|
783 SDL_WINDOW_RESIZABLE
;
785 if( vg
.screen_mode
== 1 )
786 flags
|= SDL_WINDOW_FULLSCREEN
;
787 else if( vg
.screen_mode
== 0 )
788 flags
|= SDL_WINDOW_FULLSCREEN_DESKTOP
;
790 vg_info( "CreateWindow( %d %d %u )\n", vg
.window_x
, vg
.window_y
, flags
);
792 if((vg
.window
= SDL_CreateWindow( window_name
, 0, 0,
793 vg
.window_x
, vg
.window_y
, flags
))){
794 if( vg
.screen_mode
== 2 )
795 SDL_SetWindowPosition( vg
.window
, video_mode
.w
-vg
.window_x
, 0 );
798 vg_error( "SDL_CreateWindow failed: %s", SDL_GetError() );
802 SDL_RaiseWindow( vg
.window
);
803 SDL_SetWindowMinimumSize( vg
.window
, 1280, 720 );
804 SDL_SetWindowMaximumSize( vg
.window
, 4096, 4096 );
806 vg_info( "CreateContext\n" );
809 if( SDL_IsTextInputActive() ) SDL_StopTextInput();
814 if( (vg
.gl_context
= SDL_GL_CreateContext(vg
.window
) )){
815 SDL_GL_GetDrawableSize( vg
.window
, &vg
.window_x
, &vg
.window_y
);
816 vg_success( "Window created (%dx%d)\n", vg
.window_x
, vg
.window_y
);
819 vg_error( "SDL_GL_CreateContext failed: %s\n", SDL_GetError() );
824 if( !gladLoadGLLoader((GLADloadproc
)SDL_GL_GetProcAddress
) ) {
825 vg_error( "Glad Failed to initialize\n" );
826 SDL_GL_DeleteContext( vg
.gl_context
);
831 const unsigned char* glver
= glGetString( GL_VERSION
);
832 vg_success( "Load setup complete, OpenGL version: %s\n", glver
);
834 SDL_GL_SetSwapInterval(0); /* disable vsync while loading */
836 SDL_DisplayMode dispmode
;
837 if( !SDL_GetWindowDisplayMode( vg
.window
, &dispmode
) ){
838 if( dispmode
.refresh_rate
){
839 vg
.display_refresh_rate
= dispmode
.refresh_rate
;
843 if( vg
.display_refresh_rate
< 25 || vg
.display_refresh_rate
> 300 ){
844 vg
.display_refresh_rate
= 60;
847 vg_info( "Display refresh rate: %d\n", dispmode
.refresh_rate
);
848 if( !vg
.fps_limit
) vg
.fps_limit
= vg
.display_refresh_rate
;
851 static void _vg_terminate(void)
854 _vg_console_write_persistent();
856 SDL_AtomicLock( &vg
.sl_status
);
857 vg
.engine_status
= k_engine_status_none
;
858 SDL_AtomicUnlock( &vg
.sl_status
);
862 vg_success( "If you see this it means everything went.. \"well\".....\n" );
864 SDL_GL_DeleteContext( vg
.gl_context
);
869 static void vg_enter( int argc
, char *argv
[], const char *window_name
){
870 vg_rand_seed( &vg
.rand
, 461 );
871 _vg_process_launch_opts_internal( argc
, argv
);
877 vg_console_reg_var( "vg_fps_limit", &vg
.fps_limit
,
878 k_var_dtype_i32
, VG_VAR_PERSISTENT
);
879 vg_console_reg_var( "vg_vsync", &vg
.vsync
,
880 k_var_dtype_i32
, VG_VAR_PERSISTENT
);
881 vg_console_reg_var( "vg_quality", &vg
.quality_profile
,
882 k_var_dtype_i32
, VG_VAR_PERSISTENT
);
883 vg_console_reg_var( "vg_screen_mode", &vg
.screen_mode
,
884 k_var_dtype_i32
, VG_VAR_PERSISTENT
);
886 vg_console_load_autos();
888 vg_console_reg_cmd( "vg_settings", cmd_vg_settings_toggle
, NULL
);
889 _vg_init_window( window_name
);
892 SDL_SetRelativeMouseMode(1);
894 vg
.thread_id_main
= SDL_GetThreadID(NULL
);
896 /* Opengl-required systems */
900 vg
.engine_status
= k_engine_status_load_internal
;
902 _vg_opengl_sync_init();
903 vg_loader_start( _vg_load_full
, NULL
);
908 static void vg_fatal_error( const char *fmt
, ... )
911 va_start( args
, fmt
);
912 _vg_logx_va( stderr
, NULL
, "fatal", KRED
, fmt
, args
);
915 vg_print_backtrace();
917 SDL_AtomicLock( &vg
.sl_status
);
918 vg
.engine_status
= k_engine_status_crashed
;
919 SDL_AtomicUnlock( &vg
.sl_status
);
921 if( vg_thread_purpose() == k_thread_purpose_loader
){
922 longjmp( vg
.env_loader_exit
, 1 );
925 vg_error( "There is no jump to the error runner thing yet! bai bai\n" );
933 static void vg_fatal_error( const char *fmt
, ... )
936 va_start( args
, fmt
);
937 _vg_logx_va( stderr
, NULL
, "fatal", KRED
, fmt
, args
);
945 * Graphic cards will check these to force it to use the GPU
947 u32 NvOptimusEnablement
= 0x00000001;
948 int AmdPowerXpressRequestHighPerformance
= 1;
952 #endif /* VG_HEADER_H */