diff --git a/Makefile b/Makefile index da1a55e..7b610e7 100644 --- a/Makefile +++ b/Makefile @@ -491,7 +491,7 @@ PLATFORM_CFLAGS += -DNO_SEGMENTED_MEMORY -DUSE_SYSTEM_MALLOC # Compiler and linker flags for graphics backend ifeq ($(ENABLE_OPENGL),1) # TODO: right now the opengl and vulkan backends are linked, will seperate later... - GFX_CFLAGS := -DENABLE_OPENGL -DENABLE_VULKAN + GFX_CFLAGS := -DENABLE_OPENGL -DENABLE_VULKAN -DENABLE_GFX_DUMMY GFX_LDFLAGS := ifeq ($(TARGET_WINDOWS),1) GFX_CFLAGS += $(shell sdl2-config --cflags) -DGLEW_STATIC diff --git a/src/pc/gfx/gfx_dummy.c b/src/pc/gfx/gfx_dummy.c index c9c644a..2ae23bf 100644 --- a/src/pc/gfx/gfx_dummy.c +++ b/src/pc/gfx/gfx_dummy.c @@ -151,6 +151,10 @@ static void gfx_dummy_renderer_end_frame(void) { static void gfx_dummy_renderer_finish_render(void) { } +const char* gfx_dummy_get_name(void) { + return "Dummy"; +} + struct GfxWindowManagerAPI gfx_dummy_wm_api = { gfx_dummy_wm_init, gfx_dummy_wm_set_keyboard_callbacks, @@ -187,6 +191,7 @@ struct GfxRenderingAPI gfx_dummy_renderer_api = { gfx_dummy_renderer_on_resize, gfx_dummy_renderer_start_frame, gfx_dummy_renderer_end_frame, - gfx_dummy_renderer_finish_render + gfx_dummy_renderer_finish_render, + gfx_dummy_get_name }; #endif diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 0c53f17..a5568a2 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -1,4 +1,5 @@ #include +#include #ifdef TARGET_WEB #include @@ -100,39 +101,6 @@ void produce_one_frame(void) { gfx_end_frame(); } -#ifdef TARGET_WEB -static void em_main_loop(void) { -} - -static void request_anim_frame(void (*func)(double time)) { - EM_ASM(requestAnimationFrame(function(time) { - dynCall("vd", $0, [time]); - }), func); -} - -static void on_anim_frame(double time) { - static double target_time; - - time *= 0.03; // milliseconds to frame count (33.333 ms -> 1) - - if (time >= target_time + 10.0) { - // We are lagging 10 frames behind, probably due to coming back after inactivity, - // so reset, with a small margin to avoid potential jitter later. - target_time = time - 0.010; - } - - for (int i = 0; i < 2; i++) { - // If refresh rate is 15 Hz or something we might need to generate two frames - if (time >= target_time) { - produce_one_frame(); - target_time = target_time + 1.0; - } - } - - request_anim_frame(on_anim_frame); -} -#endif - static void save_config(void) { configfile_save(CONFIG_FILE); } @@ -141,7 +109,7 @@ static void on_fullscreen_changed(bool is_now_fullscreen) { configFullscreen = is_now_fullscreen; } -void main_func(void) { +int main(int argc, char *argv[]) { #ifdef USE_SYSTEM_MALLOC main_pool_init(); gGfxAllocOnlyPool = alloc_only_pool_init(); @@ -154,35 +122,48 @@ void main_func(void) { configfile_load(CONFIG_FILE); atexit(save_config); -#ifdef TARGET_WEB - emscripten_set_main_loop(em_main_loop, 0, 0); - request_anim_frame(on_anim_frame); -#endif + int ogl_vulkan_dummy = 0; + + for(int i = 1; i < argc; i++) { + if(strcmp(argv[i], "-opengl") == 0) { + ogl_vulkan_dummy = 0; + } + + if(strcmp(argv[i], "-vulkan") == 0) { + ogl_vulkan_dummy = 1; + } + + if(strcmp(argv[i], "-dummy") == 0) { + ogl_vulkan_dummy = 2; + } + } -#if defined(ENABLE_DX12) - rendering_api = &gfx_direct3d12_api; - wm_api = &gfx_dxgi_api; -#elif defined(ENABLE_DX11) - rendering_api = &gfx_direct3d11_api; - wm_api = &gfx_dxgi_api; -#elif defined(ENABLE_OPENGL) - rendering_api = &gfx_vulkan_api; wm_api = &gfx_sdl; -#elif defined(ENABLE_GFX_DUMMY) - rendering_api = &gfx_dummy_renderer_api; - wm_api = &gfx_dummy_wm_api; -#endif - gfx_init(wm_api, rendering_api, "Super Mario 64 PC-Port", configFullscreen); - + switch(ogl_vulkan_dummy) { + case 0: + { + rendering_api = &gfx_opengl_api; + } + break; + case 1: + { + rendering_api = &gfx_vulkan_api; + } + break; + case 2: + { + rendering_api = &gfx_dummy_renderer_api; + } + break; + } + + + gfx_init(wm_api, rendering_api, "Super Mario 64", configFullscreen); + wm_api->set_fullscreen_changed_callback(on_fullscreen_changed); wm_api->set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up); - -#if HAVE_WASAPI - if (audio_api == NULL && audio_wasapi.init()) { - audio_api = &audio_wasapi; - } -#endif + #if HAVE_PULSE_AUDIO if (audio_api == NULL && audio_pulse.init()) { audio_api = &audio_pulse; @@ -193,11 +174,7 @@ void main_func(void) { audio_api = &audio_alsa; } #endif -#ifdef TARGET_WEB - if (audio_api == NULL && audio_sdl.init()) { - audio_api = &audio_sdl; - } -#endif + if (audio_api == NULL) { audio_api = &audio_null; } @@ -206,28 +183,10 @@ void main_func(void) { sound_init(); thread5_game_loop(NULL); -#ifdef TARGET_WEB - /*for (int i = 0; i < atoi(argv[1]); i++) { - game_loop_one_iteration(); - }*/ - inited = 1; -#else inited = 1; while (1) { wm_api->main_loop(produce_one_frame); } -#endif -} -#if defined(_WIN32) || defined(_WIN64) -#include -int WINAPI WinMain(UNUSED HINSTANCE hInstance, UNUSED HINSTANCE hPrevInstance, UNUSED LPSTR pCmdLine, UNUSED int nCmdShow) { - main_func(); return 0; -} -#else -int main(UNUSED int argc, UNUSED char *argv[]) { - main_func(); - return 0; -} -#endif +} \ No newline at end of file