2023-07-30 19:18:50 +00:00
// ----------------------------------------------------------------------------
2023-08-10 14:30:56 +00:00
static void v4k_pre_init ( ) {
2023-10-14 19:47:24 +00:00
window_icon ( va ( " %s%s.png " , app_path ( ) , app_name ( ) ) ) ;
2023-07-30 19:18:50 +00:00
glfwPollEvents ( ) ;
int i ;
# pragma omp parallel for
2023-10-15 11:16:35 +00:00
for ( i = 0 ; i < = 3 ; + + i ) {
2023-07-30 19:18:50 +00:00
/**/ if ( i = = 0 ) ddraw_init ( ) ; // init this on thread#0 since it will be compiling shaders, and shaders need to be compiled from the very same thread than glfwMakeContextCurrent() was set up
else if ( i = = 1 ) sprite_init ( ) ;
2023-09-27 06:49:59 +00:00
else if ( i = = 2 ) profiler_init ( ) ;
2023-07-30 19:18:50 +00:00
else if ( i = = 3 ) storage_mount ( " save/ " ) , storage_read ( ) , touch_init ( ) ; // for ems
}
// window_swap();
}
2023-08-10 14:30:56 +00:00
static void v4k_post_init ( float refresh_rate ) {
2023-07-30 19:18:50 +00:00
// cook cleanup
cook_stop ( ) ;
vfs_reload ( ) ;
2023-10-14 19:47:24 +00:00
// init subsystems that depend on cooked assets now
2023-10-13 10:59:44 +00:00
2023-10-14 19:47:24 +00:00
int i ;
2023-07-30 19:18:50 +00:00
# pragma omp parallel for
2023-10-15 11:16:35 +00:00
for ( i = 0 ; i < = 3 ; + + i ) {
2023-10-14 19:47:24 +00:00
if ( i = = 0 ) scene_init ( ) ; // init these on thread #0, since both will be compiling shaders, and shaders need to be compiled from the very same thread than glfwMakeContextCurrent() was set up
2023-10-15 11:16:35 +00:00
if ( i = = 0 ) ui_init ( ) ; // init these on thread #0, since both will be compiling shaders, and shaders need to be compiled from the very same thread than glfwMakeContextCurrent() was set up
if ( i = = 0 ) window_icon ( va ( " %s.png " , app_name ( ) ) ) ; // init on thread #0, because of glfw
if ( i = = 0 ) input_init ( ) ; // init on thread #0, because of glfw
if ( i = = 1 ) audio_init ( 0 ) ;
if ( i = = 2 ) script_init ( ) , kit_init ( ) , midi_init ( ) ;
if ( i = = 3 ) network_init ( ) ;
2023-07-30 19:18:50 +00:00
}
// display window
glfwShowWindow ( window ) ;
glfwGetFramebufferSize ( window , & w , & h ) ; //glfwGetWindowSize(window, &w, &h);
randset ( time_ns ( ) ) ;
boot_time = - time_ss ( ) ; // measure boot time, this is continued in window_stats()
// clean any errno setup by cooking stage
errno = 0 ;
hz = refresh_rate ;
// t = glfwGetTime();
}
// ----------------------------------------------------------------------------
static
2023-08-10 14:30:56 +00:00
void v4k_quit ( void ) {
2023-07-30 19:18:50 +00:00
storage_flush ( ) ;
midi_quit ( ) ;
}
2023-08-10 14:30:56 +00:00
void v4k_init ( ) {
2023-07-30 19:18:50 +00:00
do_once {
// install signal handlers
2023-10-07 17:34:09 +00:00
ifdef ( debug , trap_install ( ) ) ;
2023-07-30 19:18:50 +00:00
// init panic handler
panic_oom_reserve = SYS_REALLOC ( panic_oom_reserve , 1 < < 20 ) ; // 1MiB
// init glfw
glfw_init ( ) ;
// enable ansi console
tty_init ( ) ;
// chdir to root (if invoked as tcc -g -run)
2023-10-09 15:05:56 +00:00
// chdir(app_path());
2023-07-30 19:18:50 +00:00
2023-08-10 14:30:56 +00:00
// skip tcc argvs (if invoked as tcc file.c v4k.c -g -run) (win)
2023-07-30 19:18:50 +00:00
if ( __argc > 1 ) if ( strstr ( __argv [ 0 ] , " /tcc " ) | | strstr ( __argv [ 0 ] , " \\ tcc " ) ) {
__argc = 0 ;
}
// create or update cook.zip file
2023-10-15 11:16:35 +00:00
if ( /* !COOK_ON_DEMAND && */ have_tools ( ) & & cook_jobs ( ) ) {
2023-07-30 19:18:50 +00:00
cook_start ( COOK_INI , " ** " , 0 | COOK_ASYNC | COOK_CANCELABLE ) ;
}
2023-08-10 14:30:56 +00:00
atexit ( v4k_quit ) ;
2023-07-30 19:18:50 +00:00
}
}