mirror of
https://github.com/luanti-org/luanti.git
synced 2025-12-19 05:15:47 +01:00
IrrlichtMt: Initial SDL3 support (#16583)
This commit implements support for SDL3, more specifically, >= 3.2.0 (the first released version). Almost all changes were made according to https://github.com/libsdl-org/SDL/blob/release-3.2.10/docs/README-migration.md?plain=1 and the suggestions provided by `SDL3/SDL_oldnames.h`.
This commit is contained in:
@@ -16,7 +16,13 @@
|
||||
#include <emscripten/html5.h>
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_USE_SDL3_
|
||||
#define SDL_DISABLE_OLD_NAMES
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_mouse.h>
|
||||
#else
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
@@ -99,12 +105,7 @@ public:
|
||||
}
|
||||
|
||||
//! Get the SDL version
|
||||
std::string getVersionString() const override
|
||||
{
|
||||
SDL_version ver;
|
||||
SDL_GetVersion(&ver);
|
||||
return std::to_string(ver.major) + "." + std::to_string(ver.minor) + "." + std::to_string(ver.patch);
|
||||
}
|
||||
std::string getVersionString() const override;
|
||||
|
||||
//! Get the display density in dots per inch.
|
||||
float getDisplayDensity() const override;
|
||||
@@ -125,11 +126,14 @@ public:
|
||||
void setVisible(bool visible) override
|
||||
{
|
||||
IsVisible = visible;
|
||||
#ifdef _IRR_USE_SDL3_
|
||||
if (visible)
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
else {
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
SDL_ShowCursor();
|
||||
else
|
||||
SDL_HideCursor();
|
||||
#else
|
||||
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Returns if the cursor is currently visible.
|
||||
@@ -166,8 +170,11 @@ public:
|
||||
static_cast<int>(x / Device->ScaleX),
|
||||
static_cast<int>(y / Device->ScaleY));
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_USE_SDL3_
|
||||
if (SDL_GetWindowRelativeMouseMode(Device->Window)) {
|
||||
#else
|
||||
if (SDL_GetRelativeMouseMode()) {
|
||||
#endif
|
||||
// There won't be an event for this warp (details on libsdl-org/SDL/issues/6034)
|
||||
Device->MouseX = x;
|
||||
Device->MouseY = y;
|
||||
@@ -197,13 +204,16 @@ public:
|
||||
|
||||
virtual void setRelativeMode(bool relative) override
|
||||
{
|
||||
#ifdef _IRR_USE_SDL3_
|
||||
if (relative != (bool)SDL_GetWindowRelativeMouseMode(Device->Window)) {
|
||||
SDL_SetWindowRelativeMouseMode(Device->Window, relative);
|
||||
}
|
||||
#else
|
||||
// Only change it when necessary, as it flushes mouse motion when enabled
|
||||
if (relative != static_cast<bool>(SDL_GetRelativeMouseMode())) {
|
||||
if (relative)
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
else
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void setActiveIcon(gui::ECURSOR_ICON iconId) override
|
||||
@@ -263,8 +273,13 @@ public:
|
||||
{
|
||||
void operator()(SDL_Cursor *ptr)
|
||||
{
|
||||
#ifdef _IRR_USE_SDL3_
|
||||
if (ptr)
|
||||
SDL_DestroyCursor(ptr);
|
||||
#else
|
||||
if (ptr)
|
||||
SDL_FreeCursor(ptr);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
std::vector<std::unique_ptr<SDL_Cursor, CursorDeleter>> Cursors;
|
||||
@@ -282,7 +297,7 @@ private:
|
||||
static bool keyIsKnownSpecial(EKEY_CODE irrlichtKey);
|
||||
|
||||
// Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0).
|
||||
static int findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtKey, bool numlock);
|
||||
static wchar_t findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtKey, u16 keymod);
|
||||
|
||||
std::variant<u32, EKEY_CODE> getScancodeFromKey(const Keycode &key) const override;
|
||||
Keycode getKeyFromScancode(const u32 scancode) const override;
|
||||
@@ -316,7 +331,9 @@ private:
|
||||
|
||||
bool Resizable;
|
||||
|
||||
#ifndef _IRR_USE_SDL3_
|
||||
static u32 getFullscreenFlag(bool fullscreen);
|
||||
#endif // SDL3: Replaced by boolean
|
||||
|
||||
core::rect<s32> lastElemPos;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user