diff --git a/CMakeLists.txt b/CMakeLists.txt index 68bc94cd..8d5e0de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,6 @@ endif() option(BUILD_LIBRETRO "Build libretro core" OFF) option(BUILD_TOOLS "Build tools" OFF) option(BUILD_TESTS "Build tests" OFF) -option(ENABLE_MICROPROFILE "Enable MicroProfile" ON) if(WIN32 OR MINGW) set(PLATFORM_WINDOWS TRUE) @@ -98,6 +97,18 @@ list(APPEND REDREAM_INCLUDES deps/glew-1.13.0/include) list(APPEND REDREAM_LIBS glew_s) list(APPEND REDREAM_DEFS GLEW_STATIC) +# inih +add_library(inih STATIC deps/inih/ini.c) +list(APPEND REDREAM_INCLUDES deps/inih) +list(APPEND REDREAM_LIBS inih) + +# xbyak +list(APPEND REDREAM_INCLUDES deps/xbyak-4.901) + +#-------------------------------------------------- +# optional libs +#-------------------------------------------------- + # imgui add_library(imgui STATIC deps/cimgui/imgui/imgui.cpp @@ -108,22 +119,10 @@ add_library(imgui STATIC deps/cimgui/cimgui/fontAtlas.cpp deps/cimgui/cimgui/listClipper.cpp) list(APPEND REDREAM_INCLUDES deps/cimgui) -list(APPEND REDREAM_LIBS imgui) - -# inih -add_library(inih STATIC deps/inih/ini.c) -list(APPEND REDREAM_INCLUDES deps/inih) -list(APPEND REDREAM_LIBS inih) +list(APPEND IMGUI_LIBS imgui) # microprofile -list(APPEND MICROPROFILE_INCLUDES deps/microprofile) - -# xbyak -list(APPEND REDREAM_INCLUDES deps/xbyak-4.901) - -#-------------------------------------------------- -# optional libs -#-------------------------------------------------- +list(APPEND REDREAM_INCLUDES deps/microprofile) # sdl2 if(NOT BUILD_LIBRETRO) @@ -142,7 +141,7 @@ if(APPLE) set(SDL_FRAMEWORK_CARBON 1) endif() add_subdirectory(deps/sdl2-2.0.5 EXCLUDE_FROM_ALL) -list(APPEND SDL_INCLUDE_DIRS deps/sdl2-2.0.5/include) +list(APPEND REDREAM_INCLUDES deps/sdl2-2.0.5/include) if(MINGW) list(APPEND SDL_LIBS mingw32) endif() @@ -341,15 +340,18 @@ set(REDREAM_SDL_SOURCES source_group_by_dir(REDREAM_SDL_SOURCES) add_executable(redream ${REDREAM_SDL_SOURCES}) -target_include_directories(redream SYSTEM PUBLIC ${REDREAM_INCLUDES} ${MICROPROFILE_INCLUDE_DIRS} ${SDL_INCLUDE_DIRS}) +target_include_directories(redream SYSTEM PUBLIC ${REDREAM_INCLUDES}) target_include_directories(redream PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) target_link_libraries(redream ${REDREAM_LIBS} ${SDL_LIBS}) target_compile_definitions(redream PRIVATE ${REDREAM_DEFS}) target_compile_options(redream PRIVATE ${REDREAM_FLAGS}) -if(ENABLE_MICROPROFILE) - target_compile_definitions(redream PRIVATE ENABLE_MICROPROFILE=1) -endif() +# enable imgui +target_link_libraries(redream ${IMGUI_LIBS}) +target_compile_definitions(redream PRIVATE ENABLE_IMGUI=1) + +# enable microprofile +target_compile_definitions(redream PRIVATE ENABLE_MICROPROFILE=1) #-------------------------------------------------- # recc diff --git a/src/emulator.c b/src/emulator.c index 9e6d258b..d20c7fba 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -453,6 +453,7 @@ static void emu_paint(struct emu *emu) { r_end_ui_surfaces(emu->r); } +#if ENABLE_IMGUI if (emu->debug_menu) { if (igBeginMainMenuBar()) { if (igBeginMenu("DEBUG", 1)) { @@ -503,6 +504,7 @@ static void emu_paint(struct emu *emu) { igEndMainMenuBar(); } } +#endif imgui_render(emu->imgui); mp_render(emu->mp); diff --git a/src/guest/aica/aica.c b/src/guest/aica/aica.c index 5ac75582..51cc3c74 100644 --- a/src/guest/aica/aica.c +++ b/src/guest/aica/aica.c @@ -835,6 +835,7 @@ void aica_set_clock(struct aica *aica, uint32_t time) { aica->rtc = time; } +#if ENABLE_IMGUI void aica_debug_menu(struct aica *aica) { if (igBeginMainMenuBar()) { if (igBeginMenu("AICA", 1)) { @@ -851,6 +852,7 @@ void aica_debug_menu(struct aica *aica) { igEndMainMenuBar(); } } +#endif void aica_destroy(struct aica *aica) { /* shutdown rtc */ diff --git a/src/guest/bios/bios.c b/src/guest/bios/bios.c index 417e2063..cf464891 100644 --- a/src/guest/bios/bios.c +++ b/src/guest/bios/bios.c @@ -329,6 +329,7 @@ static int bios_boot(struct bios *bios) { return 1; } +#if ENABLE_IMGUI void bios_debug_menu(struct bios *bios) { int changed = 0; @@ -382,6 +383,7 @@ void bios_debug_menu(struct bios *bios) { LOG_WARNING("bios settings changed, restart for changes to take effect"); } } +#endif int bios_invalid_instr(struct bios *bios) { struct dreamcast *dc = bios->dc; diff --git a/src/guest/holly/holly.c b/src/guest/holly/holly.c index 8f7d5f47..e2145f53 100644 --- a/src/guest/holly/holly.c +++ b/src/guest/holly/holly.c @@ -325,6 +325,7 @@ void holly_raise_interrupt(struct holly *hl, holly_interrupt_t intr) { } } +#if ENABLE_IMGUI void holly_debug_menu(struct holly *hl) { if (igBeginMainMenuBar()) { if (igBeginMenu("HOLLY", 1)) { @@ -350,6 +351,7 @@ void holly_debug_menu(struct holly *hl) { igEndMainMenuBar(); } } +#endif void holly_destroy(struct holly *hl) { dc_destroy_device((struct device *)hl); diff --git a/src/guest/sh4/sh4.c b/src/guest/sh4/sh4.c index 584f99dd..5a6d7dd6 100644 --- a/src/guest/sh4/sh4.c +++ b/src/guest/sh4/sh4.c @@ -209,6 +209,7 @@ void sh4_reset(struct sh4 *sh4, uint32_t pc) { sh4->execute_if->running = 1; } +#if ENABLE_IMGUI void sh4_debug_menu(struct sh4 *sh4) { struct jit *jit = sh4->jit; @@ -235,6 +236,7 @@ void sh4_debug_menu(struct sh4 *sh4) { igEndMainMenuBar(); } } +#endif void sh4_destroy(struct sh4 *sh4) { jit_destroy(sh4->jit); diff --git a/src/render/imgui.cc b/src/render/imgui.cc index 0f60444d..48277480 100644 --- a/src/render/imgui.cc +++ b/src/render/imgui.cc @@ -1,4 +1,6 @@ +#if ENABLE_IMGUI #include +#endif extern "C" { #include "core/assert.h" @@ -14,6 +16,7 @@ struct imgui { }; extern "C" void imgui_render(struct imgui *imgui) { +#if ENABLE_IMGUI ImGuiIO &io = ImGui::GetIO(); /* update draw batches. note, this doesn't _actually_ render anything because @@ -61,9 +64,11 @@ extern "C" void imgui_render(struct imgui *imgui) { r_end_ui_surfaces(imgui->r); } +#endif } extern "C" void imgui_update_input(struct imgui *imgui) { +#if ENABLE_IMGUI ImGuiIO &io = ImGui::GetIO(); int width = r_viewport_width(imgui->r); @@ -75,10 +80,12 @@ extern "C" void imgui_update_input(struct imgui *imgui) { /* reset mouse scroll state */ io.MouseWheel = 0.0; +#endif } extern "C" void imgui_keydown(struct imgui *imgui, enum keycode code, int16_t value) { +#if ENABLE_IMGUI ImGuiIO &io = ImGui::GetIO(); if (code == K_MWHEELUP) { @@ -91,7 +98,6 @@ extern "C" void imgui_keydown(struct imgui *imgui, enum keycode code, io.MouseDown[1] = value > 0; } else if (code == K_MOUSE3) { io.MouseDown[2] = value > 0; - ; } else if (code == K_LALT || code == K_RALT) { imgui->alt[code == K_LALT ? 0 : 1] = !!value; io.KeyAlt = imgui->alt[0] || imgui->alt[1]; @@ -104,21 +110,27 @@ extern "C" void imgui_keydown(struct imgui *imgui, enum keycode code, } else { io.KeysDown[code] = value > 0; } +#endif } extern "C" void imgui_mousemove(struct imgui *imgui, int x, int y) { +#if ENABLE_IMGUI ImGuiIO &io = ImGui::GetIO(); io.MousePos = ImVec2((float)x, (float)y); +#endif } extern "C" void imgui_destroy(struct imgui *imgui) { +#if ENABLE_IMGUI ImGui::Shutdown(); free(imgui); +#endif } extern "C" struct imgui *imgui_create(struct render_backend *r) { +#if ENABLE_IMGUI struct imgui *imgui = reinterpret_cast(calloc(1, sizeof(struct imgui))); @@ -168,4 +180,7 @@ extern "C" struct imgui *imgui_create(struct render_backend *r) { io.Fonts->TexID = reinterpret_cast(static_cast(handle)); return imgui; +#else + return NULL; +#endif } diff --git a/src/render/imgui.h b/src/render/imgui.h index c34e87ba..14fac79e 100644 --- a/src/render/imgui.h +++ b/src/render/imgui.h @@ -1,9 +1,12 @@ #ifndef IMGUI_H #define IMGUI_H +#include "host/keycode.h" + +#if ENABLE_IMGUI #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS #include -#include "host/keycode.h" +#endif struct imgui; struct render_backend; diff --git a/src/render/microprofile.cc b/src/render/microprofile.cc index f5688ec7..996a9705 100644 --- a/src/render/microprofile.cc +++ b/src/render/microprofile.cc @@ -275,16 +275,16 @@ void mp_keydown(struct microprofile *mp, enum keycode key, int16_t value) { void mp_destroy(struct microprofile *mp) { #if ENABLE_MICROPROFILE r_destroy_texture(mp->r, mp->font_texture); -#endif free(mp); +#endif } struct microprofile *mp_create(struct render_backend *r) { +#if ENABLE_MICROPROFILE struct microprofile *mp = reinterpret_cast( calloc(1, sizeof(struct microprofile))); -#if ENABLE_MICROPROFILE mp->r = r; /* register and enable cpu and gpu groups by default */ @@ -305,9 +305,11 @@ struct microprofile *mp_create(struct render_backend *r) { r_create_texture(mp->r, PXL_RGBA, FILTER_NEAREST, WRAP_CLAMP_TO_EDGE, WRAP_CLAMP_TO_EDGE, 0, FONT_WIDTH, FONT_HEIGHT, reinterpret_cast(s_font_data)); -#endif return mp; +#else + return NULL; +#endif } /* microprofile expects the following three functions to be defined, they're