Skip to content

Commit

Permalink
Update from upstream
Browse files Browse the repository at this point in the history
also lower ram useage to 4GB from 8GB, hopefully this doesn't cause any issues
  • Loading branch information
SolDev69 committed Aug 30, 2024
2 parents 785ace8 + fa482de commit f2f5cd2
Show file tree
Hide file tree
Showing 24 changed files with 1,056 additions and 175 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
open_collective: pojavlauncher
patreon: pojavlauncher
4 changes: 2 additions & 2 deletions app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ configurations {
android {
namespace 'net.kdt.pojavlaunch'

compileSdk = 33
compileSdk = 34

lintOptions {
abortOnError false
Expand All @@ -114,7 +114,7 @@ android {
defaultConfig {
applicationId "net.kdt.pojavlaunch"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode getDateSeconds()
versionName getVersionName()
multiDexEnabled true //important
Expand Down
13 changes: 9 additions & 4 deletions app_pojavlauncher/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>

<application
android:name=".PojavApplication"
Expand Down Expand Up @@ -119,10 +121,13 @@
</intent-filter>
</provider>

<service android:name=".services.ProgressService" />
<service
android:name=".services.GameService"
android:process=":game" />
<service android:name=".services.ProgressService"
android:foregroundServiceType="dataSync"/>
<service android:name=".services.GameService" android:process=":game"
android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="This application is intended to run a 3rd-party piece of software which cannot be managed using the activity's saved instance state. This service is used for background persistence of this piece of software."/>
</service>
</application>
<queries>
<package android:name="net.kdt.pojavlaunch.ffmpeg"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static void execKeyIndex(int index){
sendKeyPress(getValueByIndex(index));
}

public static int getValueByIndex(int index) {
public static short getValueByIndex(int index) {
return sLwjglKeycodes[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import androidx.annotation.RequiresApi;

import net.kdt.pojavlaunch.customcontrols.ControlLayout;
import net.kdt.pojavlaunch.customcontrols.gamepad.DefaultDataProvider;
import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad;
import net.kdt.pojavlaunch.customcontrols.mouse.AbstractTouchpad;
import net.kdt.pojavlaunch.customcontrols.mouse.AndroidPointerCapture;
Expand Down Expand Up @@ -202,6 +203,10 @@ public boolean onTouchEvent(MotionEvent e) {
return mCurrentTouchProcessor.processTouchEvent(e);
}

private void createGamepad(View contextView, InputDevice inputDevice) {
mGamepad = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
}

/**
* The event for mouse/joystick movements
*/
Expand All @@ -211,9 +216,7 @@ public boolean dispatchGenericMotionEvent(MotionEvent event) {
int mouseCursorIndex = -1;

if(Gamepad.isGamepadEvent(event)){
if(mGamepad == null){
mGamepad = new Gamepad(this, event.getDevice());
}
if(mGamepad == null) createGamepad(this, event.getDevice());

mInputManager.handleMotionEventInput(getContext(), event, mGamepad);
return true;
Expand Down Expand Up @@ -285,9 +288,7 @@ public boolean processKeyEvent(KeyEvent event) {
}

if(Gamepad.isGamepadEvent(event)){
if(mGamepad == null){
mGamepad = new Gamepad(this, event.getDevice());
}
if(mGamepad == null) createGamepad(this, event.getDevice());

mInputManager.handleKeyEventInput(getContext(), event, mGamepad);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.kdt.pojavlaunch.customcontrols.gamepad;

import net.kdt.pojavlaunch.GrabListener;

import org.lwjgl.glfw.CallbackBridge;

public class DefaultDataProvider implements GamepadDataProvider {
public static final DefaultDataProvider INSTANCE = new DefaultDataProvider();

// Cannot instantiate this class publicly
private DefaultDataProvider() {}

@Override
public GamepadMap getGameMap() {
return GamepadMapStore.getGameMap();
}


@Override
public GamepadMap getMenuMap() {
return GamepadMapStore.getMenuMap();
}

@Override
public boolean isGrabbing() {
return CallbackBridge.isGrabbing();
}

@Override
public void attachGrabListener(GrabListener grabListener) {
CallbackBridge.addGrabListener(grabListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.core.content.res.ResourcesCompat;
import androidx.core.math.MathUtils;

import net.kdt.pojavlaunch.GrabListener;
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.utils.MCOptionUtils;

Expand Down Expand Up @@ -75,12 +73,11 @@ public class Gamepad implements GrabListener, GamepadHandler {
private double mMouseAngle;
private double mMouseSensitivity = 19;

private final GamepadMap mGameMap = GamepadMap.getDefaultGameMap();
private final GamepadMap mMenuMap = GamepadMap.getDefaultMenuMap();
private GamepadMap mCurrentMap = mGameMap;
private GamepadMap mGameMap;
private GamepadMap mMenuMap;
private GamepadMap mCurrentMap;

// The negation is to force trigger the onGrabState
private boolean isGrabbing = !CallbackBridge.isGrabbing();
private boolean isGrabbing;


/* Choreographer with time to compute delta on ticking */
Expand All @@ -91,7 +88,9 @@ public class Gamepad implements GrabListener, GamepadHandler {
@SuppressWarnings("FieldCanBeLocal") //the field is used in a WeakReference
private final MCOptionUtils.MCOptionListener mGuiScaleListener = () -> notifyGUISizeChange(getMcScale());

public Gamepad(View contextView, InputDevice inputDevice){
private final GamepadDataProvider mMapProvider;

public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);

mScreenChoreographer = Choreographer.getInstance();
Expand Down Expand Up @@ -120,16 +119,34 @@ public void doFrame(long frameTimeNanos) {
int size = (int) ((22 * getMcScale()) / mScaleFactor);
mPointerImageView.setLayoutParams(new FrameLayout.LayoutParams(size, size));

mMapProvider = mapProvider;

CallbackBridge.sendCursorPos(CallbackBridge.windowWidth/2f, CallbackBridge.windowHeight/2f);
((ViewGroup)contextView.getParent()).addView(mPointerImageView);

if(showCursor) {
((ViewGroup)contextView.getParent()).addView(mPointerImageView);
}


placePointerView(CallbackBridge.physicalWidth/2, CallbackBridge.physicalHeight/2);

CallbackBridge.addGrabListener(this);
reloadGamepadMaps();
mMapProvider.attachGrabListener(this);
}



public void reloadGamepadMaps() {
if(mGameMap != null) mGameMap.resetPressedState();
if(mMenuMap != null) mMenuMap.resetPressedState();
GamepadMapStore.load();
mGameMap = mMapProvider.getGameMap();
mMenuMap = mMapProvider.getMenuMap();
mCurrentMap = mGameMap;
// Force state refresh
boolean currentGrab = CallbackBridge.isGrabbing();
isGrabbing = !currentGrab;
onGrabState(currentGrab);
}

public void updateJoysticks(){
updateDirectionalJoystick();
Expand All @@ -144,29 +161,32 @@ public void notifyGUISizeChange(int newSize){
}


public static void sendInput(int[] keycodes, boolean isDown){
for(int keycode : keycodes){
public static void sendInput(short[] keycodes, boolean isDown){
for(short keycode : keycodes){
switch (keycode){
case GamepadMap.MOUSE_SCROLL_DOWN:
if(isDown) CallbackBridge.sendScroll(0, -1);
break;
case GamepadMap.MOUSE_SCROLL_UP:
if(isDown) CallbackBridge.sendScroll(0, 1);
break;

case LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT:
case GamepadMap.MOUSE_LEFT:
sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
break;
case GamepadMap.MOUSE_MIDDLE:
sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_MIDDLE, isDown);
break;
case GamepadMap.MOUSE_RIGHT:
sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
break;
case LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT:
sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
case GamepadMap.UNSPECIFIED:
break;


default:
sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
CallbackBridge.setModifiers(keycode, isDown);
break;
}
CallbackBridge.setModifiers(keycode, isDown);
}

}
Expand Down Expand Up @@ -261,32 +281,32 @@ private GamepadMap getCurrentMap(){
private static void sendDirectionalKeycode(int direction, boolean isDown, GamepadMap map){
switch (direction){
case DIRECTION_NORTH:
sendInput(map.DIRECTION_FORWARD, isDown);
map.DIRECTION_FORWARD.update(isDown);
break;
case DIRECTION_NORTH_EAST:
sendInput(map.DIRECTION_FORWARD, isDown);
sendInput(map.DIRECTION_RIGHT, isDown);
map.DIRECTION_FORWARD.update(isDown);
map.DIRECTION_RIGHT.update(isDown);
break;
case DIRECTION_EAST:
sendInput(map.DIRECTION_RIGHT, isDown);
map.DIRECTION_RIGHT.update(isDown);
break;
case DIRECTION_SOUTH_EAST:
sendInput(map.DIRECTION_RIGHT, isDown);
sendInput(map.DIRECTION_BACKWARD, isDown);
map.DIRECTION_RIGHT.update(isDown);
map.DIRECTION_BACKWARD.update(isDown);
break;
case DIRECTION_SOUTH:
sendInput(map.DIRECTION_BACKWARD, isDown);
map.DIRECTION_BACKWARD.update(isDown);
break;
case DIRECTION_SOUTH_WEST:
sendInput(map.DIRECTION_BACKWARD, isDown);
sendInput(map.DIRECTION_LEFT, isDown);
map.DIRECTION_BACKWARD.update(isDown);
map.DIRECTION_LEFT.update(isDown);
break;
case DIRECTION_WEST:
sendInput(map.DIRECTION_LEFT, isDown);
map.DIRECTION_LEFT.update(isDown);
break;
case DIRECTION_NORTH_WEST:
sendInput(map.DIRECTION_FORWARD, isDown);
sendInput(map.DIRECTION_LEFT, isDown);
map.DIRECTION_FORWARD.update(isDown);
map.DIRECTION_LEFT.update(isDown);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
package net.kdt.pojavlaunch.customcontrols.gamepad;

import android.view.KeyEvent;

/**
* Simple button able to store its state and some properties
* This class corresponds to a button that does exist on the gamepad
*/
public class GamepadButton {

public int[] keycodes;
public class GamepadButton extends GamepadEmulatedButton {
public boolean isToggleable = false;
private boolean mIsDown = false;
private boolean mIsToggled = false;

public void update(KeyEvent event){
boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN);
update(isKeyDown);
}

public void update(boolean isKeyDown){
if(isKeyDown != mIsDown){
mIsDown = isKeyDown;
if(isToggleable){
if(isKeyDown){
mIsToggled = !mIsToggled;
Gamepad.sendInput(keycodes, mIsToggled);
}
return;
}
Gamepad.sendInput(keycodes, mIsDown);
@Override
protected void onDownStateChanged(boolean isDown) {
if(isToggleable && isDown){
mIsToggled = !mIsToggled;
Gamepad.sendInput(keycodes, mIsToggled);
return;
}
super.onDownStateChanged(isDown);
}

public void resetButtonState(){
if(mIsDown || mIsToggled){
@Override
public void resetButtonState() {
if(!mIsDown && mIsToggled) {
Gamepad.sendInput(keycodes, false);
mIsToggled = false;
} else {
super.resetButtonState();
}
mIsDown = false;
mIsToggled = false;
}

public boolean isDown(){
return isToggleable ? mIsToggled : mIsDown;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.kdt.pojavlaunch.customcontrols.gamepad;

import net.kdt.pojavlaunch.GrabListener;

public interface GamepadDataProvider {
GamepadMap getMenuMap();
GamepadMap getGameMap();
boolean isGrabbing();
void attachGrabListener(GrabListener grabListener);
}
Loading

0 comments on commit f2f5cd2

Please sign in to comment.