Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d41850d
use CMAKE_CURRENT_SOURCE_DIR
Farmer-Markus Oct 6, 2025
7212e35
first time running
Farmer-Markus Oct 6, 2025
154dbc4
Allow overriting paths using enviroment variables
Farmer-Markus Oct 17, 2025
b9c1b8f
revoked some changes
Farmer-Markus Oct 17, 2025
48e4345
Added gles support using gl4es
Farmer-Markus Oct 18, 2025
ebb1b78
Fixed crash on windows without borders
Farmer-Markus Oct 18, 2025
b536a73
Fixed small mistake
Farmer-Markus Oct 18, 2025
81098a6
Added Natural mouse mode and basic touch controls
Farmer-Markus Oct 20, 2025
2992c4a
Fixed some issues
Farmer-Markus Oct 20, 2025
107d540
Fixed formatting
Farmer-Markus Oct 20, 2025
4988c05
Fixed formatting (again)
Farmer-Markus Oct 20, 2025
4e32c59
Fixed Natural mouse movement with gui scale
Farmer-Markus Oct 22, 2025
821db6f
Added touch zoom and fixed gl4es lightning
Farmer-Markus Oct 22, 2025
82cca08
Fixed formatting
Farmer-Markus Oct 22, 2025
152da4c
Changed dbl click timing on touch
Farmer-Markus Oct 22, 2025
a9e90cd
Fixed dbl click bug
Farmer-Markus Oct 22, 2025
1ca1b58
Added test for touch movement
Farmer-Markus Oct 23, 2025
73004a5
Changed default Settings for Android
Farmer-Markus Oct 23, 2025
8d00021
Revised previous changes
Farmer-Markus Oct 25, 2025
bb0f187
Fixed formatting
Farmer-Markus Oct 25, 2025
c3507f0
Fixed formatting
Farmer-Markus Oct 25, 2025
9c0b200
Added tests for cfg envOverride and touch dblClick
Farmer-Markus Oct 26, 2025
7d5c270
Fixed formatting
Farmer-Markus Oct 26, 2025
62d71ba
Changed dblick close window behaviour
Farmer-Markus Oct 26, 2025
f14d60d
Fixed formatting
Farmer-Markus Oct 26, 2025
1556dcc
minor changes
Farmer-Markus Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.DS_Store
.vscode
.vs
.cache
/S2
/build
/external/boost*
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(DEFINED CMAKE_TOOLCHAIN_FILE)
message(STATUS "Used Toolchain definition file '${CMAKE_TOOLCHAIN_FILE}'")
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" "${CMAKE_SOURCE_DIR}/external/libutil/cmake")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules" "${PROJECT_SOURCE_DIR}/external/libutil/cmake")

include(EnableCCache)

Expand Down Expand Up @@ -242,6 +242,7 @@ include(RttrCoverageCfg)
include(EnableSanitizers)

option(RTTR_USE_SYSTEM_LIBS "Default to using system-wide installed libs for external dependencies that have known system versions." OFF)
option(RTTR_BUILD_LIB "Executables will be build as shared library." OFF)

################################################################################
# Configure files
Expand Down
6 changes: 3 additions & 3 deletions copyDepsToBuildDir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Needs to be configured with @ONLY and called with -DCMAKE_BUILD_TYPE=...

set(CMAKE_HOST_UNIX "@CMAKE_HOST_UNIX@")
set(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@")
set(PROJECT_SOURCE_DIR "@PROJECT_SOURCE_DIR@")
set(RTTR_TRANSLATION_OUTPUT "@RTTR_TRANSLATION_OUTPUT@")
set(RTTR_DATADIR "@RTTR_DATADIR@")
set(RTTR_GAMEDIR "@RTTR_GAMEDIR@")
Expand Down Expand Up @@ -37,9 +37,9 @@ file(COPY "${RTTR_TRANSLATION_OUTPUT}/"
DESTINATION "${RTTR_OUTPUT_PATH}/RTTR/languages"
FILES_MATCHING PATTERN "*.mo"
)
file(COPY "${CMAKE_SOURCE_DIR}/data/RTTR" DESTINATION "${RTTR_OUTPUT_PATH}")
file(COPY "${PROJECT_SOURCE_DIR}/data/RTTR" DESTINATION "${RTTR_OUTPUT_PATH}")

set(S2_GAME_PATHS ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/S2)
set(S2_GAME_PATHS ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/S2)
get_filename_component(GAME_OUTPUT_PATH "${RTTR_GAMEDIR}" ABSOLUTE BASE_DIR "${CUR_OUTPUT_DIR}")
if(NOT EXISTS ${GAME_OUTPUT_PATH}/DATA)
find_path(S2_DATA_DIR DATA/IO.LST PATHS ${S2_GAME_PATHS})
Expand Down
48 changes: 31 additions & 17 deletions external/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,41 @@ include(ConstrainedOption)
constrained_option(RTTR_OPENGL
DEFAULT "OGL2.0Compat"
DESCRIPTION "The OpenGL version to use"
VALUES OGL2.0Compat OGL2.0 OGL2.1Compat OGL2.1 OGL3.3 GLES2.0)
VALUES OGL2.0Compat OGL2.0 OGL2.1Compat OGL2.1 OGL3.3 GLES2.0 GL4ES)

string(REGEX MATCH "^(OGL|GLES)([0-9])\\.([0-9])(Compat)?$" ogl_match ${RTTR_OPENGL})
if(NOT ogl_match)
message(FATAL_ERROR "Invalid value for RTTR_OPENGL: ${RTTR_OPENGL}.")
endif()
set(RTTR_OGL_MAJOR ${CMAKE_MATCH_2})
set(RTTR_OGL_MINOR ${CMAKE_MATCH_3})
if(CMAKE_MATCH_1 STREQUAL "GLES")
set(RTTR_OGL_ES 1)
set(rttr_glad_folder "OpenGLES")
else()
# gl4es OpenGL 2.1 -> GL ES 2.0 https://github.com/ptitSeb/gl4es
if(RTTR_OPENGL STREQUAL "GL4ES")
set(RTTR_OGL_MAJOR 2)
set(RTTR_OGL_MINOR 0)
set(RTTR_OGL_ES 0)
set(rttr_glad_folder "OpenGL")
endif()
if(CMAKE_MATCH_4 STREQUAL "Compat")
set(RTTR_OGL_COMPAT 1)
else()
set(RTTR_OGL_COMPAT 0)
set(RTTR_OGL_GL4ES 1)

# Use default glad for gl4es
set(rttr_glad_folder "OpenGL2.0Compat")

else()
set(RTTR_OGL_GL4ES 0)
string(REGEX MATCH "^(OGL|GLES)([0-9])\\.([0-9])(Compat)?$" ogl_match ${RTTR_OPENGL})
if(NOT ogl_match)
message(FATAL_ERROR "Invalid value for RTTR_OPENGL: ${RTTR_OPENGL}.")
endif()
set(RTTR_OGL_MAJOR ${CMAKE_MATCH_2})
set(RTTR_OGL_MINOR ${CMAKE_MATCH_3})
if(CMAKE_MATCH_1 STREQUAL "GLES")
set(RTTR_OGL_ES 1)
set(rttr_glad_folder "OpenGLES")
else()
set(RTTR_OGL_ES 0)
set(rttr_glad_folder "OpenGL")
endif()
if(CMAKE_MATCH_4 STREQUAL "Compat")
set(RTTR_OGL_COMPAT 1)
else()
set(RTTR_OGL_COMPAT 0)
endif()
get_filename_component(rttr_glad_folder "${rttr_glad_folder}${RTTR_OGL_MAJOR}.${RTTR_OGL_MINOR}${CMAKE_MATCH_4}" ABSOLUTE)
endif()
get_filename_component(rttr_glad_folder "${rttr_glad_folder}${RTTR_OGL_MAJOR}.${RTTR_OGL_MINOR}${CMAKE_MATCH_4}" ABSOLUTE)
configure_file(openglCfg.hpp.cmake include/openglCfg.hpp @ONLY)

add_library(glad STATIC ${rttr_glad_folder}/src/glad.c)
Expand Down
3 changes: 3 additions & 0 deletions external/glad/openglCfg.hpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
#define RTTR_OGL_ES @RTTR_OGL_ES@
// True(thy) if OpenGL compatibility profile should be used
#define RTTR_OGL_COMPAT @RTTR_OGL_COMPAT@
// True(thy) if gl4es should be used
#define RTTR_OGL_GL4ES @RTTR_OGL_GL4ES@


#endif
2 changes: 1 addition & 1 deletion extras/videoDrivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ rttr_set_output_dir(RUNTIME ${RTTR_DRIVERDIR}/video)
rttr_set_output_dir(LIBRARY ${RTTR_DRIVERDIR}/video)

add_subdirectory(WinAPI)
add_subdirectory(SDL2)
add_subdirectory(SDL2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change

23 changes: 21 additions & 2 deletions extras/videoDrivers/SDL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ find_package(SDL2 2.0.5)

if(SDL2_FOUND)
add_library(videoSDL2 SHARED ${RTTR_DRIVER_INTERFACE} VideoSDL2.cpp VideoSDL2.h icon.h icon.cpp)
target_link_libraries(videoSDL2 PRIVATE videodrv s25util::common glad Boost::nowide SDL2::SDL2)

if(RTTR_OPENGL STREQUAL "GL4ES")
if(NOT TARGET GL)
message(STATUS "Fetching gl4es from repository...")
include(FetchContent)
FetchContent_Declare(
gl4es
GIT_REPOSITORY https://github.com/ptitSeb/gl4es
GIT_TAG master
)
FetchContent_MakeAvailable(gl4es)
target_include_directories(videoSDL2 PRIVATE
${gl4es_SOURCE_DIR}/include
)
endif()
# gl4es generates "GL" library
target_link_libraries(videoSDL2 PRIVATE videodrv s25util::common glad Boost::nowide SDL2::SDL2 GL)
else()
target_link_libraries(videoSDL2 PRIVATE videodrv s25util::common glad Boost::nowide SDL2::SDL2)
endif()
enable_warnings(videoSDL2)

if(WIN32)
Expand All @@ -20,4 +39,4 @@ if(SDL2_FOUND)
LIBRARY DESTINATION ${RTTR_DRIVERDIR}/video
)
add_dependencies(drivers videoSDL2)
endif()
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change

87 changes: 75 additions & 12 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <s25util/utf8.h>
#include <boost/nowide/iostream.hpp>
#include <SDL.h>
#include <SDL_hints.h>
#include <algorithm>
#include <memory>

Expand All @@ -25,13 +26,19 @@
# include <windows.h> // Avoid "Windows headers require the default packing option" due to SDL2
# include <SDL_syswm.h>
#endif // _WIN32
#if RTTR_OGL_GL4ES
# include <gl4esinit.h>
#endif

#define CHECK_SDL(call) \
do \
{ \
([&]() -> bool { \
if((call) == -1) \
{ \
PrintError(SDL_GetError()); \
} while(false)
return false; \
} \
return true; \
})()

namespace {
template<typename T>
Expand All @@ -40,6 +47,14 @@ struct SDLMemoryDeleter
void operator()(T* p) const { SDL_free(p); }
};

#if RTTR_OGL_ES || RTTR_OGL_GL4ES
constexpr SDL_GLprofile RTTR_SDL_GL_PROFILE = SDL_GL_CONTEXT_PROFILE_ES;
#elif RTTR_OGL_COMPAT
constexpr SDL_GLprofile RTTR_SDL_GL_PROFILE = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY;
#else
constexpr SDL_GLprofile RTTR_SDL_GL_PROFILE = SDL_GL_CONTEXT_PROFILE_CORE;
#endif

template<typename T>
using SDL_memory = std::unique_ptr<T, SDLMemoryDeleter<T>>;
} // namespace
Expand All @@ -56,7 +71,11 @@ void FreeVideoInstance(IVideoDriver* driver)

const char* GetDriverName()
{
#if RTTR_OGL_GL4ES
return "(SDL2) OpenGL-ES gl4es via SDL2-Library";
#else
return "(SDL2) OpenGL via SDL2-Library";
#endif
}

VideoSDL2::VideoSDL2(VideoDriverLoaderInterface* CallBack) : VideoDriver(CallBack), window(nullptr), context(nullptr) {}
Expand All @@ -75,6 +94,8 @@ bool VideoSDL2::Initialize()
{
initialized = false;
rttr::ScopedLeakDisabler _;
// Do not emulate mouse events using touch
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
PrintError(SDL_GetError());
Expand Down Expand Up @@ -115,14 +136,7 @@ bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, bo
// GL-Attributes
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RTTR_OGL_MAJOR));
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RTTR_OGL_MINOR));
SDL_GLprofile profile;
if((RTTR_OGL_ES))
profile = SDL_GL_CONTEXT_PROFILE_ES;
else if((RTTR_OGL_COMPAT))
profile = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY;
else
profile = SDL_GL_CONTEXT_PROFILE_CORE;
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile));
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, RTTR_SDL_GL_PROFILE));

CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
Expand Down Expand Up @@ -414,6 +428,50 @@ bool VideoSDL2::MessageLoop()
}
}
break;
case SDL_FINGERDOWN:
{
VideoMode wnSize = GetWindowSize();
mouse_xy.pos = getGuiScale().screenToView(Position(static_cast<int>(ev.tfinger.x * wnSize.width),
static_cast<int>(ev.tfinger.y * wnSize.height)));
mouse_xy.ldown = true;
mouse_xy.num_tfingers++;
CallBack->Msg_LeftDown(mouse_xy);
break;
}
case SDL_FINGERUP:
{
VideoMode wnSize = GetWindowSize();
mouse_xy.pos = getGuiScale().screenToView(Position(static_cast<int>(ev.tfinger.x * wnSize.width),
static_cast<int>(ev.tfinger.y * wnSize.height)));
mouse_xy.ldown = false;
CallBack->Msg_LeftUp(mouse_xy);
mouse_xy.num_tfingers--; // Dirty way to count leftUp as touch event without extra isTouch bool
break;
}
case SDL_FINGERMOTION:
{
VideoMode wnSize = GetWindowSize();
const auto newPos = getGuiScale().screenToView(Position(
static_cast<int>(ev.tfinger.x * wnSize.width), static_cast<int>(ev.tfinger.y * wnSize.height)));

if(newPos != mouse_xy.pos)
{
mouse_xy.pos = newPos;
CallBack->Msg_MouseMove(mouse_xy);
}
break;
}
case SDL_MULTIGESTURE:
{
if(std::fabs(ev.mgesture.dDist) > 0.001)
{
if(ev.mgesture.dDist > 0)
CallBack->Msg_WheelUp(mouse_xy);
else
CallBack->Msg_WheelDown(mouse_xy);
}
break;
}
}
}

Expand Down Expand Up @@ -446,7 +504,11 @@ void VideoSDL2::ListVideoModes(std::vector<VideoMode>& video_modes) const

OpenGL_Loader_Proc VideoSDL2::GetLoaderFunction() const
{
#if RTTR_OGL_GL4ES
return gl4es_GetProcAddress;
#else
return SDL_GL_GetProcAddress;
#endif
}

void VideoSDL2::SetMousePos(Position pos)
Expand Down Expand Up @@ -482,7 +544,8 @@ void VideoSDL2::MoveWindowToCenter()
SDL_Rect usableBounds;
CHECK_SDL(SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(window), &usableBounds));
int top, left, bottom, right;
CHECK_SDL(SDL_GetWindowBordersSize(window, &top, &left, &bottom, &right));
if(CHECK_SDL(SDL_GetWindowBordersSize(window, &top, &left, &bottom, &right)) != 0)
top = left = bottom = right = 0;
usableBounds.w -= left + right;
usableBounds.h -= top + bottom;
if(usableBounds.w < GetWindowSize().width || usableBounds.h < GetWindowSize().height)
Expand Down
27 changes: 17 additions & 10 deletions libs/driver/include/driver/MouseCoords.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@
class MouseCoords
{
public:
MouseCoords() : pos(0, 0), ldown(false), rdown(false), dbl_click(false) {}
MouseCoords(int x, int y, bool ldown = false, bool rdown = false, bool dbl_click = false)
: pos(x, y), ldown(ldown), rdown(rdown), dbl_click(dbl_click)
MouseCoords() : pos(0, 0), ldown(false), rdown(false), dbl_click(false), num_tfingers(0) {}
MouseCoords(int x, int y, bool ldown = false, bool rdown = false, bool dbl_click = false, unsigned num_tfingers = 0)
: pos(x, y), ldown(ldown), rdown(rdown), dbl_click(dbl_click), num_tfingers(num_tfingers)
{}
MouseCoords(Position pos, bool ldown = false, bool rdown = false, bool dbl_click = false)
: pos(pos), ldown(ldown), rdown(rdown), dbl_click(dbl_click)
MouseCoords(Position pos, bool ldown = false, bool rdown = false, bool dbl_click = false, unsigned num_tfingers = 0)
: pos(pos), ldown(ldown), rdown(rdown), dbl_click(dbl_click), num_tfingers(num_tfingers)
{}

Position pos;
bool ldown; /// Linke Maustaste gedrückt
bool rdown; /// Rechte Maustaste gedrückt
bool dbl_click; /// Linke Maustaste - Doppelklick
bool ldown; // Left mouse button pressed
bool rdown; // Right mouse button pressed
bool dbl_click; // Left mouse button - doubleclick
unsigned num_tfingers; // Count of fingers currently on touchscreen

Position GetPos() const { return pos; }
};

/// Maximale Zeitdifferenz in ms für einen Doppeklick
const unsigned DOUBLE_CLICK_INTERVAL = 500;
// Max time difference in ms to trigger doubleclick
constexpr unsigned DOUBLE_CLICK_INTERVAL = 500;

// Max time difference in ms to trigger contextclick
constexpr unsigned TOUCH_MAX_CLICK_INTERVAL = 250;
constexpr unsigned TOUCH_DOUBLE_CLICK_INTERVAL = 175;
// Max distance between the two clicks to trigger doubleclick
constexpr unsigned TOUCH_MAX_DOUBLE_CLICK_DISTANCE = 30;
3 changes: 3 additions & 0 deletions libs/driver/include/driver/VideoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class VideoDriver : public IVideoDriver
/// Funktion zum Auslesen ob die Rechte Maustaste gedrückt ist.
bool GetMouseStateR() const override;

/// Function to check if at least 1 finger is on screen
bool IsTouchEvent() const override;

VideoMode GetWindowSize() const override final { return windowSize_; }
Extent GetRenderSize() const override final { return scaledRenderSize_; }
bool IsFullscreen() const override final { return isFullscreen_; }
Expand Down
2 changes: 2 additions & 0 deletions libs/driver/include/driver/VideoInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class BOOST_SYMBOL_VISIBLE IVideoDriver
virtual bool GetMouseStateL() const = 0;
/// Return true when right mouse button is pressed
virtual bool GetMouseStateR() const = 0;
/// Return true if at least 1 finger is on screen
virtual bool IsTouchEvent() const = 0;

/// Get the size of the window in screen coordinates
virtual VideoMode GetWindowSize() const = 0;
Expand Down
10 changes: 10 additions & 0 deletions libs/driver/src/VideoDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ bool VideoDriver::GetMouseStateR() const
return mouse_xy.rdown;
}

/**
* Function to check if at least 1 finger is on screen.
*
* @return @p true at least 1 finger, @p false when mouse used
*/
bool VideoDriver::IsTouchEvent() const
{
return mouse_xy.num_tfingers > 0;
}

VideoMode VideoDriver::FindClosestVideoMode(const VideoMode& mode) const
{
std::vector<VideoMode> avModes;
Expand Down
Loading
Loading