-
Notifications
You must be signed in to change notification settings - Fork 87
Android build #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Android build #1804
Changes from 18 commits
d41850d
7212e35
154dbc4
b9c1b8f
48e4345
ebb1b78
b536a73
81098a6
2992c4a
107d540
4988c05
4e32c59
821db6f
82cca08
152da4c
a9e90cd
1ca1b58
73004a5
8d00021
bb0f187
c3507f0
9c0b200
7d5c270
62d71ba
f14d60d
1556dcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| .DS_Store | ||
| .vscode | ||
| .vs | ||
| .cache | ||
| /S2 | ||
| /build | ||
| /external/boost* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated change |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -20,4 +39,4 @@ if(SDL2_FOUND) | |
| LIBRARY DESTINATION ${RTTR_DRIVERDIR}/video | ||
| ) | ||
| add_dependencies(drivers videoSDL2) | ||
| endif() | ||
| endif() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated change |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| #include <s25util/utf8.h> | ||
| #include <boost/nowide/iostream.hpp> | ||
| #include <SDL.h> | ||
| #include <SDL_hints.h> | ||
| #include <algorithm> | ||
| #include <memory> | ||
|
|
||
|
|
@@ -25,6 +26,9 @@ | |
| # 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 | ||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # include <gl4esinit.h> | ||
| #endif | ||
|
|
||
| #define CHECK_SDL(call) \ | ||
| do \ | ||
|
|
@@ -56,7 +60,11 @@ void FreeVideoInstance(IVideoDriver* driver) | |
|
|
||
| const char* GetDriverName() | ||
| { | ||
| #if RTTR_OGL_GL4ES == 1 | ||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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) {} | ||
|
|
@@ -75,6 +83,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()); | ||
|
|
@@ -116,7 +126,7 @@ 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 == 1)) | ||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| profile = SDL_GL_CONTEXT_PROFILE_ES; | ||
| else if((RTTR_OGL_COMPAT)) | ||
| profile = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY; | ||
|
|
@@ -414,6 +424,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; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -446,7 +500,11 @@ void VideoSDL2::ListVideoModes(std::vector<VideoMode>& video_modes) const | |
|
|
||
| OpenGL_Loader_Proc VideoSDL2::GetLoaderFunction() const | ||
| { | ||
| #if RTTR_OGL_GL4ES == 1 | ||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return gl4es_GetProcAddress; | ||
| #else | ||
| return SDL_GL_GetProcAddress; | ||
| #endif | ||
| } | ||
|
|
||
| void VideoSDL2::SetMousePos(Position pos) | ||
|
|
@@ -482,7 +540,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(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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -130,13 +130,25 @@ 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) | ||||||||||||||||||||||||
Flamefire marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| bfs::path path = System::getPathFromEnvVar("RTTR_" + id + "_DIR"); | ||||||||||||||||||||||||
| if(!path.empty()) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| LOG.write("Note: %1% path manually set to %2%\n", LogTarget::Stdout) % id % path; | ||||||||||||||||||||||||
| } else | ||||||||||||||||||||||||
| return defaultPath; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return path; | ||||||||||||||||||||||||
|
Comment on lines
+147
to
+153
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd try to avoid negated checks. Especially here it might be natural the other way round
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,20 @@ else() | |
| set(s25client_RC ) | ||
| endif() | ||
|
|
||
| add_executable(s25client s25client.cpp commands.cpp ${s25client_RC}) | ||
| target_link_libraries(s25client PRIVATE s25Main Boost::program_options Boost::nowide rttr::vld) | ||
| add_dependencies(s25client drivers) | ||
| if(RTTR_BUILD_LIB) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats the point I do not understand? why does the application needs to be a shared library? O.o
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An android app can't just execute an ELF binary. (security reasons) |
||
| add_library(s25client SHARED s25client.cpp commands.cpp ${s25client_RC}) | ||
| else() | ||
| add_executable(s25client s25client.cpp commands.cpp ${s25client_RC}) | ||
| endif() | ||
|
|
||
| if(ANDROID) | ||
| find_package(SDL2 2.0.5) # SDL2 android needs a specific sdl function(SDL_main) as entry point. | ||
| target_link_libraries(s25client PRIVATE s25Main Boost::program_options Boost::nowide rttr::vld SDL2::SDL2) | ||
| else() | ||
| target_link_libraries(s25client PRIVATE s25Main Boost::program_options Boost::nowide rttr::vld) | ||
| endif() | ||
|
|
||
| add_dependencies(s25client drivers translations) | ||
|
|
||
| if(WIN32) | ||
| target_include_directories(s25client PRIVATE ${rcDir}) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.