Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 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")

set(checkSubmodules FALSE)
# Figure out RTTR_REVISION (git hash) and RTTR_VERSION (date)
Expand Down Expand Up @@ -242,6 +242,10 @@ include(EnableSanitizers)

option(RTTR_USE_SYSTEM_LIBS "Default to using system-wide installed libs for external dependencies that have known system versions." OFF)

# Eg. Only libraries are able to run on android. The java native interface(jni) will call the SDL_main() function which calls main() in libs25client.so
# https://developer.android.com/studio/projects/add-native-code
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
13 changes: 9 additions & 4 deletions external/glad/openglCfg.hpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
// The OpenGL(ES) major and minor version to be used
#define RTTR_OGL_MAJOR @RTTR_OGL_MAJOR@
#define RTTR_OGL_MINOR @RTTR_OGL_MINOR@
// True(thy) if OpenGL ES should be used
#define RTTR_OGL_ES @RTTR_OGL_ES@
// True(thy) if OpenGL compatibility profile should be used
#define RTTR_OGL_COMPAT @RTTR_OGL_COMPAT@

// 1 if OpenGL ES should be used
#cmakedefine01 RTTR_OGL_ES

// 1 if OpenGL compatibility profile should be used
#cmakedefine01 RTTR_OGL_COMPAT

// 1 if gl4es should be used
#cmakedefine01 RTTR_OGL_GL4ES

#endif
21 changes: 20 additions & 1 deletion 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 Down
78 changes: 71 additions & 7 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <s25util/utf8.h>
#include <boost/nowide/iostream.hpp>
#include <SDL.h>
#include <SDL_hints.h>
#include <SDL_video.h>
#include <algorithm>
#include <memory>

Expand All @@ -25,13 +27,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 \
{ \
if((call) == -1) \
([&]() -> bool { \
if((call) < 0) \
{ \
PrintError(SDL_GetError()); \
} while(false)
return false; \
} \
return true; \
})()

namespace {
template<typename T>
Expand Down Expand Up @@ -67,7 +75,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 @@ -86,6 +98,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 @@ -127,12 +141,13 @@ bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, bo
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))
if(RTTR_OGL_ES || RTTR_OGL_GL4ES)
profile = SDL_GL_CONTEXT_PROFILE_ES;
else if((RTTR_OGL_COMPAT))
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_RED_SIZE, 8));
Expand Down Expand Up @@ -424,6 +439,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 @@ -456,7 +515,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 @@ -491,7 +554,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
13 changes: 10 additions & 3 deletions libs/driver/include/driver/MouseCoords.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ struct MouseCoords
MouseCoords(int x, int y) : pos(x, y) {}

Position pos = Position(0, 0);
bool ldown = false; /// left button down
bool rdown = false; /// right button down
bool dbl_click = false; /// double-click (left button)
bool ldown = false; /// left button down
bool rdown = false; /// right button down
bool dbl_click = false; /// double-click (left button)
unsigned num_tfingers = 0; /// Count of fingers currently on touchscreen
};

/// Maximum interval between two clicks to be considered a double-click (in milliseconds)
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
25 changes: 17 additions & 8 deletions libs/rttrConfig/src/RttrConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,22 @@ bool RttrConfig::Init()
bfs::current_path(prefixPath_);
homePath = System::getHomePath();
pathMappings.clear();
pathMappings["BIN"] = RTTR_BINDIR;
pathMappings["EXTRA_BIN"] = RTTR_EXTRA_BINDIR;
pathMappings["DATA"] = RTTR_DATADIR;
pathMappings["GAME"] = RTTR_GAMEDIR;
pathMappings["LIB"] = RTTR_LIBDIR;
pathMappings["DRIVER"] = RTTR_DRIVERDIR;
pathMappings["RTTR"] = RTTR_DATADIR "/RTTR";
pathMappings["USERDATA"] = RTTR_USERDATADIR;
pathMappings["BIN"] = getEnvOverride("BIN", RTTR_BINDIR);
pathMappings["EXTRA_BIN"] = getEnvOverride("EXTRA_BIN", RTTR_EXTRA_BINDIR);
pathMappings["DATA"] = getEnvOverride("DATA", RTTR_DATADIR);
pathMappings["GAME"] = getEnvOverride("GAME", RTTR_GAMEDIR);
pathMappings["LIB"] = getEnvOverride("LIB", RTTR_LIBDIR);
pathMappings["DRIVER"] = getEnvOverride("DRIVER", RTTR_DRIVERDIR);
pathMappings["RTTR"] = getEnvOverride("RTTR", RTTR_DATADIR "/RTTR");
pathMappings["USERDATA"] = getEnvOverride("USERDATA", RTTR_USERDATADIR);
return true;
}

bfs::path RttrConfig::getEnvOverride(const std::string& id, const bfs::path& defaultPath)
{
bfs::path path = System::getPathFromEnvVar("RTTR_" + id + "_DIR");
if(path.empty())
return defaultPath;
LOG.write("Note: %1% path manually set to %2%\n", LogTarget::Stdout) % id % path;
return path;
}
3 changes: 3 additions & 0 deletions libs/rttrConfig/src/RttrConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class RttrConfig : public Singleton<RttrConfig>

public:
bool Init();

/// Checks the env var for path override and returns result path
static boost::filesystem::path getEnvOverride(const std::string& id, const boost::filesystem::path& defaultPath);
/// Return the prefix path for the installation
static boost::filesystem::path GetPrefixPath();
/// Return the path from which RTTR was compiled
Expand Down
Loading
Loading