Skip to content

Commit

Permalink
Added SPELUNKY_PSP_WITH_IMGUI compile definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeef committed Dec 17, 2023
1 parent c9c2965 commit 99e95d8
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmake/DependenciesDarwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ macro(add_darwin_dependencies)
target_compile_definitions(Dependencies INTERFACE
SPELUNKY_PSP_PLATFORM_DARWIN
SPELUNKY_PSP_PLATFORM_DESKTOP
SPELUNKY_PSP_WITH_IMGUI
)
set(SPELUNKY_PSP_WITH_IMGUI TRUE)
endmacro()

macro(spelunky_psp_post_build_darwin)
Expand Down
3 changes: 3 additions & 0 deletions cmake/DependenciesLinux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ macro(add_linux_dependencies)

add_library(Dependencies INTERFACE)
target_link_libraries(Dependencies INTERFACE SDL_2_XX)
# TODO: Separate target, i.e PlatformDefinitions
target_compile_definitions(Dependencies INTERFACE
SPELUNKY_PSP_PLATFORM_LINUX
SPELUNKY_PSP_PLATFORM_DESKTOP
SPELUNKY_PSP_WITH_IMGUI
)
set(SPELUNKY_PSP_WITH_IMGUI TRUE)
endmacro()

macro(spelunky_psp_post_build_linux)
Expand Down
4 changes: 3 additions & 1 deletion cmake/DependenciesWindows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ macro(add_windows_dependencies)
target_compile_definitions(Dependencies INTERFACE
SPELUNKY_PSP_PLATFORM_WINDOWS
SPELUNKY_PSP_PLATFORM_DESKTOP
)
SPELUNKY_PSP_WITH_IMGUI
)
set(SPELUNKY_PSP_WITH_IMGUI TRUE)
endmacro()

macro(spelunky_psp_post_build_windows)
Expand Down
3 changes: 2 additions & 1 deletion src/game-loop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,6 @@ target_link_libraries(GameLoop
Audio
glad
GraphicsUtils
imgui
$<$<BOOL:${SPELUNKY_PSP_WITH_IMGUI}>:imgui>
Dependencies
)
14 changes: 12 additions & 2 deletions src/game-loop/src/prefabs/ui/CheatConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
#include "components/generic/ScriptingComponent.hpp"
#include "components/generic/ImguiComponent.hpp"
#include "logger/log.h"
#include "imgui_impl_opengl2.h"
#include "imgui_impl_sdl2.h"
#include "Input.hpp"
#include "prefabs/npc/RedFrog.hpp"
#include "components/specialized/MainDudeComponent.hpp"
#include "game-loop/GameLoop.hpp"

// TODO: Better way to handle this than if-defing as there will be more imgui-components
#if defined(SPELUNKY_PSP_WITH_IMGUI)
#include "imgui_impl_opengl2.h"
#include "imgui_impl_sdl2.h"

namespace {
// Based on ImGui's example console:
static int Stricmp(const char *s1, const char *s2) {
Expand Down Expand Up @@ -309,6 +312,13 @@ namespace {
const std::function<void()> dont_render_callback = [](){};
};
}
#else
class CheatConsoleScript final : public ScriptBase {
public:
explicit CheatConsoleScript(entt::entity self) { }
void update(entt::entity owner, uint32_t delta_time_ms) override { }
};
#endif

namespace prefabs {

Expand Down
9 changes: 7 additions & 2 deletions src/game-loop/src/system/RenderingSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "components/generic/QuadComponent.hpp"
#include "components/generic/MeshComponent.hpp"
#include "components/generic/BlinkingComponent.hpp"
#include "imgui_impl_opengl2.h"
#include "imgui_impl_sdl2.h"
#include "components/generic/ImguiComponent.hpp"

void RenderingSystem::update(std::uint32_t delta_time_ms)
Expand Down Expand Up @@ -141,6 +139,10 @@ void RenderingSystem::update_opengl(std::uint32_t delta_time_ms) {
});
}

#if defined(SPELUNKY_PSP_WITH_IMGUI)
#include "imgui_impl_opengl2.h"
#include "imgui_impl_sdl2.h"

void RenderingSystem::update_imgui() {

ImGui_ImplOpenGL2_NewFrame();
Expand All @@ -161,3 +163,6 @@ void RenderingSystem::update_imgui() {
ImGui_ImplOpenGL2_RenderDrawData(draw_data);
}
}
#else
void RenderingSystem::update_imgui() {}
#endif
3 changes: 2 additions & 1 deletion src/input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ target_link_libraries(Input
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>:SDL_2_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>:SDL_1_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>:SDL_1_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_DESKTOP}>:imgui>
$<$<BOOL:${SPELUNKY_PSP_WITH_IMGUI}>:imgui>
Dependencies
)
11 changes: 9 additions & 2 deletions src/input/src/Input_Desktop.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#include "Input.hpp"

#include <SDL2/SDL_events.h>
#include "imgui_impl_sdl2.h"

#if defined(SPELUNKY_PSP_WITH_IMGUI)
#include "imgui_impl_sdl2.h"
void imgui_event_processing(const SDL_Event* event) { ImGui_ImplSDL2_ProcessEvent(event); }
#else
void imgui_event_processing(const SDL_Event* event) {}
#endif


const char* Input::get_pause_binding_msg()
{
Expand Down Expand Up @@ -52,7 +59,7 @@ void Input::poll()

while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
imgui_event_processing(&event);
if (event.type == SDL_EventType::SDL_KEYDOWN || event.type == SDL_EventType::SDL_KEYUP)
{
const auto& key = event.key.keysym.sym;
Expand Down
3 changes: 2 additions & 1 deletion src/video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ target_link_libraries(Video
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_DARWIN}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_ANDROID}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_DESKTOP}>,imgui,>
$<IF:$<BOOL:${SPELUNKY_PSP_WITH_IMGUI}>,imgui,>
Dependencies
)
7 changes: 7 additions & 0 deletions src/video/src/Video_Desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <SDL2/SDL_video.h>
#include <stdexcept>

#if defined(SPELUNKY_PSP_WITH_IMGUI)
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_opengl2.h"
Expand Down Expand Up @@ -37,7 +38,13 @@ namespace {
ImGui::DestroyContext();
}
};
}
#else
struct Imgui { Imgui(SDL_Window *window, void *gl_context) {}};
#endif

namespace
{
std::pair<int, int> query_screen_dimensions() {
SDL_DisplayMode dm;
if (SDL_GetDesktopDisplayMode(0, &dm) != 0)
Expand Down
2 changes: 1 addition & 1 deletion vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ add_subdirectory(glad)
add_subdirectory(cjson)
add_subdirectory(entt)

if (SPELUNKY_PSP_PLATFORM_DESKTOP)
if (SPELUNKY_PSP_WITH_IMGUI)
add_subdirectory(imgui)
endif()

0 comments on commit 99e95d8

Please sign in to comment.