Skip to content

Commit 981d415

Browse files
committed
threaded mode fixes
1 parent e814e16 commit 981d415

File tree

7 files changed

+39
-47
lines changed

7 files changed

+39
-47
lines changed

src/studio/screens/mainmenu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@ bool studio_mainmenu_keyboard(StudioMainMenu* main)
9090

9191
static s32 optionFullscreenGet(void* data)
9292
{
93-
StudioMainMenu* main = data;
94-
return tic_sys_fullscreen_get(studioUserdata(main->studio)) ? 1 : 0;
93+
return tic_sys_fullscreen_get() ? 1 : 0;
9594
}
9695

9796
static void optionFullscreenSet(void* data, s32 pos)
9897
{
9998
StudioMainMenu* main = data;
100-
tic_sys_fullscreen_set(main->options->fullscreen = (pos == 1), studioUserdata(main->studio));
99+
tic_sys_fullscreen_set(main->options->fullscreen = (pos == 1));
101100
}
102101

103102
static const char OffValue[] = "OFF";

src/studio/studio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ static inline bool keyWasPressedOnce(Studio* studio, s32 key)
17781778

17791779
static void gotoFullscreen(Studio* studio)
17801780
{
1781-
tic_sys_fullscreen_set(studio->config->data.options.fullscreen = !tic_sys_fullscreen_get(studioUserdata(studio)), studio->userdata);
1781+
tic_sys_fullscreen_set(studio->config->data.options.fullscreen = !tic_sys_fullscreen_get());
17821782
}
17831783

17841784
static void switchCrtMonitor(Studio* studio)

src/studio/system.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ char* tic_sys_clipboard_get();
5757
void tic_sys_clipboard_free(char* text);
5858
u64 tic_sys_counter_get();
5959
u64 tic_sys_freq_get();
60-
bool tic_sys_fullscreen_get(void *userdata);
61-
void tic_sys_fullscreen_set(bool value, void *userdata);
60+
bool tic_sys_fullscreen_get();
61+
void tic_sys_fullscreen_set(bool value);
6262
void tic_sys_title(const char* title);
6363
void tic_sys_addfile(void(*callback)(void* userdata, const char* name, const u8* buffer, s32 size), void* userdata);
6464
void tic_sys_getfile(const char* name, const void* buffer, s32 size);

src/system/baremetalpi/kernel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ u64 tic_sys_freq_get()
111111
return HZ;
112112
}
113113

114-
void tic_sys_fullscreen_set(bool value, void *userdata)
114+
void tic_sys_fullscreen_set(bool value)
115115
{
116116
}
117117

118-
bool tic_sys_fullscreen_get(void *userdata)
118+
bool tic_sys_fullscreen_get()
119119
{
120120
return false;
121121
}

src/system/n3ds/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ u64 tic_sys_freq_get()
191191
return SYSCLOCK_ARM11;
192192
}
193193

194-
void tic_sys_fullscreen_set(bool value, void *userdata)
194+
void tic_sys_fullscreen_set(bool value)
195195
{
196196
}
197197

198-
bool tic_sys_fullscreen_get(void *userdata)
198+
bool tic_sys_fullscreen_get()
199199
{
200200
return false;
201201
}

src/system/sdl/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ u64 tic_sys_freq_get()
14111411
return SDL_GetPerformanceFrequency();
14121412
}
14131413

1414-
bool tic_sys_fullscreen_get(void* userdata)
1414+
bool tic_sys_fullscreen_get()
14151415
{
14161416
#if defined(CRT_SHADER_SUPPORT)
14171417
if(!studio_config(platform.studio)->soft)
@@ -1426,7 +1426,7 @@ bool tic_sys_fullscreen_get(void* userdata)
14261426
}
14271427
}
14281428

1429-
void tic_sys_fullscreen_set(bool value, void *userdata)
1429+
void tic_sys_fullscreen_set(bool value)
14301430
{
14311431
#if defined(CRT_SHADER_SUPPORT)
14321432
if(!studio_config(platform.studio)->soft)
@@ -2000,7 +2000,7 @@ static s32 start(s32 argc, char **argv, const char* folder)
20002000
#endif
20012001

20022002
if(studio_config(platform.studio)->options.fullscreen)
2003-
tic_sys_fullscreen_set(true, platform.studio);
2003+
tic_sys_fullscreen_set(true);
20042004
}
20052005

20062006
SDL_PauseAudioDevice(platform.audio.device, 0);

src/system/sokol/main.c

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ typedef struct
8383

8484
struct
8585
{
86-
char title[TICNAME_MAX];
86+
char data[TICNAME_MAX];
8787
bool async;
88-
} window;
88+
} title;
8989

9090
} App;
9191

@@ -148,24 +148,24 @@ u64 tic_sys_freq_get()
148148
return 1e9;
149149
}
150150

151-
void tic_sys_fullscreen_set(bool value, void *userdata)
151+
void tic_sys_fullscreen_set(bool value)
152152
{
153-
App *app = userdata;
153+
App *app = sapp_userdata();
154154
app->fullscreen.async = true;
155155
app->fullscreen.set = !app->fullscreen.set;
156156
}
157157

158-
bool tic_sys_fullscreen_get(void *userdata)
158+
bool tic_sys_fullscreen_get()
159159
{
160-
App *app = userdata;
160+
App *app = sapp_userdata();
161161
return app->fullscreen.set;
162162
}
163163

164164
void tic_sys_title(const char* title)
165165
{
166166
App *app = sapp_userdata();
167-
app->window.async = true;
168-
strcpy(app->window.title, title);
167+
app->title.async = true;
168+
strcpy(app->title.data, title);
169169
}
170170

171171
void tic_sys_addfile(void(*callback)(void* userdata, const char* name, const u8* buffer, s32 size), void* userdata)
@@ -576,22 +576,23 @@ static void drawImage(Rect r,sg_image image, sg_sampler sampler)
576576
sgl_disable_texture();
577577
}
578578

579-
static void checkrate(App* app)
579+
static void threadedMode(App* app)
580580
{
581-
if(app->threaded)
581+
#if defined(__TIC_EMSCRIPTEN__)
582+
emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, 1000 / TIC80_FRAMERATE);
583+
#else
584+
// use separate thread to call tick
585+
if(!app->thread)
582586
{
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
587+
mutex_init(&app->lock);
588+
thread_create(&app->thread, loop, app);
593589
}
594-
else
590+
#endif
591+
}
592+
593+
static void checkrate(App* app)
594+
{
595+
if(!app->threaded)
595596
{
596597
float refresh_rate = 1.0f / sapp_frame_duration();
597598
float target = refresh_rate / (float)TIC80_FRAMERATE;
@@ -606,17 +607,9 @@ static void checkrate(App* app)
606607
app->divider = div;
607608
#endif
608609
}
609-
else
610-
{
611-
#if defined(__TIC_EMSCRIPTEN__)
612-
emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, 1000 / TIC80_FRAMERATE);
613-
#else
614-
// use separate thread to call tick
615-
mutex_init(&app->lock);
616-
thread_create(&app->thread, loop, app);
617-
#endif
618-
}
610+
else threadedMode(app);
619611
}
612+
else threadedMode(app);
620613
}
621614

622615
static void frame(void *userdata)
@@ -966,10 +959,10 @@ static void event(const sapp_event* event, void *userdata)
966959
#endif
967960
}
968961

969-
if(app->window.async)
962+
if(app->title.async)
970963
{
971-
app->window.async = false;
972-
sapp_set_window_title(app->window.title);
964+
app->title.async = false;
965+
sapp_set_window_title(app->title.data);
973966
}
974967
}
975968

0 commit comments

Comments
 (0)