Skip to content

Commit

Permalink
SDL 2.0.18 is now the required minimum (OpenXRay#1683)
Browse files Browse the repository at this point in the history
Remove redundant SDL_VERSION_ATLEAST for versions <= 2.0.18
  • Loading branch information
sobkas authored May 27, 2024
1 parent 2f5c1d9 commit a29ea70
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 77 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ add_compile_definitions(
)

if (NOT WIN32)
find_package(SDL2 REQUIRED)
find_package(SDL2 2.0.18 REQUIRED)
# Fix to support older SDL2
# https://github.com/OpenXRay/xray-16/issues/1595
if (NOT TARGET SDL2::SDL2 AND DEFINED SDL2_LIBRARIES)
Expand Down
16 changes: 0 additions & 16 deletions src/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,11 @@ XRCORE_API bool HasSSE = SDL_HasSSE();
XRCORE_API bool HasSSE2 = SDL_HasSSE2();
XRCORE_API bool HasSSE42 = SDL_HasSSE42();

#if SDL_VERSION_ATLEAST(2, 0, 6)
XRCORE_API bool HasAVX = SDL_HasAVX();
#else
XRCORE_API bool HasAVX = false();
#endif

#if SDL_VERSION_ATLEAST(2, 0, 9)
XRCORE_API bool HasAVX2 = SDL_HasAVX2();
#else
XRCORE_API bool HasAVX2 = false;
#endif

#if SDL_VERSION_ATLEAST(2, 0, 9)
XRCORE_API bool HasAVX512F = SDL_HasAVX512F();
#else
XRCORE_API bool HasAVX512F = false;
#endif

XRCORE_API u64 qpc_freq = SDL_GetPerformanceFrequency();

Expand Down Expand Up @@ -85,12 +73,8 @@ void _initialize_cpu()

// Other architectures
listFeature("AltiVec", SDL_HasAltiVec());
#if SDL_VERSION_ATLEAST(2, 0, 12)
listFeature("ARMSIMD", SDL_HasARMSIMD());
#endif
#if SDL_VERSION_ATLEAST(2, 0, 6)
listFeature("NEON", SDL_HasNEON());
#endif
#if SDL_VERSION_ATLEAST(2, 24, 0)
listFeature("LSX", SDL_HasLSX());
listFeature("LASX", SDL_HasLASX());
Expand Down
4 changes: 0 additions & 4 deletions src/xrEngine/Device_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ void CRenderDevice::InitializeImGui()
// See SDL hack in ImGui_ImplSDL2_ShowWindow().
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon) ? SDL_WINDOW_SKIP_TASKBAR : 0;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 5)
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0;
#endif

const auto vd = IM_NEW(ImGuiViewportData)
{
Expand Down Expand Up @@ -192,13 +190,11 @@ void CRenderDevice::InitializeImGui()
SDL_SetWindowTitle(vd->Window, title);
};

#if SDL_VERSION_ATLEAST(2, 0, 5)
platform_io.Platform_SetWindowAlpha = [](ImGuiViewport* viewport, float alpha)
{
const auto vd = static_cast<ImGuiViewportData*>(viewport->PlatformUserData);
SDL_SetWindowOpacity(vd->Window, alpha);
};
#endif
#endif // IMGUI_ENABLE_VIEWPORTS

editor().InitBackend();
Expand Down
10 changes: 0 additions & 10 deletions src/xrEngine/Device_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ void FillImGuiMonitorData(const int monitorID)
monitor.MainPos = monitor.WorkPos = ImVec2((float)r.x, (float)r.y);
monitor.MainSize = monitor.WorkSize = ImVec2((float)r.w, (float)r.h);

#if SDL_VERSION_ATLEAST(2, 0, 5)
SDL_GetDisplayUsableBounds(monitorID, &r);
monitor.WorkPos = ImVec2((float)r.x, (float)r.y);
monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
#endif

#if SDL_VERSION_ATLEAST(2, 0, 4)
// FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set
// DpiScale to cocoa_window.backingScaleFactor here.
float dpi = 0.0f;
if (!SDL_GetDisplayDPI(monitorID, &dpi, nullptr, nullptr))
monitor.DpiScale = dpi / 96.0f;
#endif

monitor.PlatformHandle = (void*)(intptr_t)monitorID;
platform_io.Monitors.push_back(monitor);
Expand Down Expand Up @@ -107,9 +103,7 @@ void CRenderDevice::SetWindowDraggable(bool draggable)
const bool resizable = SDL_GetWindowFlags(Device.m_sdlWnd) & SDL_WINDOW_RESIZABLE;
m_allowWindowDrag = draggable && windowed && resizable;

#if SDL_VERSION_ATLEAST(2, 0, 5)
SDL_SetWindowOpacity(Device.m_sdlWnd, m_allowWindowDrag ? 0.95f : 1.0f);
#endif
}

void CRenderDevice::UpdateWindowProps()
Expand Down Expand Up @@ -180,14 +174,12 @@ void CRenderDevice::UpdateWindowRects()
SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowBounds.x, &m_rcWindowBounds.y);
SDL_GetWindowSize(m_sdlWnd, &m_rcWindowBounds.w, &m_rcWindowBounds.h);

#if SDL_VERSION_ATLEAST(2, 0, 5)
int top, left, bottom, right;
SDL_GetWindowBordersSize(m_sdlWnd, &top, &left, &bottom, &right);
m_rcWindowBounds.x -= left;
m_rcWindowBounds.y -= top;
m_rcWindowBounds.w += right;
m_rcWindowBounds.h += bottom;
#endif
}

void CRenderDevice::SelectResolution(const bool windowed)
Expand Down Expand Up @@ -268,9 +260,7 @@ void CRenderDevice::OnFatalError()
{
// make it sure window will hide in any way
SDL_SetWindowFullscreen(m_sdlWnd, SDL_FALSE);
#if SDL_VERSION_ATLEAST(2, 0, 16)
SDL_SetWindowAlwaysOnTop(m_sdlWnd, SDL_FALSE);
#endif
SDL_ShowWindow(m_sdlWnd);
SDL_MinimizeWindow(m_sdlWnd);
SDL_HideWindow(m_sdlWnd);
Expand Down
15 changes: 0 additions & 15 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,31 +307,23 @@ void CRenderDevice::ProcessEvent(const SDL_Event& event)

switch (event.type)
{
#if SDL_VERSION_ATLEAST(2, 0, 9)
case SDL_DISPLAYEVENT:
{
switch (event.display.type)
{
case SDL_DISPLAYEVENT_ORIENTATION:
#if SDL_VERSION_ATLEAST(2, 0, 14)
case SDL_DISPLAYEVENT_CONNECTED:
case SDL_DISPLAYEVENT_DISCONNECTED:
#endif
CleanupVideoModes();
FillVideoModes();
#if SDL_VERSION_ATLEAST(2, 0, 14)
if (event.display.display == psDeviceMode.Monitor && event.display.type != SDL_DISPLAYEVENT_CONNECTED)
#else
if (event.display.display == psDeviceMode.Monitor)
#endif
Reset();
else
UpdateWindowProps();
break;
} // switch (event.display.type)
break;
}
#endif
case SDL_WINDOWEVENT:
{
const auto window = SDL_GetWindowFromID(event.window.windowID);
Expand All @@ -348,22 +340,15 @@ void CRenderDevice::ProcessEvent(const SDL_Event& event)
if (window == m_sdlWnd)
{
UpdateWindowRects();
#if !SDL_VERSION_ATLEAST(2, 0, 18) // without SDL_WINDOWEVENT_DISPLAY_CHANGED, let's detect monitor change ourselves
const int display = SDL_GetWindowDisplayIndex(window);
if (display != -1)
psDeviceMode.Monitor = display;
#endif
}
if (viewport)
viewport->PlatformRequestMove = true;
break;
}

#if SDL_VERSION_ATLEAST(2, 0, 18)
case SDL_WINDOWEVENT_DISPLAY_CHANGED:
psDeviceMode.Monitor = event.window.data1;
break;
#endif

case SDL_WINDOWEVENT_RESIZED:
if (window == m_sdlWnd)
Expand Down
2 changes: 0 additions & 2 deletions src/xrEngine/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,8 @@ void CApplication::ShowSplash(bool topmost)

Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN;

#if SDL_VERSION_ATLEAST(2,0,5)
if (topmost)
flags |= SDL_WINDOW_ALWAYS_ON_TOP;
#endif

m_window = SDL_CreateWindow("OpenXRay", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_surface->w, m_surface->h, flags);
SDL_ShowWindow(m_window);
Expand Down
30 changes: 2 additions & 28 deletions src/xrEngine/xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,16 @@ void CInput::OpenController(int idx)
if (!controller)
return;

#if SDL_VERSION_ATLEAST(2, 0, 14)
if (psControllerEnableSensors.test(1))
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_GYRO, SDL_TRUE);
#endif

controllers.emplace_back(controller);
}

void CInput::EnableControllerSensors(bool enable)
{
#if SDL_VERSION_ATLEAST(2, 0, 14)
for (auto controller : controllers)
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_GYRO, enable ? SDL_TRUE : SDL_FALSE);
#endif
}

//-----------------------------------------------------------------------
Expand Down Expand Up @@ -134,12 +131,8 @@ void CInput::MouseUpdate()
static_assert(std::size(IdxToKey) == COUNT_MOUSE_BUTTONS);

bool mouseMoved = false;
#if SDL_VERSION_ATLEAST(2, 0, 18)
int offs[2]{};
float scroll[2]{};
#else
int offs[COUNT_MOUSE_AXIS]{};
#endif
const auto mousePrev = mouseState;
mouseAxisState[2] = 0;
mouseAxisState[3] = 0;
Expand Down Expand Up @@ -182,13 +175,8 @@ void CInput::MouseUpdate()
}
case SDL_MOUSEWHEEL:
mouseMoved = true;
#if SDL_VERSION_ATLEAST(2, 0, 18)
scroll[0] += event.wheel.preciseX;
scroll[1] += event.wheel.preciseY;
#else
offs[2] += event.wheel.x;
offs[3] += event.wheel.y;
#endif
mouseAxisState[2] += event.wheel.x;
mouseAxisState[3] += event.wheel.y;
break;
Expand All @@ -205,13 +193,9 @@ void CInput::MouseUpdate()
{
if (offs[0] || offs[1])
cbStack.back()->IR_OnMouseMove(offs[0], offs[1]);
#if SDL_VERSION_ATLEAST(2, 0, 18)

if (!fis_zero(scroll[0]) || !fis_zero(scroll[1]))
cbStack.back()->IR_OnMouseWheel(scroll[0], scroll[1]);
#else
if (offs[2] || offs[3])
cbStack.back()->IR_OnMouseWheel(offs[2], offs[3]);
#endif
}
}

Expand Down Expand Up @@ -341,11 +325,7 @@ void CInput::ControllerUpdate()
decltype(controllerAxisState) controllerAxisStatePrev;
CopyMemory(controllerAxisStatePrev, controllerAxisState, sizeof(controllerAxisState));

#if SDL_VERSION_ATLEAST(2, 0, 14)
constexpr SDL_EventType MAX_EVENT = SDL_CONTROLLERSENSORUPDATE;
#else
constexpr SDL_EventType MAX_EVENT = SDL_CONTROLLERDEVICEREMAPPED;
#endif

count = SDL_PeepEvents(events, MAX_CONTROLLER_EVENTS,
SDL_GETEVENT, SDL_CONTROLLERAXISMOTION, MAX_EVENT);
Expand Down Expand Up @@ -411,7 +391,6 @@ void CInput::ControllerUpdate()
break;
}

#if SDL_VERSION_ATLEAST(2, 0, 14)
case SDL_CONTROLLERSENSORUPDATE:
{
if (last_input_controller != event.csensor.which) // only use data from the recently used controller
Expand All @@ -424,7 +403,6 @@ void CInput::ControllerUpdate()
cbStack.back()->IR_OnControllerAttitudeChange(gyro);
break;
}
#endif
} // switch (event.type)
}

Expand Down Expand Up @@ -749,7 +727,6 @@ bool CInput::IsExclusiveMode() const

void CInput::Feedback(FeedbackType type, float s1, float s2, float duration)
{
#if SDL_VERSION_ATLEAST(2, 0, 9)
const u16 s1_rumble = iFloor(u16(-1) * clampr(s1, 0.0f, 1.0f));
const u16 s2_rumble = iFloor(u16(-1) * clampr(s2, 0.0f, 1.0f));
const u32 duration_ms = duration < 0.f ? 0 : iFloor(duration * 1000.f);
Expand All @@ -768,17 +745,14 @@ void CInput::Feedback(FeedbackType type, float s1, float s2, float duration)

case FeedbackTriggers:
{
#if SDL_VERSION_ATLEAST(2, 0, 14)
if (last_input_controller != -1)
{
const auto controller = SDL_GameControllerFromInstanceID(last_input_controller);
SDL_GameControllerRumbleTriggers(controller, s1_rumble, s2_rumble, duration_ms);
}
break;
#endif
}

default: NODEFAULT;
}
#endif
}
2 changes: 1 addition & 1 deletion src/xrEngine/xr_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <SDL.h>

#if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
# define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
#else
# define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
Expand Down

0 comments on commit a29ea70

Please sign in to comment.