Skip to content

Commit f05cba6

Browse files
committed
Port to SDL3
1 parent 53a328c commit f05cba6

20 files changed

+42
-41
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ else()
3939
endif()
4040

4141
find_package(fmt CONFIG REQUIRED)
42-
find_package(SDL2 CONFIG REQUIRED)
42+
find_package(SDL3 CONFIG REQUIRED)
4343
find_package(libtcod CONFIG REQUIRED)
4444
target_link_libraries(
4545
${PROJECT_NAME}
4646
PUBLIC
4747
fmt::fmt
48-
SDL2::SDL2
48+
SDL3::SDL3
4949
libtcod::libtcod
5050
)
5151
add_library(umbra::umbra ALIAS ${PROJECT_NAME})

src/demo/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ else()
2424
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra)
2525
endif()
2626

27-
find_package(SDL2 CONFIG REQUIRED)
27+
find_package(SDL3 CONFIG REQUIRED)
2828
find_package(libtcod CONFIG REQUIRED)
2929
target_link_libraries(
3030
${PROJECT_NAME}
3131
PRIVATE
32-
SDL2::SDL2
33-
SDL2::SDL2main
32+
SDL3::SDL3
3433
libtcod::libtcod
3534
umbra::umbra
3635
)

src/demo/circle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class Circle : public UmbraModule {
3535
void onEvent(const SDL_Event& ev) override {
3636
TCOD_mouse_t tcod_mouse{};
3737
tcod::sdl2::process_event(ev, tcod_mouse);
38-
if (ev.type == SDL_MOUSEMOTION) isGreen = circle.contains(tcod_mouse.cx, tcod_mouse.cy);
39-
if (isGreen && ev.type == SDL_MOUSEBUTTONDOWN && ev.button.button == SDL_BUTTON_LEFT) {
38+
if (ev.type == SDL_EVENT_MOUSE_MOTION) isGreen = circle.contains(tcod_mouse.cx, tcod_mouse.cy);
39+
if (isGreen && ev.type == SDL_EVENT_MOUSE_BUTTON_DOWN && ev.button.button == SDL_BUTTON_LEFT) {
4040
setActive(false);
4141
}
4242
}

src/demo/demo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void Demo::render() {
6363
}
6464

6565
void Demo::onEvent(const SDL_Event& ev) {
66-
if (ev.type == SDL_KEYDOWN) {
67-
switch (ev.key.keysym.sym) {
66+
if (ev.type == SDL_EVENT_KEY_DOWN) {
67+
switch (ev.key.key) {
6868
case SDLK_SPACE:
6969
getEngine()->activateModule(666);
7070
break;

src/demo/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28-
#include <SDL.h>
28+
#include <SDL3/SDL_main.h>
2929
#include <stdio.h>
3030

3131
#include "circle.hpp"

src/demo/matrix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
#include "matrix.hpp"
2828

29-
#include <SDL_timer.h>
29+
#include <SDL3/SDL_timer.h>
3030
#include <stdio.h>
3131

3232
#include "globals.hpp"
@@ -38,7 +38,7 @@ constexpr std::array CHARACTERS{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'
3838
'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
3939

4040
bool Matrix::update() {
41-
const auto now = SDL_GetTicks64();
41+
const auto now = SDL_GetTicks();
4242
if (next_lead_ms <= now) {
4343
next_lead_ms = now + rng() % 200;
4444
auto& new_lead = leads.emplace_back();
@@ -50,7 +50,7 @@ bool Matrix::update() {
5050
}
5151

5252
void Matrix::render() {
53-
const auto now = SDL_GetTicks64();
53+
const auto now = SDL_GetTicks();
5454
// Advance leads.
5555
for (auto& lead : leads) {
5656
if (lead.next_y_ms <= now) {

src/demo/panel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
#include "panel.hpp"
2828

29-
#include <SDL_timer.h>
29+
#include <SDL3/SDL_timer.h>
3030

3131
#include <algorithm>
3232

@@ -43,7 +43,7 @@ void Panel::render() {
4343
}
4444

4545
bool Panel::update() {
46-
const uint64_t time = SDL_GetTicks64();
46+
const uint64_t time = SDL_GetTicks();
4747
if (rect.mouseHover) {
4848
lastHover = time;
4949
posx += 3;

src/umbra/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void UmbraConfig::registerFont(const UmbraFont& new_font) {
161161
}
162162

163163
bool UmbraConfig::activateFont(int shift) {
164-
int s = CLAMP(-1, 1, shift);
164+
int s = std::clamp(shift, -1, 1);
165165
// check if there are any registered fonts
166166
if (fonts.size() == 0)
167167
return false; // can happen if a user uses the default terminal.png without registering any font

src/umbra/engine.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
*/
2727
#include "engine.hpp"
2828

29-
#include <SDL_events.h>
30-
#include <SDL_timer.h>
29+
#include <SDL3/SDL_events.h>
30+
#include <SDL3/SDL_timer.h>
3131
#include <fmt/core.h>
3232
#include <stdarg.h>
3333
#include <stdio.h>
@@ -173,11 +173,11 @@ class UmbraModuleConfigParser : public ITCODParserListener {
173173
void error(const char* msg) override { UmbraLog::error(fmt::format("UmbraModuleConfigParser | {}", msg)); }
174174
};
175175

176-
int UmbraEngine::onSDLEvent(void* userdata, SDL_Event* event) {
176+
bool UmbraEngine::onSDLEvent(void* userdata, SDL_Event* event) {
177177
auto self = static_cast<UmbraEngine*>(userdata);
178178
for (auto& module : self->activeModules) module->onEvent(*event);
179-
if (event->type == SDL_QUIT) self->deactivateAll();
180-
return 0;
179+
if (event->type == SDL_EVENT_QUIT) self->deactivateAll();
180+
return true;
181181
};
182182

183183
UmbraEngine::UmbraEngine(const char* fileName, UmbraRegisterCallbackFlag flag) {
@@ -206,7 +206,7 @@ UmbraEngine::UmbraEngine(const char* fileName, UmbraRegisterCallbackFlag flag) {
206206
SDL_AddEventWatch(onSDLEvent, this);
207207
}
208208

209-
UmbraEngine::~UmbraEngine() { SDL_DelEventWatch(onSDLEvent, this); }
209+
UmbraEngine::~UmbraEngine() { SDL_RemoveEventWatch(onSDLEvent, this); }
210210

211211
void UmbraEngine::setWindowTitle(std::string title) { windowTitle = title; }
212212

src/umbra/engine.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#ifndef UMBRA_ENGINE_HPP
2828
#define UMBRA_ENGINE_HPP
2929

30-
#include <SDL_events.h>
30+
#include <SDL3/SDL_events.h>
3131
#include <fmt/printf.h>
3232
#include <libtcod/console_types.h>
3333

@@ -399,7 +399,7 @@ class UmbraEngine {
399399
*/
400400
void registerInternalModule(UmbraInternalModuleID id, UmbraModule* module);
401401
/// @brief SDL event watcher.
402-
static int onSDLEvent(void* userdata, SDL_Event* event);
402+
static bool onSDLEvent(void* userdata, SDL_Event* event);
403403
};
404404

405405
#endif

0 commit comments

Comments
 (0)