mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-12-22 16:30:23 +00:00
Optional updates for the loading screen (#87)
- added support for WAPI_DXGI (now only WAPI_DUMMY does not render the loading screen)
This commit is contained in:
parent
fe114133ff
commit
75ce4e1d1d
4 changed files with 43 additions and 34 deletions
|
@ -1,8 +1,11 @@
|
|||
#include "loading.h"
|
||||
|
||||
#ifdef LOADING_SCREEN_SUPPORTED
|
||||
|
||||
#include "djui/djui.h"
|
||||
#include "pc/djui/djui_unicode.h"
|
||||
|
||||
#include "pc_main.h"
|
||||
#include "loading.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/cliopts.h"
|
||||
#include "rom_checker.h"
|
||||
|
@ -19,13 +22,12 @@ struct LoadingScreen {
|
|||
};
|
||||
|
||||
static struct LoadingScreen* sLoading = NULL;
|
||||
|
||||
pthread_t gLoadingThreadId;
|
||||
pthread_mutex_t gLoadingThreadMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool gIsThreaded = false;
|
||||
|
||||
#define RUN_THREADED if (gIsThreaded)
|
||||
|
||||
void loading_screen_set_segment_text(const char* text) {
|
||||
snprintf(gCurrLoadingSegment.str, 256, text);
|
||||
}
|
||||
|
@ -39,7 +41,7 @@ static void loading_screen_produce_one_frame(void) {
|
|||
}
|
||||
|
||||
static bool loading_screen_on_render(struct DjuiBase* base) {
|
||||
RUN_THREADED { pthread_mutex_lock(&gLoadingThreadMutex); }
|
||||
if (gIsThreaded) { pthread_mutex_lock(&gLoadingThreadMutex); }
|
||||
|
||||
u32 windowWidth, windowHeight;
|
||||
WAPI.get_dimensions(&windowWidth, &windowHeight);
|
||||
|
@ -76,7 +78,7 @@ static bool loading_screen_on_render(struct DjuiBase* base) {
|
|||
|
||||
djui_base_compute(base);
|
||||
|
||||
RUN_THREADED { pthread_mutex_unlock(&gLoadingThreadMutex); }
|
||||
if (gIsThreaded) { pthread_mutex_unlock(&gLoadingThreadMutex); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -87,7 +89,7 @@ static void loading_screen_destroy(struct DjuiBase* base) {
|
|||
sLoading = NULL;
|
||||
}
|
||||
|
||||
void init_loading_screen(void) {
|
||||
static void init_loading_screen(void) {
|
||||
struct LoadingScreen* load = calloc(1, sizeof(struct LoadingScreen));
|
||||
struct DjuiBase* base = &load->base;
|
||||
|
||||
|
@ -134,7 +136,10 @@ void init_loading_screen(void) {
|
|||
}
|
||||
|
||||
void loading_screen_reset(void) {
|
||||
djui_base_destroy(&sLoading->base);
|
||||
if (sLoading) {
|
||||
djui_base_destroy(&sLoading->base);
|
||||
sLoading = NULL;
|
||||
}
|
||||
djui_shutdown();
|
||||
alloc_display_list_reset();
|
||||
gDisplayListHead = NULL;
|
||||
|
@ -151,9 +156,6 @@ void render_loading_screen(void) {
|
|||
}
|
||||
|
||||
pthread_join(gLoadingThreadId, NULL);
|
||||
gIsThreaded = false;
|
||||
|
||||
loading_screen_reset();
|
||||
}
|
||||
|
||||
void render_rom_setup_screen(void) {
|
||||
|
@ -165,3 +167,5 @@ void render_rom_setup_screen(void) {
|
|||
WAPI.main_loop(loading_screen_produce_one_frame);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#ifndef LOADING_HEADER
|
||||
#define LOADING_HEADER
|
||||
|
||||
#if !defined(WAPI_DUMMY)
|
||||
#define LOADING_SCREEN_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef LOADING_SCREEN_SUPPORTED
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "cliopts.h"
|
||||
|
@ -13,21 +19,12 @@ struct LoadingSegment {
|
|||
|
||||
extern struct LoadingSegment gCurrLoadingSegment;
|
||||
|
||||
extern bool gIsThreaded;
|
||||
|
||||
#if !defined(WAPI_DXGI) && !defined(WAPI_DUMMY)
|
||||
#define LOADING_SCREEN_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef LOADING_SCREEN_SUPPORTED
|
||||
#define LOADING_SCREEN_MUTEX(...) if (!gCLIOpts.hideLoadingScreen && gIsThreaded) { \
|
||||
pthread_mutex_lock(&gLoadingThreadMutex); \
|
||||
__VA_ARGS__; \
|
||||
pthread_mutex_unlock(&gLoadingThreadMutex); \
|
||||
}
|
||||
#else
|
||||
#define LOADING_SCREEN_MUTEX(...)
|
||||
#endif
|
||||
#define LOADING_SCREEN_MUTEX(...) \
|
||||
if (!gCLIOpts.hideLoadingScreen && gIsThreaded) { \
|
||||
pthread_mutex_lock(&gLoadingThreadMutex); \
|
||||
__VA_ARGS__; \
|
||||
pthread_mutex_unlock(&gLoadingThreadMutex); \
|
||||
}
|
||||
|
||||
extern pthread_t gLoadingThreadId;
|
||||
extern pthread_mutex_t gLoadingThreadMutex;
|
||||
|
@ -36,6 +33,13 @@ extern bool gIsThreaded;
|
|||
|
||||
void loading_screen_set_segment_text(const char* text);
|
||||
void render_loading_screen(void);
|
||||
void loading_screen_reset(void);
|
||||
void render_rom_setup_screen(void);
|
||||
|
||||
#else // LOADING_SCREEN_SUPPORTED
|
||||
|
||||
#define LOADING_SCREEN_MUTEX(...)
|
||||
|
||||
#endif // LOADING_SCREEN_SUPPORTED
|
||||
|
||||
#endif
|
||||
|
|
|
@ -308,9 +308,7 @@ void game_exit(void) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void* main_game_init(void* isThreaded) {
|
||||
gIsThreaded = isThreaded != NULL;
|
||||
|
||||
void* main_game_init(UNUSED void*) {
|
||||
// load language
|
||||
if (!djui_language_init(configLanguage)) { snprintf(configLanguage, MAX_CONFIG_STRING, "%s", ""); }
|
||||
|
||||
|
@ -337,11 +335,6 @@ void* main_game_init(void* isThreaded) {
|
|||
if (gCLIOpts.fullscreen == 1) { configWindow.fullscreen = true; }
|
||||
else if (gCLIOpts.fullscreen == 2) { configWindow.fullscreen = false; }
|
||||
|
||||
if (!gGfxInited) {
|
||||
gfx_init(&WAPI, &RAPI, TITLE);
|
||||
WAPI.set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up, keyboard_on_text_input);
|
||||
}
|
||||
|
||||
audio_init();
|
||||
sound_init();
|
||||
smlua_audio_custom_init();
|
||||
|
@ -403,10 +396,12 @@ int main(int argc, char *argv[]) {
|
|||
#ifdef LOADING_SCREEN_SUPPORTED
|
||||
bool threadSuccess = false;
|
||||
if (!gCLIOpts.hideLoadingScreen && pthread_mutex_init(&gLoadingThreadMutex, NULL) == 0) {
|
||||
if (pthread_create(&gLoadingThreadId, NULL, main_game_init, (void*) 1) == 0) {
|
||||
gIsThreaded = true;
|
||||
if (pthread_create(&gLoadingThreadId, NULL, main_game_init, NULL) == 0) {
|
||||
render_loading_screen(); // render the loading screen while the game is setup
|
||||
threadSuccess = true;
|
||||
}
|
||||
gIsThreaded = false;
|
||||
pthread_mutex_destroy(&gLoadingThreadMutex);
|
||||
}
|
||||
if (!threadSuccess)
|
||||
|
@ -424,6 +419,10 @@ int main(int argc, char *argv[]) {
|
|||
#endif
|
||||
if (!audio_api) { audio_api = &audio_null; }
|
||||
|
||||
#ifdef LOADING_SCREEN_SUPPORTED
|
||||
loading_screen_reset();
|
||||
#endif
|
||||
|
||||
// initialize djui
|
||||
djui_init();
|
||||
djui_unicode_init();
|
||||
|
|
|
@ -100,6 +100,7 @@ bool main_rom_handler(void) {
|
|||
return gRomIsValid;
|
||||
}
|
||||
|
||||
#ifdef LOADING_SCREEN_SUPPORTED
|
||||
void rom_on_drop_file(const char *path) {
|
||||
static bool hasDroppedInvalidFile = false;
|
||||
if (strlen(path) > 0) {
|
||||
|
@ -109,4 +110,5 @@ void rom_on_drop_file(const char *path) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue