Skip to content

Commit

Permalink
platform: android: port to SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
Velaron committed Feb 16, 2024
1 parent 2c0d6e0 commit de7b317
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 24 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ jobs:
# - os: ubuntu-aarch64-20.04
# targetos: linux
# targetarch: aarch64

# - os: ubuntu-20.04
# targetos: android
# targetarch: 32
# - os: ubuntu-20.04
# targetos: android
# targetarch: 64

- os: ubuntu-20.04
targetos: android
targetarch: multiarch
# - os: ubuntu-20.04
# targetos: motomagx
# targetarch: armv6
Expand All @@ -51,7 +46,6 @@ jobs:
env:
SDL_VERSION: 2.28.5
GH_CPU_ARCH: ${{ matrix.targetarch }}
ANDROID_SDK_TOOLS_VER: 4333796
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
CMakeLists.txt*
CMakeScripts
Testing
compile_commands.json
_deps
# makedepend
Makefile.dep
*.bak
Expand Down
4 changes: 4 additions & 0 deletions engine/client/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,11 @@ void Con_RunConsole( void )
{
if( cls.state < ca_active || cl.first_frame )
con.showlines = refState.height; // full screen
#if XASH_MOBILE_PLATFORM
else con.showlines = refState.height; // always fullscreen on mobile
#else
else con.showlines = (refState.height >> 1); // half screen
#endif
}
else con.showlines = 0; // none visible

Expand Down
20 changes: 17 additions & 3 deletions engine/client/in_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2031,8 +2031,15 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx
// Hack for keyboard, hope it help
if( cls.key_dest == key_console || cls.key_dest == key_message )
{
if ( type == event_down ) // don't pop it again on event_up
static float x1 = 0.0f;
x1 += dx;

if ( type == event_up ) // don't show keyboard on every tap
{
Key_EnableTextInput( true, true );
x1 = 0.0f;
}

if( cls.key_dest == key_console )
{
static float y1 = 0;
Expand All @@ -2051,9 +2058,16 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx
}
}

// exit of console area
if( type == event_down && x < 0.1f && y > 0.9f )
// exit of console area
if( type == event_down && x < 0.1f && y > 0.9f )
Cbuf_AddText( "escape\n" );

// swipe from edge to exit console/chat
if(( x > 0.8f && x1 < -0.1f ) || ( x < 0.2f && x1 > 0.1f ))
{
Cbuf_AddText( "escape\n" );
x1 = 0.0f;
}
}
UI_MouseMove( TO_SCRN_X(x), TO_SCRN_Y(y) );
//MsgDev( D_NOTE, "touch %d %d\n", TO_SCRN_X(x), TO_SCRN_Y(y) );
Expand Down
2 changes: 2 additions & 0 deletions engine/platform/sdl/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,9 @@ static void SDLash_EventFilter( SDL_Event *event )
SDLash_ActiveEvent( false );
break;
case SDL_WINDOWEVENT_RESIZED:
#ifndef XASH_MOBILE_PLATFORM
if( vid_fullscreen.value == WINDOW_MODE_WINDOWED )
#endif
{
SDL_Window *wnd = SDL_GetWindowFromID( event->window.windowID );
VID_SaveWindowSize( event->window.data1, event->window.data2,
Expand Down
15 changes: 8 additions & 7 deletions engine/platform/sdl/vid_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode )
if( !glw_state.software )
SetBits( wndFlags, SDL_WINDOW_OPENGL );

#if !XASH_MOBILE_PLATFORM
if( window_mode == WINDOW_MODE_WINDOWED )
{
SDL_Rect r;
Expand Down Expand Up @@ -787,10 +786,6 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode )
SetBits( wndFlags, SDL_WINDOW_BORDERLESS );
xpos = ypos = 0;
}
#else
SetBits( wndFlags, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_INPUT_GRABBED );
xpos = ypos = SDL_WINDOWPOS_UNDEFINED;
#endif

if( !VID_CreateWindowWithSafeGL( wndname, xpos, ypos, width, height, wndFlags ))
return false;
Expand All @@ -799,14 +794,12 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode )
if( FBitSet( SDL_GetWindowFlags( host.hWnd ), SDL_WINDOW_MAXIMIZED|SDL_WINDOW_FULLSCREEN_DESKTOP ) != 0 )
SDL_GetWindowSize( host.hWnd, &width, &height );

#if !XASH_MOBILE_PLATFORM
if( window_mode != WINDOW_MODE_WINDOWED )
{
if( !VID_SetScreenResolution( width, height, window_mode ))
return false;
}
else VID_RestoreScreenResolution();
#endif

VID_SetWindowIcon( host.hWnd );
SDL_ShowWindow( host.hWnd );
Expand Down Expand Up @@ -1175,6 +1168,14 @@ qboolean VID_SetMode( void )
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}

#if XASH_MOBILE_PLATFORM
if( Q_strcmp( vid_fullscreen.string, DEFAULT_FULLSCREEN ))
{
Cvar_DirectSet( &vid_fullscreen, DEFAULT_FULLSCREEN );
Con_Reportf( S_ERROR "VID_SetMode: windowed unavailable on this platform\n" );
}
#endif

if( !FBitSet( vid_fullscreen.flags, FCVAR_CHANGED ))
Cvar_DirectSet( &vid_fullscreen, DEFAULT_FULLSCREEN );
else
Expand Down
3 changes: 2 additions & 1 deletion engine/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def build(bld):
app_name = 'xash3d-fwgs'
)
else:
if bld.env.DISABLE_LAUNCHER:
# always build as shared library on Android
if bld.env.DISABLE_LAUNCHER and bld.env.DEST_OS != "android":
install_path = bld.env.BINDIR
program = 'cxxprogram' if is_cxx_link else 'cprogram'
if bld.env.STATIC:
Expand Down
8 changes: 4 additions & 4 deletions scripts/gha/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export PATH=$PATH:$JAVA_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$AN

pushd android

./gradlew assembleContinuous
./gradlew assembleDebug

pushd app/build/outputs/apk/continuous
pushd app/build/outputs/apk/debug

$ANDROID_HOME/build-tools/34.0.0/apksigner sign --ks $GITHUB_WORKSPACE/android/debug.keystore --ks-key-alias androiddebugkey \
--ks-pass pass:android --key-pass pass:android --out app-continuous-signed.apk app-continuous-unsigned.apk
--ks-pass pass:android --key-pass pass:android --out app-debug-signed.apk app-debug.apk

popd
popd

mkdir -p artifacts/

mv android/app/build/outputs/apk/continuous/app-continuous-signed.apk artifacts/xash3d-fwgs-android.apk
mv android/app/build/outputs/apk/debug/app-debug-signed.apk artifacts/xash3d-fwgs-android.apk

0 comments on commit de7b317

Please sign in to comment.