Added support for embedded portable handhelds (#1781)

Initial changes required for running on Anbernic devices.

* Disabled SDL Joystick api as it conflicts with gptokeyb.
* Added resolution scaling changes

The changes I have made are for the following purposes:
- The game is run with a companion program that listens to the handhelds gamepad and translates it into
keyboard/mouse events, this allows more fine grained control and better portability between
devices/platforms. GemRB currently listens for the same events and is doubling up events, i have added an
option to disable the sdl controller api inside of gemrb. (-DSDL_DISABLE_CONTROLLER_API)
- The last option is to fix resolution independence on devices with higher resolution screens. These devices
do not run with an x windows server so the current fullscreen/windowed code doesn't scale up the screen
resolution. (-DSDL_RESOLUTION_INDEPENDANCE="ON")
This commit is contained in:
Jacob
2023-02-11 11:10:57 +01:00
committed by GitHub
parent 19a4483b13
commit 53dc55587f
6 changed files with 48 additions and 9 deletions
+5 -1
View File
@@ -97,6 +97,9 @@ OPTION(USE_FREETYPE "Enable FreeType support" ON)
OPTION(USE_PNG "Enable LibPNG support" ON)
OPTION(USE_VORBIS "Enable Vorbis support" ON)
OPTION(USE_SDL_CONTROLLER_API "Enable SDL controller APIs. (disable if you plan on handling controller input in an external program like gptokeyb)" ON)
OPTION(SDL_RESOLUTION_INDEPENDANCE "Scale the window to the size of the screen with pixel scaling." OFF)
#VCPKG dll deployment is circumvented because it doesn't currently work for gemrb
IF(WIN32 AND _VCPKG_INSTALLED_DIR)
OPTION(VCPKG_AUTO_DEPLOY "Fix VCPKG dependency DLL locations" ON)
@@ -391,7 +394,6 @@ IF(NOT OPENGL_BACKEND STREQUAL "None")
MESSAGE(FATAL_ERROR "OpenGLES2 library not found!")
ENDIF()
ENDIF()
ENDIF()
find_package(ZLIB REQUIRED)
@@ -672,6 +674,8 @@ PRINT_OPTION(INSOURCEBUILD)
PRINT_OPTION(DISABLE_WERROR)
PRINT_OPTION(WIN32_USE_STDIO)
PRINT_OPTION(SDL_BACKEND)
PRINT_OPTION(USE_SDL_CONTROLLER_API)
PRINT_OPTION(SDL_DISABLE_CONTROLLER_API)
PRINT_OPTION(PYTHON_VERSION)
PRINT_OPTION(OPENGL_BACKEND)
PRINT_OPTION(SANITIZE)
+1 -1
View File
@@ -37,7 +37,7 @@ Architectures and platforms that successfully run or ran GemRB:
* various Macintosh systems (even pre x86)
* some smart phones (Symbian, Android, other Linux-based, iOS)
* some consoles (OpenPandora, Dingoo)
* some exotic OSes (ReactOS, SyllableOS, Haiku, AmigaOS)
* some exotic OSes (ReactOS, SyllableOS, Haiku, AmigaOS, AmberElec, ArkOS, UnofficialOS)
If you have something to add to the list or if an entry doesn't work any more, do let us know!
+2
View File
@@ -25,4 +25,6 @@
#cmakedefine HAVE_MMAP ${HAVE_MMAP}
#cmakedefine SUPPORTS_MEMSTREAM ${SUPPORTS_MEMSTREAM}
#cmakedefine BAKE_ICON 1
#cmakedefine USE_SDL_CONTROLLER_API 1
#cmakedefine SDL_RESOLUTION_INDEPENDANCE 1
#endif
+4
View File
@@ -558,7 +558,11 @@ bool Window::DispatchEvent(const Event& event)
DispatchTouchUp(target, event.touch, event.mod);
break;
default:
#ifdef USE_SDL_CONTROLLER_API
// If controller api is not used, this maybe reached if a controller is used.
assert(false); // others should be handled above
#endif
break;
}
// absorb other screen events i guess
return true;
+32 -7
View File
@@ -86,6 +86,7 @@ int SDL20VideoDriver::Init()
{
int ret = SDLVideoDriver::Init();
#ifdef USE_SDL_CONTROLLER_API
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) {
Log(ERROR, "SDL2", "InitSubSystem failed: {}", SDL_GetError());
return ret;
@@ -99,6 +100,7 @@ int SDL20VideoDriver::Init()
}
}
}
#endif
return ret;
}
@@ -129,7 +131,25 @@ int SDL20VideoDriver::CreateSDLDisplay(const char* title)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
#endif
#ifdef SDL_RESOLUTION_INDEPENDANCE
SDL_DisplayMode current;
int should_be_zero = SDL_GetCurrentDisplayMode(0, &current);
if (should_be_zero != 0) {
Log(ERROR, "SDL 2 Driver", "couldnt get resolution: {}", SDL_GetError());
return GEM_ERROR;
}
Log(DEBUG, "SDL 2 Driver", "Game Resolution: {}x{}, Screen Resolution: {}x{}",
screenSize.w, screenSize.h, current.w, current.h);
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, current.w, current.h, winFlags);
#else
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenSize.w, screenSize.h, winFlags);
#endif
if (window == NULL) {
Log(ERROR, "SDL 2 Driver", "couldnt create window: {}", SDL_GetError());
return GEM_ERROR;
@@ -140,6 +160,15 @@ int SDL20VideoDriver::CreateSDLDisplay(const char* title)
#endif
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_ACCELERATED);
// Moved this here to fix a weird rendering issue
// we set logical size so that platforms where the window can be a diffrent size then requested
// function properly. eg iPhone and Android the requested size may be 640x480,
// but the window will always be the size of the screen
SDL_RenderSetLogicalSize(renderer, screenSize.w, screenSize.h);
//SDL_GetRendererOutputSize(renderer, &screenSize.w, &screenSize.h);
SDL_RendererInfo info;
SDL_GetRendererInfo(renderer, &info);
Log(DEBUG, "SDL20Video", "Renderer: {}", info.name);
@@ -192,12 +221,6 @@ int SDL20VideoDriver::CreateSDLDisplay(const char* title)
}
#endif
// we set logical size so that platforms where the window can be a diffrent size then requested
// function properly. eg iPhone and Android the requested size may be 640x480,
// but the window will always be the size of the screen
SDL_RenderSetLogicalSize(renderer, screenSize.w, screenSize.h);
//SDL_GetRendererOutputSize(renderer, &screenSize.w, &screenSize.h);
SDL_StopTextInput(); // for some reason this is enabled from start
return GEM_OK;
@@ -226,7 +249,7 @@ void SDL20VideoDriver::SwapBuffers(VideoBuffers& buffers)
blitRGBAShader->SetUniformValue("u_dither", 1, 0);
blitRGBAShader->SetUniformValue("u_rgba", 1, 1);
#endif
SDL_SetRenderTarget(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
@@ -675,6 +698,7 @@ int SDL20VideoDriver::ProcessEvent(const SDL_Event & event)
Event e;
switch (event.type) {
#ifdef USE_SDL_CONTROLLER_API
case SDL_CONTROLLERDEVICEREMOVED:
if (gameController != nullptr) {
const SDL_GameController *removedController = SDL_GameControllerFromInstanceID(event.jdevice.which);
@@ -710,6 +734,7 @@ int SDL20VideoDriver::ProcessEvent(const SDL_Event & event)
EvntManager->DispatchEvent(std::move(e));
}
break;
#endif
case SDL_FINGERDOWN: // fallthough
case SDL_FINGERUP:
{
+4
View File
@@ -207,6 +207,7 @@ int SDLVideoDriver::ProcessEvent(const SDL_Event & event)
}
}
break;
#ifdef USE_SDL_CONTROLLER_API
case SDL_JOYAXISMOTION:
{
float pct = event.jaxis.value / float(sizeof(Sint16));
@@ -227,6 +228,9 @@ int SDLVideoDriver::ProcessEvent(const SDL_Event & event)
EvntManager->DispatchEvent(std::move(e));
}
break;
#endif
default:
break;
}
return GEM_OK;
}