Skip to content

Commit

Permalink
Update to SDL3
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschwarzer committed Feb 2, 2025
1 parent e5ff5b7 commit 9faab1e
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 68 deletions.
2 changes: 1 addition & 1 deletion projects/Core/api/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Modloader/windows_api/common.h>

#include <Core/settings.h>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

using namespace modloader;
using namespace app::classes;
Expand Down
2 changes: 1 addition & 1 deletion projects/Core/api/game/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <Modloader/app/types/PlayerUberStateGroup.h>
#include <Modloader/app/types/UI_Cameras.h>
#include <Modloader/modloader.h>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

using namespace modloader;
using namespace app::classes;
Expand Down
2 changes: 1 addition & 1 deletion projects/Core/ipc/console.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Modloader/modloader.h>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

#include <nlohmann/json.hpp>
#include <string>
Expand Down
8 changes: 2 additions & 6 deletions projects/Randomizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,8 @@ target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)

target_link_libraries(${PROJECT_NAME} protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)

find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(
${PROJECT_NAME}
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
)
find_package(SDL3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} SDL3::SDL3)

message(STATUS "Assigning source groups.")

Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/dev/console_seed_debugger.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>
#include <Modloader/modloader.h>
#include <Modloader/windows_api/console.h>
#include <Randomizer/dev/seed_debugger.h>
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/dev/seed_debugger.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>
#include <Randomizer/randomizer.h>
#include <Randomizer/dev/seed_debugger.h>
#include <Randomizer/seed/items/item.h>
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/input/controller_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <Modloader/modloader.h>

#include <algorithm>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>
#include <nlohmann/json.hpp>
#include <unordered_map>
#include <unordered_set>
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/input/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Modloader/modloader.h>

#include <fstream>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>
#include <nlohmann/json.hpp>
#include <string>

Expand Down
82 changes: 42 additions & 40 deletions projects/Randomizer/input/sdl_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@
#include <Modloader/app/methods/IntroLogosSkip.h>
#include <Modloader/app/methods/System/TimeSpan.h>
#include <Modloader/app/types/TimeSpan.h>
#include <sdl2/SDL.h>
#include <SDL3/SDL.h>

namespace {
using namespace app::classes;

bool enable_native_controller_support = false;
SDL_GameController* controller = nullptr;
SDL_Gamepad* controller = nullptr;

void detect_controller() {
if (controller != nullptr) {
SDL_GameControllerClose(controller);
SDL_CloseGamepad(controller);
}

for (int i = 0; i < SDL_NumJoysticks(); i++) {
if (SDL_IsGameController(i)) {
controller = SDL_GameControllerOpen(i);
SDL_GameControllerSetLED(controller, 255, 255, 255);
SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 225);
modloader::info("sdl_input", "Controller connected");
int joystick_count;
const auto joysticks = SDL_GetJoysticks(&joystick_count);

for (int i = 0; i < joystick_count; i++) {
if (SDL_IsGamepad(joysticks[i])) {
controller = SDL_OpenGamepad(joysticks[i]);
SDL_SetGamepadLED(controller, 255, 255, 255);
SDL_RumbleGamepad(controller, 0xFFFF, 0xFFFF, 225);
SDL_RumbleGamepadTriggers(controller, 0xFFFF, 0xFFFF, 225);
modloader::info("sdl_input", "Gamepad connected");
return;
}
}
Expand All @@ -40,10 +44,8 @@ namespace {
enable_native_controller_support = core::settings::native_controller_support_enabled();

if (enable_native_controller_support) {
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");

if (auto sdl_init_error = SDL_Init(SDL_INIT_GAMECONTROLLER); sdl_init_error < 0) {
modloader::error("sdl_input", std::format("Failed to initialize SDL, error {}", sdl_init_error));
if (!SDL_Init(SDL_INIT_GAMEPAD)) {
modloader::error("sdl_input", std::format("Failed to initialize SDL, error {}", SDL_GetError()));
}

modloader::info("sdl_input", "SDL initialized");
Expand Down Expand Up @@ -79,7 +81,7 @@ namespace {

SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_CONTROLLERDEVICEADDED || event.type == SDL_CONTROLLERDEVICEREMOVED) {
if (event.type == SDL_EVENT_GAMEPAD_ADDED || event.type == SDL_EVENT_GAMEPAD_REMOVED) {
detect_controller();
}
}
Expand All @@ -100,38 +102,38 @@ namespace {
this_ptr->fields.gamepadStatePrev.Gamepad.wButtons = this_ptr->fields.gamepadStateCurrent.Gamepad.wButtons;
this_ptr->fields.gamepadStatePrev.PacketNumber = this_ptr->fields.gamepadStateCurrent.PacketNumber;

this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbLX = SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTX);
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbLY = static_cast<short>(~SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTY));
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbRX = SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbRY = static_cast<short>(~SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY));
this_ptr->fields.gamepadStateCurrent.Gamepad.bLeftTrigger = SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERLEFT) / 128;
this_ptr->fields.gamepadStateCurrent.Gamepad.bRightTrigger = SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) / 128;
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbLX = SDL_GetGamepadAxis(controller, SDL_GAMEPAD_AXIS_LEFTX);
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbLY = static_cast<short>(~SDL_GetGamepadAxis(controller, SDL_GAMEPAD_AXIS_LEFTY));
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbRX = SDL_GetGamepadAxis(controller, SDL_GAMEPAD_AXIS_RIGHTX);
this_ptr->fields.gamepadStateCurrent.Gamepad.sThumbRY = static_cast<short>(~SDL_GetGamepadAxis(controller, SDL_GAMEPAD_AXIS_RIGHTY));
this_ptr->fields.gamepadStateCurrent.Gamepad.bLeftTrigger = SDL_GetGamepadAxis(controller, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) / 128;
this_ptr->fields.gamepadStateCurrent.Gamepad.bRightTrigger = SDL_GetGamepadAxis(controller, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) / 128;
this_ptr->fields.gamepadStateCurrent.Gamepad.wButtons = static_cast<short>(
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_UP) << 0) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN) << 1) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT) << 2) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT) << 3) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_START) << 4) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_BACK) << 5) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_LEFTSTICK) << 6) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_RIGHTSTICK) << 7) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_LEFTSHOULDER) << 8) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) << 9) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_A) << 12) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_B) << 13) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_X) << 14) +
(SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_Y) << 15)
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_DPAD_UP) << 0) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_DPAD_DOWN) << 1) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_DPAD_LEFT) << 2) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_DPAD_RIGHT) << 3) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_START) << 4) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_BACK) << 5) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_LEFT_STICK) << 6) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_RIGHT_STICK) << 7) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER) << 8) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER) << 9) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_SOUTH) << 12) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_EAST) << 13) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_WEST) << 14) +
(SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_NORTH) << 15)
);
this_ptr->fields.gamepadStateCurrent.PacketNumber++;

// Emulate Start/Select on touchpad
if (SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_TOUCHPAD)) {
uint8_t state;
if (SDL_GetGamepadButton(controller, SDL_GAMEPAD_BUTTON_TOUCHPAD)) {
bool state;
float x, y, pressure;
SDL_GameControllerGetTouchpadFinger(controller, 0, 0, &state, &x, &y, &pressure);
SDL_GetGamepadTouchpadFinger(controller, 0, 0, &state, &x, &y, &pressure);

this_ptr->fields.gamepadStateCurrent.Gamepad.wButtons |=
(state != 1 || x >= 0.5 /* right side touchpad */)
(!state || x >= 0.5 /* right side touchpad */)
? (1u << 4u) // Start
: (1u << 5u); // Select
}
Expand All @@ -149,7 +151,7 @@ namespace {
return;
}

// We can ignore the length parameter since XBoxControllerManager will call this function periodically anyways
SDL_GameControllerRumble(controller, left_motor * 0xFFFF, right_motor * 0xFFFF, 100);
// We can ignore the length parameter since XBoxControllerManager will call this function periodically anyway
SDL_RumbleGamepad(controller, left_motor * 0xFFFF, right_motor * 0xFFFF, 100);
}
}
2 changes: 1 addition & 1 deletion projects/Randomizer/location_data/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <Randomizer/location_data/parser.h>

#include <fstream>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

namespace randomizer::location_data {
bool parse_location_data(std::filesystem::path path, location_data_emitter emitter) {
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/seed/items/icon_override.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Randomizer/seed/items/icon_override.h>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

namespace randomizer::seed::items {
void SetIconOverride::grant() {
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/seed/items/input.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Randomizer/input/rando_bindings.h>
#include <Randomizer/seed/items/input.h>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

namespace randomizer::seed::items {
void Input::grant() {
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/seed/items/refill.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>
#include <Randomizer/seed/items/refill.h>

#include <Core/api/game/player.h>
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/seed/legacy_parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Randomizer/seed/items/icon_override.h>
#include <fstream>
#include <iostream>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>
#include <regex>
#include <span>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/state_data/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Randomizer/state_data/parser.h>

#include <fstream>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

namespace randomizer::state_data {
bool parse_state_data(std::filesystem::path path, std::unordered_map<core::api::uber_states::UberStateCondition, std::string>& states) {
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/ui/main_menu_seed_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Randomizer/game/spawning_and_preloading.h>
#include <Randomizer/randomizer.h>
#include <Randomizer/seed/legacy_parser/parser.h>
#include <magic_enum.hpp>
#include <magic_enum/magic_enum.hpp>

using namespace utils;
using namespace app::classes;
Expand Down
22 changes: 14 additions & 8 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "wotw-rando-client",
"version-string" : "1.0.0",
"builtin-baseline" : "cd5e746ec203c8c3c61647e0886a8df8c1e78e41",
"builtin-baseline" : "0ca64b4e1c70fa6d9f53b369b8f3f0843797c20c",
"dependencies" : [ {
"name" : "stb",
"version>=" : "2024-07-29#1"
Expand Down Expand Up @@ -37,14 +37,20 @@
}, {
"name" : "openssl",
"version>=" : "3.4.0"
}, {
"name" : "protobuf",
"version>=" : "3.21.12#4"
}, {
"name" : "sdl2",
"version>=" : "2.30.8"
}, {
"name" : "stduuid",
"version>=" : "1.2.3"
} ]
}, {
"name" : "sdl3",
"version>=" : "3.2.0"
}, {
"name" : "protobuf",
"version>=" : "3.21.12#4"
} ],
"overrides": [
{
"name": "protobuf",
"version": "3.21.12#4"
}
]
}

0 comments on commit 9faab1e

Please sign in to comment.