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 Nov 7, 2023
1 parent 0aa8a28 commit 7727b04
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 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.1
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 @@ -2093,7 +2093,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
16 changes: 13 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,12 @@ 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 )
// 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 @@ -1178,6 +1171,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
2 changes: 1 addition & 1 deletion engine/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def build(bld):
app_name = 'xash3d-fwgs'
)
else:
if bld.env.SINGLE_BINARY:
if bld.env.SINGLE_BINARY 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
2 changes: 1 addition & 1 deletion public/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def build(bld):
bld.stlib(source = bld.path.ant_glob('*.c'),
target = 'public',
features = 'c',
use = 'sdk_includes',
use = ['sdk_includes'],
subsystem = bld.env.MSVC_SUBSYSTEM)

if bld.env.TESTS:
Expand Down

0 comments on commit 7727b04

Please sign in to comment.