Skip to content

Commit

Permalink
Remove Switch (Kenix3#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
briaguya-ai authored Apr 29, 2024
1 parent 04066de commit 3d2e6bc
Show file tree
Hide file tree
Showing 18 changed files with 10 additions and 396 deletions.
7 changes: 0 additions & 7 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ if((CMAKE_SYSTEM_NAME MATCHES "Windows") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES
target_link_libraries(storm ${CLANG_RT_BUILTINS_LIBRARY})
endif()
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
target_compile_definitions(storm PRIVATE -D_POSIX_C_SOURCE=200809L)
endif()

#=================== ImGui ===================

Expand All @@ -44,10 +41,6 @@ target_sources(ImGui
${IMGUI_DIR}/imgui.cpp
)

if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
target_include_directories(ImGui PRIVATE ${DEVKITPRO}/portlibs/switch/include/)
endif()

target_sources(ImGui
PRIVATE
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
Expand Down
2 changes: 1 addition & 1 deletion extern/ImGui/backends/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_HOVERED
#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwSetWindowOpacity
#define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetMonitorContentScale
#if defined(__EMSCRIPTEN__) || defined(__SWITCH__) // no Vulkan support in GLFW for Emscripten or homebrew Nintendo Switch
#if defined(__EMSCRIPTEN__) // no Vulkan support in GLFW for Emscripten
#define GLFW_HAS_VULKAN (0)
#else
#define GLFW_HAS_VULKAN (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwCreateWindowSurface
Expand Down
11 changes: 0 additions & 11 deletions extern/ImGui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,3 @@ namespace ImGui
void MyFunction(const char* name, MyMatrix44* mtx);
}
*/

#ifdef __SWITCH__
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#define GL_GLEXT_PROTOTYPES 1
#include <glad/glad.h>

#define ImGuiKey_NavGamepadActivate ImGuiKey_GamepadFaceRight
#define ImGuiKey_NavGamepadCancel ImGuiKey_GamepadFaceDown
#define ImGuiKey_NavGamepadMenu ImGuiKey_GamepadFaceUp
#define ImGuiKey_NavGamepadInput ImGuiKey_GamepadFaceLeft
#endif
3 changes: 0 additions & 3 deletions include/libultraship/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@
#ifdef __APPLE__
#include "utils/AppleFolderManager.h"
#endif
#ifdef __SWITCH__
#include "port/switch/SwitchImpl.h"
#endif
#endif
#endif
12 changes: 3 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ target_sources(libultraship PRIVATE ${Source_Files__Utils__BinaryTools})

#=================== Port ===================

if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
set(Source_Files__Port
${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.h
${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchPerformanceProfiles.h
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
if (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(Source_Files__Port
${CMAKE_CURRENT_SOURCE_DIR}/port/mobile/MobileImpl.h
${CMAKE_CURRENT_SOURCE_DIR}/port/mobile/MobileImpl.cpp
Expand Down Expand Up @@ -179,7 +173,7 @@ target_include_directories(libultraship

#=================== Linking ===================

if (NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(libultraship PUBLIC "$<LINK_LIBRARY:WHOLE_ARCHIVE,storm>")
else()
target_link_libraries(libultraship PUBLIC storm)
Expand All @@ -201,7 +195,7 @@ target_link_libraries(libultraship PRIVATE libzip::zip)
find_package(nlohmann_json REQUIRED)
target_link_libraries(libultraship PUBLIC nlohmann_json::nlohmann_json)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(libultraship PRIVATE Threads::Threads)
Expand Down
9 changes: 0 additions & 9 deletions src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#ifdef __APPLE__
#include "utils/AppleFolderManager.h"
#elif defined(__SWITCH__)
#include "port/switch/SwitchImpl.h"
#endif

namespace Ship {
Expand Down Expand Up @@ -200,22 +198,15 @@ void Context::InitResourceManager(const std::vector<std::string>& otrFiles,
}

if (!GetResourceManager()->DidLoadSuccessfully()) {
#if defined(__SWITCH__)
printf("Main OTR file not found!\n");
#else
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OTR file not found",
"Main OTR file not found. Please generate one", nullptr);
SPDLOG_ERROR("Main OTR file not found!");
#ifdef __IOS__
// We need this exit to close the app when we dismiss the dialog
exit(0);
#endif
#endif
return;
}
#ifdef __SWITCH__
Ship::Switch::Init(PostInitPhase);
#endif
}

void Context::InitControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ std::shared_ptr<ControllerRumbleMapping> RumbleMappingFactory::CreateRumbleMappi
}

auto controller = SDL_GameControllerOpen(sdlIndex);
#ifdef __SWITCH__
bool hasRumble = false;
#else
bool hasRumble = SDL_GameControllerHasRumble(controller);
#endif

if (hasRumble) {
sdlControllersWithRumble[lusIndex] = SDL_GameControllerOpen(sdlIndex);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,8 @@ bool SDLMapping::UsesPlaystationLayout() {
}

bool SDLMapping::UsesSwitchLayout() {
#ifdef __SWITCH__
return true;
#else
auto type = GetSDLControllerType();
return type == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO || type == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR;
#endif
}

bool SDLMapping::UsesXboxLayout() {
Expand Down
7 changes: 2 additions & 5 deletions src/graphic/Fast3D/gfx_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#elif __APPLE__
#include <SDL2/SDL.h>
#include <GL/glew.h>
#elif __SWITCH__
#include <SDL2/SDL.h>
#include <glad/glad.h>
#elif USE_OPENGLES
#include <SDL2/SDL.h>
#include <GLES3/gl3.h>
Expand Down Expand Up @@ -752,7 +749,7 @@ static void gfx_opengl_upload_texture(const uint8_t* rgba32_buf, uint32_t width,
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba32_buf);
}

#if defined(__SWITCH__) || defined(USE_OPENGLES)
#ifdef USE_OPENGLES
#define GL_MIRROR_CLAMP_TO_EDGE 0x8743
#endif

Expand Down Expand Up @@ -847,7 +844,7 @@ static void gfx_opengl_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_
}

static void gfx_opengl_init(void) {
#if !defined(__SWITCH__) && !defined(__linux__)
#ifndef __linux__
glewInit();
#endif

Expand Down
41 changes: 0 additions & 41 deletions src/graphic/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include <stdio.h>

#ifndef __SWITCH__
#include "libultraship/libultraship.h"
#else
// including libultraship.h on switch leads to conflicting typedefs for u64 and s64
// so we need to just include classes.h instead here
#include "libultraship/classes.h"
#endif

#if defined(ENABLE_OPENGL) || defined(__APPLE__)

Expand All @@ -24,11 +18,6 @@
#elif __APPLE__
#include <SDL.h>
#include "gfx_metal.h"
#elif __SWITCH__
#include <SDL2/SDL.h>
#include <switch.h>
#include <glad/glad.h>
#include "port/switch/SwitchImpl.h"
#else
#include <SDL2/SDL.h>
#define GL_GLEXT_PROTOTYPES 1
Expand Down Expand Up @@ -333,10 +322,6 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#elif defined(__SWITCH__)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif

#ifdef _WIN32
Expand All @@ -351,13 +336,6 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s
char title[512];
int len = sprintf(title, "%s (%s)", game_name, gfx_api_name);

#ifdef __SWITCH__
// For Switch we need to set the window width before creating the window
Ship::Switch::GetDisplaySize(&window_width, &window_height);
width = window_width;
height = window_height;
#endif

#ifdef __IOS__
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_SHOWN;
#else
Expand Down Expand Up @@ -389,22 +367,14 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s
}

if (use_opengl) {
#ifndef __SWITCH__
SDL_GL_GetDrawableSize(wnd, &window_width, &window_height);

if (start_in_fullscreen) {
set_fullscreen(true, false);
}
#endif

ctx = SDL_GL_CreateContext(wnd);

#ifdef __SWITCH__
if (!gladLoadGLLoader(SDL_GL_GetProcAddress)) {
printf("Failed to initialize glad\n");
}
#endif

SDL_GL_MakeCurrent(wnd, ctx);
SDL_GL_SetSwapInterval(vsync_enabled ? 1 : 0);

Expand Down Expand Up @@ -468,16 +438,9 @@ static void gfx_sdl_set_keyboard_callbacks(bool (*on_key_down)(int scancode), bo
}

static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) {
#ifdef __SWITCH__
while (Ship::Switch::IsRunning()) {
#else
while (is_running) {
#endif
run_one_game_iter();
}
#ifdef __SWITCH__
Ship::Switch::Exit();
#endif

SDL_DestroyRenderer(renderer);
SDL_Quit();
Expand Down Expand Up @@ -535,11 +498,7 @@ static void gfx_sdl_handle_single_event(SDL_Event& event) {
#endif
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
#ifdef __SWITCH__
Ship::Switch::GetDisplaySize(&window_width, &window_height);
#else
SDL_GL_GetDrawableSize(wnd, &window_width, &window_height);
#endif
} else if (event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(wnd)) {
// We listen specifically for main window close because closing main window
// on macOS does not trigger SDL_Quit.
Expand Down
Loading

0 comments on commit 3d2e6bc

Please sign in to comment.