@@ -73,13 +73,20 @@ typedef struct
7373 thread_t thread ;
7474 mutex_t lock ;
7575 s32 divider ;
76+ bool threaded ;
7677
7778 struct
7879 {
7980 bool set ;
8081 bool async ;
8182 } fullscreen ;
8283
84+ struct
85+ {
86+ char title [TICNAME_MAX ];
87+ bool async ;
88+ } window ;
89+
8390} App ;
8491
8592#define LOCK (X ) lock(X); SCOPE(unlock(X))
@@ -156,7 +163,9 @@ bool tic_sys_fullscreen_get(void *userdata)
156163
157164void tic_sys_title (const char * title )
158165{
159- sapp_set_window_title (title );
166+ App * app = sapp_userdata ();
167+ app -> window .async = true;
168+ strcpy (app -> window .title , title );
160169}
161170
162171void tic_sys_addfile (void (* callback )(void * userdata , const char * name , const u8 * buffer , s32 size ), void * userdata )
@@ -569,36 +578,52 @@ static void drawImage(Rect r,sg_image image, sg_sampler sampler)
569578
570579static void checkrate (App * app )
571580{
572- s32 refreshrate = 1.0 / sapp_frame_duration ();
573-
574- // check monitor refresh rate +-5Hz
575- if (refreshrate == CLAMP (refreshrate , TIC80_FRAMERATE - 5 , TIC80_FRAMERATE + 5 ))
576- {
577- #if defined(__TIC_EMSCRIPTEN__ )
578- emscripten_set_main_loop_timing (EM_TIMING_RAF , 1 );
579- #else
580- // use every frame on 60Hz
581- app -> divider = 1 ;
582- #endif
583- }
584- else if (refreshrate == CLAMP (refreshrate , 2 * TIC80_FRAMERATE - 5 , 2 * TIC80_FRAMERATE + 5 ))
581+ if (app -> threaded )
585582 {
586- #if defined(__TIC_EMSCRIPTEN__ )
587- emscripten_set_main_loop_timing (EM_TIMING_RAF , 2 );
588- #else
589- // use every 2nd frame on 120Hz
590- app -> divider = 2 ;
591- #endif
583+ #if defined(__TIC_EMSCRIPTEN__ )
584+ emscripten_set_main_loop_timing (EM_TIMING_SETTIMEOUT , 1000 / TIC80_FRAMERATE );
585+ #else
586+ // use separate thread to call tick
587+ if (!app -> thread )
588+ {
589+ mutex_init (& app -> lock );
590+ thread_create (& app -> thread , loop , app );
591+ }
592+ #endif
592593 }
593594 else
594595 {
595- #if defined(__TIC_EMSCRIPTEN__ )
596- emscripten_set_main_loop_timing (EM_TIMING_SETTIMEOUT , 1000 / TIC80_FRAMERATE );
597- #else
598- // use separate thread to call tick
599- mutex_init (& app -> lock );
600- thread_create (& app -> thread , loop , app );
601- #endif
596+ s32 refreshrate = 1.0 / sapp_frame_duration ();
597+
598+ // check monitor refresh rate +-5Hz
599+ if (refreshrate == CLAMP (refreshrate , TIC80_FRAMERATE - 5 , TIC80_FRAMERATE + 5 ))
600+ {
601+ #if defined(__TIC_EMSCRIPTEN__ )
602+ emscripten_set_main_loop_timing (EM_TIMING_RAF , 1 );
603+ #else
604+ // use every frame on 60Hz
605+ app -> divider = 1 ;
606+ #endif
607+ }
608+ else if (refreshrate == CLAMP (refreshrate , 2 * TIC80_FRAMERATE - 5 , 2 * TIC80_FRAMERATE + 5 ))
609+ {
610+ #if defined(__TIC_EMSCRIPTEN__ )
611+ emscripten_set_main_loop_timing (EM_TIMING_RAF , 2 );
612+ #else
613+ // use every 2nd frame on 120Hz
614+ app -> divider = 2 ;
615+ #endif
616+ }
617+ else
618+ {
619+ #if defined(__TIC_EMSCRIPTEN__ )
620+ emscripten_set_main_loop_timing (EM_TIMING_SETTIMEOUT , 1000 / TIC80_FRAMERATE );
621+ #else
622+ // use separate thread to call tick
623+ mutex_init (& app -> lock );
624+ thread_create (& app -> thread , loop , app );
625+ #endif
626+ }
602627 }
603628}
604629
@@ -948,6 +973,12 @@ static void event(const sapp_event* event, void *userdata)
948973 app -> fullscreen .set = sapp_is_fullscreen ();
949974#endif
950975 }
976+
977+ if (app -> window .async )
978+ {
979+ app -> window .async = false;
980+ sapp_set_window_title (app -> window .title );
981+ }
951982}
952983
953984static void cleanup (void * userdata )
@@ -1033,8 +1064,12 @@ sapp_desc sokol_start(s32 argc, char* argv[])
10331064
10341065 bool cli = false;
10351066 for (s32 i = 0 ; i < argc ; i ++ )
1067+ {
10361068 if (strcmp (argv [i ], "--cli" ) == 0 )
10371069 cli = true;
1070+ else if (strcmp (argv [i ], "--threaded" ) == 0 )
1071+ app -> threaded = true;
1072+ }
10381073
10391074 if (!cli )
10401075 {
0 commit comments