Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 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_CURRENT_SOURCE_DIR}/cmake/Modules" "${CMAKE_CURRENT_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
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_CURRENT_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
25 changes: 13 additions & 12 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# include <windows.h> // Avoid "Windows headers require the default packing option" due to SDL2
# include <SDL_syswm.h>
#endif // _WIN32
#if RTTR_OGL_GL4ES == 1
#if RTTR_OGL_GL4ES
# include <gl4esinit.h>
#endif

Expand All @@ -44,6 +44,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 @@ -60,8 +68,8 @@ void FreeVideoInstance(IVideoDriver* driver)

const char* GetDriverName()
{
#if RTTR_OGL_GL4ES == 1
return "(SDL2) OpenGL-ES(gl4es) via SDL2-Library";
#if RTTR_OGL_GL4ES
return "(SDL2) OpenGL-ES gl4es via SDL2-Library";
#else
return "(SDL2) OpenGL via SDL2-Library";
#endif
Expand Down Expand Up @@ -125,14 +133,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) || (RTTR_OGL_GL4ES == 1))
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 @@ -500,7 +501,7 @@ void VideoSDL2::ListVideoModes(std::vector<VideoMode>& video_modes) const

OpenGL_Loader_Proc VideoSDL2::GetLoaderFunction() const
{
#if RTTR_OGL_GL4ES == 1
#if RTTR_OGL_GL4ES
return gl4es_GetProcAddress;
#else
return SDL_GL_GetProcAddress;
Expand Down
18 changes: 12 additions & 6 deletions libs/driver/include/driver/MouseCoords.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ class MouseCoords
{}

Position pos;
bool ldown; /// Linke Maustaste gedrückt
bool rdown; /// Rechte Maustaste gedrückt
bool dbl_click; /// Linke Maustaste - Doppelklick
unsigned num_tfingers; /// Anzahl Finger auf dem Display
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;
4 changes: 2 additions & 2 deletions libs/driver/include/driver/VideoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class VideoDriver : public IVideoDriver
/// Funktion zum Auslesen ob die Rechte Maustaste gedrückt ist.
bool GetMouseStateR() const override;

/// Funktion zum Auslesen ob momentan touch verwendet wird.
bool GetMouseTouch() 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_; }
Expand Down
4 changes: 2 additions & 2 deletions libs/driver/include/driver/VideoInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +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 when touch is being used
virtual bool GetMouseTouch() 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
6 changes: 3 additions & 3 deletions libs/driver/src/VideoDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ bool VideoDriver::GetMouseStateR() const
}

/**
* Funktion zum Auslesen ob momentan touch verwendet wird.
* Function to check if at least 1 finger is on screen.
*
* @return @p true bei touch, @p false bei maus
* @return @p true at least 1 finger, @p false when mouse used
*/
bool VideoDriver::GetMouseTouch() const
bool VideoDriver::IsTouchEvent() const
{
return mouse_xy.num_tfingers > 0;
}
Expand Down
38 changes: 22 additions & 16 deletions libs/s25main/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#include "s25util/error.h"
#include <boost/filesystem/operations.hpp>

namespace {
#ifdef __ANDROID__
constexpr bool SHARED_TEXTURES_DEFAULT = false;
constexpr MapScrollMode MAP_SCROLL_MODE_DEFAULT = MapScrollMode::GrabAndDrag;
#else
constexpr bool SHARED_TEXTURES_DEFAULT = true;
constexpr MapScrollMode MAP_SCROLL_MODE_DEFAULT = MapScrollMode::ScrollOpposite;
#endif
} // namespace

const int Settings::VERSION = 13;
const std::array<std::string, 10> Settings::SECTION_NAMES = {
{"global", "video", "language", "driver", "sound", "lobby", "server", "proxy", "interface", "addons"}};
Expand Down Expand Up @@ -93,11 +103,7 @@ void Settings::LoadDefaults()
}
video.framerate = 0; // Special value for HW vsync
video.vbo = true;
#ifdef __ANDROID__
video.shared_textures = false;
#else
video.shared_textures = true;
#endif
video.shared_textures = SHARED_TEXTURES_DEFAULT;
video.guiScale = 0; // special value indicating automatic selection
// }

Expand Down Expand Up @@ -145,11 +151,7 @@ void Settings::LoadDefaults()
// interface
// {
interface.autosave_interval = 0;
#ifdef __ANDROID__
interface.mouseMode = 2;
#else
interface.mouseMode = 0;
#endif
interface.mapScrollMode = MAP_SCROLL_MODE_DEFAULT;
interface.enableWindowPinning = false;
interface.windowSnapDistance = 8;
// }
Expand Down Expand Up @@ -315,11 +317,15 @@ void Settings::Load()
// interface
// {
interface.autosave_interval = iniInterface->getIntValue("autosave_interval");
#ifdef __ANDROID__
interface.mouseMode = iniInterface->getValue("mouse_mode", 2);
#else
interface.mouseMode = iniInterface->getValue("mouse_mode", 0);
#endif
try
{
interface.mapScrollMode = static_cast<MapScrollMode>(iniInterface->getIntValue("map_scroll_mode"));
} catch(const std::runtime_error&)
{
// ScrollSame(old invertMouse) is 0 so invert value
interface.mapScrollMode = static_cast<MapScrollMode>(!iniInterface->getBoolValue("invert_mouse"));
Copy link
Member

Choose a reason for hiding this comment

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

That cast can't be verified at this point. Just do a ternary here to set the enum value directly. So you don't even need the comment

This will also throw an error if the value does not exist, so please keep the prior one with default value

I don't think you need the warning either as there is nothing to check: The old setting is translated 1:1 to the new one

s25util::warning("Value 'map_scroll_mode' not found! Using 'invert_mouse' instead - please recheck your settings!");
}
interface.enableWindowPinning = iniInterface->getValue("enable_window_pinning", false);
interface.windowSnapDistance = iniInterface->getValue("window_snap_distance", 8);
// }
Expand Down Expand Up @@ -484,7 +490,7 @@ void Settings::Save()
// interface
// {
iniInterface->setValue("autosave_interval", interface.autosave_interval);
iniInterface->setValue("mouse_mode", interface.mouseMode);
iniInterface->setValue("map_scroll_mode", static_cast<int>(interface.mapScrollMode));
iniInterface->setValue("enable_window_pinning", interface.enableWindowPinning);
iniInterface->setValue("window_snap_distance", interface.windowSnapDistance);
// }
Expand Down
9 changes: 8 additions & 1 deletion libs/s25main/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ struct PersistentWindowSettings
bool isMinimized = false;
};

enum class MapScrollMode
{
ScrollSame,
ScrollOpposite, // S2 Original
GrabAndDrag
};

/// Configuration class
class Settings : public Singleton<Settings, SingletonPolicies::WithLongevity>
{
Expand Down Expand Up @@ -106,7 +113,7 @@ class Settings : public Singleton<Settings, SingletonPolicies::WithLongevity>
struct
{
unsigned autosave_interval;
unsigned mouseMode; // default/original:0 inverted:1 natural:2
MapScrollMode mapScrollMode;
bool enableWindowPinning;
unsigned windowSnapDistance;
} interface;
Expand Down
28 changes: 13 additions & 15 deletions libs/s25main/TerrainRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
* providing an index and a count into the above arrays.
*/

namespace {
// gl4es has some problems with GL_MODULATE so we need to change the colors without using a gl function
#if RTTR_OGL_GL4ES
constexpr float TEXTURE_COLOR_DIVISOR = 1;
#else
constexpr float TEXTURE_COLOR_DIVISOR = 2;
#endif
}

glArchivItem_Bitmap* new_clone(const glArchivItem_Bitmap& bmp)
{
return dynamic_cast<glArchivItem_Bitmap*>(bmp.clone());
Expand Down Expand Up @@ -220,25 +229,14 @@ void TerrainRenderer::UpdateVertexColor(const MapPoint pt, const GameWorldViewer
// Unsichtbar -> schwarz
GetVertex(pt).color = 0.0f;
break;
#if RTTR_OGL_GL4ES == 1
case Visibility::FogOfWar:
// Fog of War -> abgedunkelt
GetVertex(pt).color = clr / 2.f;
break;
case Visibility::Visible:
// Normal sichtbar
GetVertex(pt).color = clr / 1.f;
break;
#else
case Visibility::FogOfWar:
// Fog of War -> abgedunkelt
GetVertex(pt).color = clr / 4.f;
GetVertex(pt).color = clr / (TEXTURE_COLOR_DIVISOR * 2);
break;
case Visibility::Visible:
// Normal sichtbar
GetVertex(pt).color = clr / 2.f;
GetVertex(pt).color = clr / TEXTURE_COLOR_DIVISOR;
break;
#endif
}
}

Expand Down Expand Up @@ -803,8 +801,8 @@ void TerrainRenderer::Draw(const Position& firstPt, const Position& lastPt, cons
glColorPointer(3, GL_FLOAT, 0, &gl_colors.front());
}

#if RTTR_OGL_GL4ES == 1
// Gl4es does not like GL_COMBINE...
#if RTTR_OGL_GL4ES
// Gl4ES behaves weird with GL_COMBINE. All textures are too bright. The function might not be implemented in GL4ES at all.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#else
// Modulate2x
Expand Down
26 changes: 14 additions & 12 deletions libs/s25main/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "s25util/MyTime.h"
#include <algorithm>

// Calc square
#define SQR(x) ((x) * (x))

WindowManager::WindowManager()
: cursor_(Cursor::Hand), disable_mouse(false), lastMousePos(Position::Invalid()), curRenderSize(0, 0),
lastLeftClickTime(0), lastLeftClickPos(0, 0)
Expand Down Expand Up @@ -357,24 +360,23 @@ void WindowManager::Msg_LeftUp(MouseCoords mc)
// Ggf. Doppelklick untersuche
unsigned time_now = VIDEODRIVER.GetTickCount();

// Sehr schwierig auf touch mit dem default dbl-click interval z.B. Mails zu löschen ohne das Fenster zu schließen
if(time_now - lastLeftClickTime < (VIDEODRIVER.IsTouch() ? DOUBLE_CLICK_INTERVAL / 3 : DOUBLE_CLICK_INTERVAL))
if(!VIDEODRIVER.IsTouch())
{
if(mc.GetPos() == lastLeftClickPos)
if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.pos == lastLeftClickPos)
mc.dbl_click = true;

} else if(time_now - lastLeftClickTime < TOUCH_DOUBLE_CLICK_INTERVAL)
{
// Calculate distance between two points
unsigned cDistance = SQR(mc.pos.x - lastLeftClickPos.x) + SQR(mc.pos.y - lastLeftClickPos.y);
Copy link
Member

Choose a reason for hiding this comment

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

Just a hint for future changes: Use const auto diff = mc.pos - lastLeftClickPos to avoid the potential for C&P issues due 2 repeated use of x and y in the same line. The below could then be if(square(diff.x) + square(diff.y) <= square(TOUCH_MAX_DOUBLE_CLICK_DISTANCE)) which explains why the RHS is squared more directly.

No need to change this, just a suggestion for future changes as this is mostly an opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Calculate distance between two points
const auto diff = mc.pos - lastLeftClickPos;
if(square(diff.x) + square(diff.y) <= square(TOUCH_MAX_DOUBLE_CLICK_DISTANCE))
    mc.dbl_click = true;

diff would be Point<int> but TOUCH_MAX_DOUBLE_CLICK_DISTANCE is unsigned which can't be compared.
Do you know a better way than changing the constant to int or using static_cast in the if statement?

Copy link
Member

Choose a reason for hiding this comment

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

Only idea: Make square return std::make_unsigned_t<T> and do the cast there as the square of an int will always be positive.

if(cDistance <= SQR(TOUCH_MAX_DOUBLE_CLICK_DISTANCE))
mc.dbl_click = true;
else if(VIDEODRIVER.IsTouch()) // Fast unmöglich 2 mal auf den exakt selben punkt zu tippen
{
// Wenn doppeltippen -> fenster schließen
IngameWindow* window = FindWindowAtPos(mc.GetPos());
if(window && !window->IsPinned())
window->Close();
}
}

if(!mc.dbl_click)
{
// Werte wieder erneut speichern
lastLeftClickPos = mc.GetPos();
// Save values for next potential dbl click
lastLeftClickPos = mc.pos;
lastLeftClickTime = time_now;
}

Expand Down
Loading
Loading