Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01de8c8189 | ||
|
|
d8f429e3c5 | ||
|
|
23105df921 | ||
|
|
0c946cc637 | ||
|
|
61c8e574d7 | ||
|
|
2401262030 | ||
|
|
ee3435d52a |
No files matched your search
Binary file not shown.
@@ -1 +1 @@
|
||||
1738839797928
|
||||
1687691695196
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
1738839797913
|
||||
1692525087345
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
1738839797921
|
||||
1732218529630
|
||||
@@ -29,8 +29,6 @@ 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.gamepad.direct.DirectGamepad;
|
||||
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepadEnableHandler;
|
||||
import net.kdt.pojavlaunch.customcontrols.mouse.AbstractTouchpad;
|
||||
import net.kdt.pojavlaunch.customcontrols.mouse.AndroidPointerCapture;
|
||||
import net.kdt.pojavlaunch.customcontrols.mouse.InGUIEventProcessor;
|
||||
@@ -42,16 +40,15 @@ import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
||||
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
|
||||
import fr.spse.gamepad_remapper.GamepadHandler;
|
||||
import fr.spse.gamepad_remapper.RemapperManager;
|
||||
import fr.spse.gamepad_remapper.RemapperView;
|
||||
|
||||
/**
|
||||
* Class dealing with showing minecraft surface and taking inputs to dispatch them to minecraft
|
||||
*/
|
||||
public class MinecraftGLSurface extends View implements GrabListener, DirectGamepadEnableHandler {
|
||||
public class MinecraftGLSurface extends View implements GrabListener {
|
||||
/* Gamepad object for gamepad inputs, instantiated on need */
|
||||
private GamepadHandler mGamepadHandler;
|
||||
private Gamepad mGamepad = null;
|
||||
/* The RemapperView.Builder object allows you to set which buttons to remap */
|
||||
private final RemapperManager mInputManager = new RemapperManager(getContext(), new RemapperView.Builder(null)
|
||||
.remapA(true)
|
||||
@@ -91,7 +88,6 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
|
||||
public MinecraftGLSurface(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
setFocusable(true);
|
||||
CallbackBridge.setDirectGamepadEnableHandler(this);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@@ -207,11 +203,7 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
|
||||
}
|
||||
|
||||
private void createGamepad(View contextView, InputDevice inputDevice) {
|
||||
if(CallbackBridge.sGamepadDirectInput) {
|
||||
mGamepadHandler = new DirectGamepad();
|
||||
}else {
|
||||
mGamepadHandler = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
|
||||
}
|
||||
mGamepad = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,9 +215,9 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
|
||||
int mouseCursorIndex = -1;
|
||||
|
||||
if(Gamepad.isGamepadEvent(event)){
|
||||
if(mGamepadHandler == null) createGamepad(this, event.getDevice());
|
||||
if(mGamepad == null) createGamepad(this, event.getDevice());
|
||||
|
||||
mInputManager.handleMotionEventInput(getContext(), event, mGamepadHandler);
|
||||
mInputManager.handleMotionEventInput(getContext(), event, mGamepad);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -295,9 +287,9 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
|
||||
}
|
||||
|
||||
if(Gamepad.isGamepadEvent(event)){
|
||||
if(mGamepadHandler == null) createGamepad(this, event.getDevice());
|
||||
if(mGamepad == null) createGamepad(this, event.getDevice());
|
||||
|
||||
mInputManager.handleKeyEventInput(getContext(), event, mGamepadHandler);
|
||||
mInputManager.handleKeyEventInput(getContext(), event, mGamepad);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -419,17 +411,6 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectGamepadEnabled() {
|
||||
post(()->{
|
||||
if(mGamepadHandler != null && mGamepadHandler instanceof Gamepad) {
|
||||
((Gamepad)mGamepadHandler).removeSelf();
|
||||
}
|
||||
// Force gamepad recreation on next event
|
||||
mGamepadHandler = null;
|
||||
});
|
||||
}
|
||||
|
||||
/** A small interface called when the listener is ready for the first time */
|
||||
public interface SurfaceReadyListener {
|
||||
void isReady();
|
||||
|
||||
@@ -325,14 +325,6 @@ public final class Tools {
|
||||
}
|
||||
javaArgList.add("-Dlog4j.configurationFile=" + configFile);
|
||||
}
|
||||
|
||||
File versionSpecificNativesDir = new File(Tools.DIR_CACHE, "natives/"+versionId);
|
||||
if(versionSpecificNativesDir.exists()) {
|
||||
String dirPath = versionSpecificNativesDir.getAbsolutePath();
|
||||
javaArgList.add("-Djava.library.path="+dirPath+":"+Tools.NATIVE_LIB_DIR);
|
||||
javaArgList.add("-Djna.boot.library.path="+dirPath);
|
||||
}
|
||||
|
||||
javaArgList.addAll(Arrays.asList(getMinecraftJVMArgs(versionId, gamedir)));
|
||||
javaArgList.add("-cp");
|
||||
javaArgList.add(launchClassPath + ":" + getLWJGL3ClassPath());
|
||||
|
||||
-5
@@ -30,9 +30,4 @@ public class DefaultDataProvider implements GamepadDataProvider {
|
||||
public void attachGrabListener(GrabListener grabListener) {
|
||||
CallbackBridge.addGrabListener(grabListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachGrabListener(GrabListener grabListener) {
|
||||
CallbackBridge.removeGrabListener(grabListener);
|
||||
}
|
||||
}
|
||||
+2
-14
@@ -26,6 +26,7 @@ import androidx.core.math.MathUtils;
|
||||
import net.kdt.pojavlaunch.GrabListener;
|
||||
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
||||
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
@@ -87,8 +88,6 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
||||
|
||||
private final GamepadDataProvider mMapProvider;
|
||||
|
||||
private boolean mRemoved = false;
|
||||
|
||||
public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){
|
||||
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
|
||||
|
||||
@@ -97,7 +96,7 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
||||
@Override
|
||||
public void doFrame(long frameTimeNanos) {
|
||||
tick(frameTimeNanos);
|
||||
if(!mRemoved) mScreenChoreographer.postFrameCallback(this);
|
||||
mScreenChoreographer.postFrameCallback(this);
|
||||
}
|
||||
};
|
||||
mScreenChoreographer.postFrameCallback(frameCallback);
|
||||
@@ -454,15 +453,4 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the Gamepad and removes all traces of the Gamepad from the view hierarchy.
|
||||
* After this call, the Gamepad is not recoverable and a new one must be made.
|
||||
*/
|
||||
public void removeSelf() {
|
||||
mRemoved = true;
|
||||
mMapProvider.detachGrabListener(this);
|
||||
ViewGroup viewGroup = (ViewGroup) mPointerImageView.getParent();
|
||||
if(viewGroup != null) viewGroup.removeView(mPointerImageView);
|
||||
}
|
||||
}
|
||||
-1
@@ -7,5 +7,4 @@ public interface GamepadDataProvider {
|
||||
GamepadMap getGameMap();
|
||||
boolean isGrabbing();
|
||||
void attachGrabListener(GrabListener grabListener);
|
||||
void detachGrabListener(GrabListener grabListener);
|
||||
}
|
||||
-5
@@ -325,11 +325,6 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
||||
grabListener.onGrabState(mGrabState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachGrabListener(GrabListener grabListener) {
|
||||
mGamepadGrabListener = null;
|
||||
}
|
||||
|
||||
public void setGrabState(boolean newState) {
|
||||
mGrabState = newState;
|
||||
if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState);
|
||||
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
|
||||
|
||||
import static org.lwjgl.glfw.CallbackBridge.sGamepadAxisBuffer;
|
||||
import static org.lwjgl.glfw.CallbackBridge.sGamepadButtonBuffer;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import fr.spse.gamepad_remapper.GamepadHandler;
|
||||
|
||||
public class DirectGamepad implements GamepadHandler {
|
||||
@Override
|
||||
public void handleGamepadInput(int keycode, float value) {
|
||||
int gKeycode = -1, gAxis = -1;
|
||||
switch (keycode) {
|
||||
case KeyEvent.KEYCODE_BUTTON_A: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_A; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_B: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_B; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_X: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_X; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_Y: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_Y; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_L1: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_LEFT_BUMPER; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_R1: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_L2:
|
||||
case MotionEvent.AXIS_LTRIGGER:
|
||||
gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER;
|
||||
break;
|
||||
case KeyEvent.KEYCODE_BUTTON_R2:
|
||||
case MotionEvent.AXIS_RTRIGGER:
|
||||
gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER;
|
||||
break;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBL: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_LEFT_THUMB; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBR: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_START: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_START; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_SELECT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_BACK; break;
|
||||
case KeyEvent.KEYCODE_DPAD_UP: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP; break;
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN; break;
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT; break;
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT; break;
|
||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||
// Behave the same way as the Gamepad here, as GLFW doesn't have a keycode
|
||||
// for the dpad center.
|
||||
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP, GamepadKeycodes.GLFW_RELEASE);
|
||||
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN, GamepadKeycodes.GLFW_RELEASE);
|
||||
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT, GamepadKeycodes.GLFW_RELEASE);
|
||||
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, GamepadKeycodes.GLFW_RELEASE);
|
||||
return;
|
||||
case MotionEvent.AXIS_X: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_X; break;
|
||||
case MotionEvent.AXIS_Y: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_Y; break;
|
||||
case MotionEvent.AXIS_Z: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_X; break;
|
||||
case MotionEvent.AXIS_RZ: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_Y; break;
|
||||
case MotionEvent.AXIS_HAT_X:
|
||||
sGamepadButtonBuffer.put(
|
||||
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT,
|
||||
value < -0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
|
||||
);
|
||||
sGamepadButtonBuffer.put(
|
||||
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT,
|
||||
value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
|
||||
);
|
||||
return;
|
||||
case MotionEvent.AXIS_HAT_Y:
|
||||
sGamepadButtonBuffer.put(
|
||||
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP,
|
||||
value < -0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
|
||||
);
|
||||
sGamepadButtonBuffer.put(
|
||||
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
|
||||
value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
|
||||
);
|
||||
return;
|
||||
}
|
||||
if(gKeycode != -1) {
|
||||
sGamepadButtonBuffer.put(gKeycode, value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE);
|
||||
}
|
||||
if(gAxis != -1) {
|
||||
sGamepadAxisBuffer.put(gAxis, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
|
||||
|
||||
/**
|
||||
* Interface that is called once when the GLFW implementation requests to switch from
|
||||
* the default gamepad implementation to the direct one. The implementor of this interface
|
||||
* must take the necessary steps to disable the default gamepad implementation and replace
|
||||
* it with an instance of DirectGamepad.
|
||||
|
||||
* This is useful for switching from default to direct input after the user has already
|
||||
* interacted with the gamepad.
|
||||
*/
|
||||
public interface DirectGamepadEnableHandler {
|
||||
/**
|
||||
* Called once when GLFW requests switching the gamepad mode from default to direct.
|
||||
*/
|
||||
void onDirectGamepadEnabled();
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
|
||||
|
||||
public class GamepadKeycodes {
|
||||
public static final byte GLFW_RELEASE = 0;
|
||||
public static final byte GLFW_PRESS = 1;
|
||||
|
||||
public static final short GLFW_GAMEPAD_BUTTON_A = 0;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_B = 1;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_X = 2;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_Y = 3;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_LEFT_BUMPER = 4;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_BACK = 6;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_START = 7;
|
||||
// Home button, unused because Android takes the home button events
|
||||
// for itself
|
||||
public static final short GLFW_GAMEPAD_BUTTON_GUIDE = 8;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_LEFT_THUMB = 9;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_RIGHT_THUMB = 10;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_DPAD_UP = 11;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_DPAD_RIGHT = 12;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_DPAD_DOWN = 13;
|
||||
public static final short GLFW_GAMEPAD_BUTTON_DPAD_LEFT = 14;
|
||||
|
||||
public static final short GLFW_GAMEPAD_AXIS_LEFT_X = 0;
|
||||
public static final short GLFW_GAMEPAD_AXIS_LEFT_Y = 1;
|
||||
public static final short GLFW_GAMEPAD_AXIS_RIGHT_X = 2;
|
||||
public static final short GLFW_GAMEPAD_AXIS_RIGHT_Y = 3;
|
||||
public static final short GLFW_GAMEPAD_AXIS_LEFT_TRIGGER = 4;
|
||||
public static final short GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
|
||||
}
|
||||
+2
@@ -2,6 +2,8 @@ package net.kdt.pojavlaunch.prefs.screens;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
@@ -39,10 +39,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class MinecraftDownloader {
|
||||
private static final double ONE_MEGABYTE = (1024d * 1024d);
|
||||
public static final String MINECRAFT_RES = "https://resources.download.minecraft.net/";
|
||||
private static final String MAVEN_CENTRAL_REPO1 = "https://repo1.maven.org/maven2/";
|
||||
private AtomicReference<Exception> mDownloaderThreadException;
|
||||
private ArrayList<DownloaderTask> mScheduledDownloadTasks;
|
||||
private ArrayList<File> mDeclaredNatives;
|
||||
private AtomicLong mProcessedFileCounter;
|
||||
private AtomicLong mProcessedSizeCounter; // Total bytes of processed files (passed SHA1 or downloaded)
|
||||
private AtomicLong mInternetUsageCounter; // How many bytes downloaded over Internet
|
||||
@@ -90,7 +88,6 @@ public class MinecraftDownloader {
|
||||
|
||||
mTargetJarFile = createGameJarPath(versionName);
|
||||
mScheduledDownloadTasks = new ArrayList<>();
|
||||
mDeclaredNatives = new ArrayList<>();
|
||||
mProcessedFileCounter = new AtomicLong(0);
|
||||
mProcessedSizeCounter = new AtomicLong(0);
|
||||
mInternetUsageCounter = new AtomicLong(0);
|
||||
@@ -123,7 +120,6 @@ public class MinecraftDownloader {
|
||||
throw thrownException;
|
||||
} else {
|
||||
ensureJarFileCopy();
|
||||
extractNatives(versionName);
|
||||
}
|
||||
}catch (InterruptedException e) {
|
||||
// Interrupted while waiting, which means that the download was cancelled.
|
||||
@@ -171,25 +167,6 @@ public class MinecraftDownloader {
|
||||
org.apache.commons.io.FileUtils.copyFile(mSourceJarFile, mTargetJarFile, false);
|
||||
}
|
||||
|
||||
private void extractNatives(String versionName) throws IOException {
|
||||
if(mDeclaredNatives.isEmpty()) return;
|
||||
int totalCount = mDeclaredNatives.size();
|
||||
|
||||
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, 0,
|
||||
R.string.newdl_extracting_native_libraries, 0, totalCount);
|
||||
|
||||
File targetDirectory = new File(Tools.DIR_CACHE, "natives/"+versionName);
|
||||
FileUtils.ensureDirectory(targetDirectory);
|
||||
NativesExtractor nativesExtractor = new NativesExtractor(targetDirectory);
|
||||
int extractedCount = 0;
|
||||
for(File source : mDeclaredNatives) {
|
||||
nativesExtractor.extractFromAar(source);
|
||||
extractedCount++;
|
||||
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, extractedCount * 100 / totalCount,
|
||||
R.string.newdl_extracting_native_libraries, extractedCount, totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
private File downloadGameJson(JMinecraftVersionList.Version verInfo) throws IOException, MirrorTamperedException {
|
||||
File targetFile = createGameJsonPath(verInfo.id);
|
||||
if(verInfo.sha1 == null && targetFile.canRead() && targetFile.isFile())
|
||||
@@ -279,8 +256,7 @@ public class MinecraftDownloader {
|
||||
long size, boolean skipIfFailed) throws IOException {
|
||||
FileUtils.ensureParentDirectory(targetFile);
|
||||
mTotalFileCount++;
|
||||
// Only attempt to check size if we still use the size counter and didn't switch to file counter.
|
||||
if(size <= 0 && !mUseFileCounter) {
|
||||
if(size < 0) {
|
||||
size = DownloadMirror.getContentLengthMirrored(downloadClass, url);
|
||||
}
|
||||
if(size < 0) {
|
||||
@@ -297,31 +273,13 @@ public class MinecraftDownloader {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the download of an AAR library containing the required natives, for later extraction
|
||||
* and adding to the library path.
|
||||
* @param baseRepository the source Maven repository to download from.
|
||||
* @param dependentLibrary the DependentLibrary to get the path from
|
||||
* @throws IOException in case if download scheduling fails.
|
||||
*/
|
||||
private void scheduleNativeLibraryDownload(String baseRepository, DependentLibrary dependentLibrary) throws IOException {
|
||||
String path = FileUtils.removeExtension(Tools.artifactToPath(dependentLibrary)) + ".aar";
|
||||
String downloadUrl = baseRepository + path;
|
||||
File targetPath = new File(Tools.DIR_HOME_LIBRARY, path);
|
||||
mDeclaredNatives.add(targetPath);
|
||||
scheduleDownload(targetPath, DownloadMirror.DOWNLOAD_CLASS_LIBRARIES, downloadUrl, null, 0, true);
|
||||
}
|
||||
|
||||
private void scheduleLibraryDownloads(DependentLibrary[] dependentLibraries) throws IOException {
|
||||
Tools.preProcessLibraries(dependentLibraries);
|
||||
growDownloadList(dependentLibraries.length);
|
||||
for(DependentLibrary dependentLibrary : dependentLibraries) {
|
||||
// Don't download lwjgl, we have our own bundled in.
|
||||
if(dependentLibrary.name.startsWith("org.lwjgl")) continue;
|
||||
// Special handling for JNA Android natives
|
||||
if(dependentLibrary.name.startsWith("net.java.dev.jna:jna:")) {
|
||||
scheduleNativeLibraryDownload(MAVEN_CENTRAL_REPO1, dependentLibrary);
|
||||
}
|
||||
|
||||
String libArtifactPath = Tools.artifactToPath(dependentLibrary);
|
||||
String sha1 = null, url = null;
|
||||
long size = 0;
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
package net.kdt.pojavlaunch.tasks;
|
||||
|
||||
import net.kdt.pojavlaunch.Architecture;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.utils.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class NativesExtractor {
|
||||
private static final ArrayList<String> LIBRARY_BLACKLIST = createLibraryBlacklist();
|
||||
private final File mDestinationDir;
|
||||
private final String mLibraryLocation;
|
||||
|
||||
public NativesExtractor(File mDestinationDir) {
|
||||
this.mDestinationDir = mDestinationDir;
|
||||
this.mLibraryLocation = "jni/"+getAarArchitectureName()+"/";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a library blacklist so that downloaded natives are not able to
|
||||
* override built-in libraries.
|
||||
* @return the resulting blacklist of library file names
|
||||
*/
|
||||
private static ArrayList<String> createLibraryBlacklist() {
|
||||
String[] includedLibraryNames = new File(Tools.NATIVE_LIB_DIR).list();
|
||||
ArrayList<String> blacklist = new ArrayList<>(includedLibraryNames.length);
|
||||
for(String libraryName : includedLibraryNames) {
|
||||
// allow overriding jnidispatch (as the integrated version may be too old)
|
||||
if(libraryName.equals("libjnidispatch.so")) continue;
|
||||
blacklist.add(libraryName);
|
||||
}
|
||||
blacklist.trimToSize();
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
private static String getAarArchitectureName() {
|
||||
int architecture = Architecture.getDeviceArchitecture();
|
||||
switch (architecture) {
|
||||
case Architecture.ARCH_ARM:
|
||||
return "armeabi-v7a";
|
||||
case Architecture.ARCH_ARM64:
|
||||
return "arm64-v8a";
|
||||
case Architecture.ARCH_X86:
|
||||
return "x86";
|
||||
case Architecture.ARCH_X86_64:
|
||||
return "x86_64";
|
||||
}
|
||||
throw new RuntimeException("Unknown CPU architecture: "+architecture);
|
||||
}
|
||||
|
||||
public void extractFromAar(File source) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
try (FileInputStream fileInputStream = new FileInputStream(source);
|
||||
ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) {
|
||||
// Wrap the ZIP input stream into a non-closeable stream to
|
||||
// avoid it being closed by processEntry()
|
||||
NonCloseableInputStream entryCopyStream = new NonCloseableInputStream(zipInputStream);
|
||||
ZipEntry entry;
|
||||
while((entry = zipInputStream.getNextEntry()) != null) {
|
||||
String entryName = entry.getName();
|
||||
if(!entryName.startsWith(mLibraryLocation) || entry.isDirectory()) continue;
|
||||
// Entry name is actually the full path, so we need to strip the path before extraction
|
||||
entryName = FileUtils.getFileName(entryName);
|
||||
// getFileName may make the file name null, avoid that case.
|
||||
if(entryName == null || LIBRARY_BLACKLIST.contains(entryName)) continue;
|
||||
|
||||
processEntry(entryCopyStream, entry, new File(mDestinationDir, entryName), buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long fileCrc32(File target, byte[] buffer) throws IOException {
|
||||
try(FileInputStream fileInputStream = new FileInputStream(target)) {
|
||||
CRC32 crc32 = new CRC32();
|
||||
int len;
|
||||
while((len = fileInputStream.read(buffer)) != -1) {
|
||||
crc32.update(buffer, 0, len);
|
||||
}
|
||||
return crc32.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
private void processEntry(InputStream sourceStream, ZipEntry zipEntry, File entryDestination, byte[] buffer) throws IOException {
|
||||
if(entryDestination.exists()) {
|
||||
long expectedSize = zipEntry.getSize();
|
||||
long expectedCrc32 = zipEntry.getCrc();
|
||||
long realSize = entryDestination.length();
|
||||
long realCrc32 = fileCrc32(entryDestination, buffer);
|
||||
// File in archive is the same as the local one, don't extract
|
||||
if(realSize == expectedSize && realCrc32 == expectedCrc32) return;
|
||||
}
|
||||
// copyInputStreamToFile copies the stream to a file and then closes it.
|
||||
org.apache.commons.io.FileUtils.copyInputStreamToFile(sourceStream, entryDestination);
|
||||
}
|
||||
|
||||
|
||||
private static class NonCloseableInputStream extends FilterInputStream {
|
||||
|
||||
protected NonCloseableInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Do nothing (the point of this class)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,6 @@ public class FileUtils {
|
||||
return pathOrUrl.substring(lastSlashIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the extension (all text after the last dot) from a path/URL string.
|
||||
* @param pathOrUrl the path or the URL of the file
|
||||
* @return the input with the extension removed
|
||||
*/
|
||||
public static String removeExtension(String pathOrUrl) {
|
||||
int lastDotIndex = pathOrUrl.lastIndexOf('.');
|
||||
if(lastDotIndex == -1) return pathOrUrl;
|
||||
return pathOrUrl.substring(0, lastDotIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that a directory exists, is a directory and is writable.
|
||||
* @param targetFile the directory to check
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.lwjgl.glfw;
|
||||
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepadEnableHandler;
|
||||
|
||||
import android.content.*;
|
||||
import android.util.Log;
|
||||
import android.view.Choreographer;
|
||||
@@ -10,10 +8,6 @@ import android.view.Choreographer;
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dalvik.annotation.optimization.CriticalNative;
|
||||
@@ -22,8 +16,6 @@ public class CallbackBridge {
|
||||
public static final Choreographer sChoreographer = Choreographer.getInstance();
|
||||
private static boolean isGrabbing = false;
|
||||
private static final ArrayList<GrabListener> grabListeners = new ArrayList<>();
|
||||
// Use a weak reference here to avoid possibly statically referencing a Context.
|
||||
private static @Nullable WeakReference<DirectGamepadEnableHandler> sDirectGamepadEnableHandler;
|
||||
|
||||
public static final int CLIPBOARD_COPY = 2000;
|
||||
public static final int CLIPBOARD_PASTE = 2001;
|
||||
@@ -35,10 +27,6 @@ public class CallbackBridge {
|
||||
public volatile static boolean holdingAlt, holdingCapslock, holdingCtrl,
|
||||
holdingNumlock, holdingShift;
|
||||
|
||||
public static final ByteBuffer sGamepadButtonBuffer;
|
||||
public static final FloatBuffer sGamepadAxisBuffer;
|
||||
public static boolean sGamepadDirectInput = false;
|
||||
|
||||
public static void putMouseEventWithCoords(int button, float x, float y) {
|
||||
putMouseEventWithCoords(button, true, x, y);
|
||||
sChoreographer.postFrameCallbackDelayed(l -> putMouseEventWithCoords(button, false, x, y), 33);
|
||||
@@ -177,16 +165,6 @@ public class CallbackBridge {
|
||||
}
|
||||
}
|
||||
|
||||
//Called from JRE side
|
||||
@SuppressWarnings("unused")
|
||||
@Keep
|
||||
private static void onDirectInputEnable() {
|
||||
Log.i("CallbackBridge", "onDirectInputEnable()");
|
||||
DirectGamepadEnableHandler enableHandler = Tools.getWeakReference(sDirectGamepadEnableHandler);
|
||||
if(enableHandler != null) enableHandler.onDirectGamepadEnabled();
|
||||
sGamepadDirectInput = true;
|
||||
}
|
||||
|
||||
//Called from JRE side
|
||||
@SuppressWarnings("unused")
|
||||
@Keep
|
||||
@@ -216,16 +194,6 @@ public class CallbackBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static FloatBuffer createGamepadAxisBuffer() {
|
||||
ByteBuffer axisByteBuffer = nativeCreateGamepadAxisBuffer();
|
||||
// NOTE: hardcoded order (also in jre_lwjgl3glfw CallbackBridge)
|
||||
return axisByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
||||
}
|
||||
|
||||
public static void setDirectGamepadEnableHandler(DirectGamepadEnableHandler h) {
|
||||
sDirectGamepadEnableHandler = new WeakReference<>(h);
|
||||
}
|
||||
|
||||
@Keep @CriticalNative public static native void nativeSetUseInputStackQueue(boolean useInputStackQueue);
|
||||
|
||||
@Keep @CriticalNative private static native boolean nativeSendChar(char codepoint);
|
||||
@@ -238,12 +206,8 @@ public class CallbackBridge {
|
||||
@Keep @CriticalNative private static native void nativeSendScroll(double xoffset, double yoffset);
|
||||
@Keep @CriticalNative private static native void nativeSendScreenSize(int width, int height);
|
||||
public static native void nativeSetWindowAttrib(int attrib, int value);
|
||||
private static native ByteBuffer nativeCreateGamepadButtonBuffer();
|
||||
private static native ByteBuffer nativeCreateGamepadAxisBuffer();
|
||||
static {
|
||||
System.loadLibrary("pojavexec");
|
||||
sGamepadButtonBuffer = nativeCreateGamepadButtonBuffer();
|
||||
sGamepadAxisBuffer = createGamepadAxisBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,6 @@ typedef void GLFW_invoke_Key_func(void* window, int key, int scancode, int actio
|
||||
typedef void GLFW_invoke_MouseButton_func(void* window, int button, int action, int mods);
|
||||
typedef void GLFW_invoke_Scroll_func(void* window, double xoffset, double yoffset);
|
||||
|
||||
typedef struct {
|
||||
unsigned char buttons [15];
|
||||
float axes[6];
|
||||
} GLFWgamepadstate;
|
||||
|
||||
struct pojav_environ_s {
|
||||
struct ANativeWindow* pojavWindow;
|
||||
basic_render_window_t* mainWindowBundle;
|
||||
@@ -47,7 +42,6 @@ struct pojav_environ_s {
|
||||
double cursorX, cursorY, cLastX, cLastY;
|
||||
jmethodID method_accessAndroidClipboard;
|
||||
jmethodID method_onGrabStateChanged;
|
||||
jmethodID method_onDirectInputEnable;
|
||||
jmethodID method_glftSetWindowAttrib;
|
||||
jmethodID method_internalWindowSizeChanged;
|
||||
jmethodID method_internalChangeMonitorSize;
|
||||
@@ -63,7 +57,6 @@ struct pojav_environ_s {
|
||||
bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse;
|
||||
bool shouldUpdateMonitorSize, monitorSizeConsumed;
|
||||
int savedWidth, savedHeight;
|
||||
GLFWgamepadstate gamepadState;
|
||||
#define ADD_CALLBACK_WWIN(NAME) \
|
||||
GLFW_invoke_##NAME##_func* GLFW_invoke_##NAME;
|
||||
ADD_CALLBACK_WWIN(Char);
|
||||
|
||||
@@ -32,15 +32,6 @@
|
||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||
#define EVENT_TYPE_SCROLL 1007
|
||||
|
||||
#define TRY_ATTACH_ENV(env_name, vm, error_message, then) JNIEnv* env_name;\
|
||||
do { \
|
||||
env_name = get_attached_env(vm); \
|
||||
if(env_name == NULL) { \
|
||||
printf(error_message); \
|
||||
then \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static void registerFunctions(JNIEnv *env);
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
@@ -53,7 +44,6 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
pojav_environ->bridgeClazz = (*dvEnv)->NewGlobalRef(dvEnv,(*dvEnv) ->FindClass(dvEnv,"org/lwjgl/glfw/CallbackBridge"));
|
||||
pojav_environ->method_accessAndroidClipboard = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "accessAndroidClipboard", "(ILjava/lang/String;)Ljava/lang/String;");
|
||||
pojav_environ->method_onGrabStateChanged = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
|
||||
pojav_environ->method_onDirectInputEnable = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onDirectInputEnable", "()V");
|
||||
pojav_environ->isUseStackQueueCall = JNI_FALSE;
|
||||
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
|
||||
LOGI("Saving JVM environ...");
|
||||
@@ -259,7 +249,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
||||
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
|
||||
assert(dalvikEnv != NULL);
|
||||
assert(pojav_environ->bridgeClazz != NULL);
|
||||
|
||||
|
||||
LOGD("Clipboard: Converting string\n");
|
||||
char *copySrcC;
|
||||
jstring copyDst = NULL;
|
||||
@@ -272,7 +262,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
||||
jstring pasteDst = convertStringJVM(dalvikEnv, env, (jstring) (*dalvikEnv)->CallStaticObjectMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_accessAndroidClipboard, action, copyDst));
|
||||
|
||||
if (copySrc) {
|
||||
(*dalvikEnv)->DeleteLocalRef(dalvikEnv, copyDst);
|
||||
(*dalvikEnv)->DeleteLocalRef(dalvikEnv, copyDst);
|
||||
(*env)->ReleaseByteArrayElements(env, copySrc, (jbyte *)copySrcC, 0);
|
||||
}
|
||||
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
|
||||
@@ -293,18 +283,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputRead
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean grabbing) {
|
||||
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeSetGrabbing failed!\n", return;);
|
||||
(*dvm_env)->CallStaticVoidMethod(dvm_env, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
|
||||
JNIEnv *dalvikEnv;
|
||||
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
|
||||
(*dalvikEnv)->CallStaticVoidMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
|
||||
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
|
||||
pojav_environ->isGrabbing = grabbing;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeEnableGamepadDirectInput(__attribute__((unused)) JNIEnv *env, __attribute__((unused)) jclass clazz) {
|
||||
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeEnableGamepadDirectInput failed!\n", return JNI_FALSE;);
|
||||
(*dvm_env)->CallStaticVoidMethod(dvm_env, pojav_environ->bridgeClazz, pojav_environ->method_onDirectInputEnable);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jboolean critical_send_char(jchar codepoint) {
|
||||
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
|
||||
if (pojav_environ->isUseStackQueueCall) {
|
||||
@@ -464,7 +449,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(
|
||||
// in environ for the Android UI thread but this is the only place that uses it
|
||||
// (very rarely, only in lifecycle callbacks) so i dont care
|
||||
|
||||
TRY_ATTACH_ENV(jvm_env, pojav_environ->runtimeJavaVMPtr, "nativeSetWindowAttrib failed: %i", return;);
|
||||
JNIEnv *jvm_env = get_attached_env(pojav_environ->runtimeJavaVMPtr);
|
||||
|
||||
(*jvm_env)->CallStaticVoidMethod(
|
||||
jvm_env, pojav_environ->vmGlfwClass,
|
||||
@@ -539,18 +524,3 @@ static void registerFunctions(JNIEnv *env) {
|
||||
use_critical_cc ? critical_fcns : noncritical_fcns,
|
||||
sizeof(critical_fcns)/sizeof(critical_fcns[0]));
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_lwjgl_glfw_GLFW_internalGetGamepadDataPointer(JNIEnv *env, jclass clazz) {
|
||||
return (jlong) &pojav_environ->gamepadState;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadButtonBuffer(JNIEnv *env, jclass clazz) {
|
||||
return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.buttons, sizeof(pojav_environ->gamepadState.buttons));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadAxisBuffer(JNIEnv *env, jclass clazz) {
|
||||
return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.axes, sizeof(pojav_environ->gamepadState.axes));
|
||||
}
|
||||
@@ -164,7 +164,7 @@ JNIEnv* get_attached_env(JavaVM* jvm) {
|
||||
env_result = (*jvm)->AttachCurrentThread(jvm, &jvm_env, NULL);
|
||||
}
|
||||
if(env_result != JNI_OK) {
|
||||
printf("get_attached_env failed: %i\n", env_result);
|
||||
printf("get_attached_env failed: %i", env_result);
|
||||
return NULL;
|
||||
}
|
||||
return jvm_env;
|
||||
|
||||
@@ -429,5 +429,4 @@
|
||||
<string name="bta_installer_available_versions">Supported BTA versions</string>
|
||||
<string name="bta_installer_untested_versions">Untested BTA versions</string>
|
||||
<string name="bta_installer_nightly_versions">Nightly BTA versions</string>
|
||||
<string name="newdl_extracting_native_libraries">Extracting native libraries (%d/%d)</string>
|
||||
</resources>
|
||||
Binary file not shown.
@@ -1,5 +1,4 @@
|
||||
package org.lwjgl.glfw;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
public class CallbackBridge {
|
||||
@@ -19,8 +18,6 @@ public class CallbackBridge {
|
||||
public static final int ANDROID_TYPE_GRAB_STATE = 0;
|
||||
|
||||
public static final boolean INPUT_DEBUG_ENABLED;
|
||||
|
||||
public static boolean sGamepadDirectEnabled;
|
||||
|
||||
// TODO send grab state event to Android
|
||||
|
||||
@@ -43,11 +40,6 @@ public class CallbackBridge {
|
||||
}
|
||||
|
||||
|
||||
public static void enableGamepadDirectInput() {
|
||||
if(sGamepadDirectEnabled) return;
|
||||
sGamepadDirectEnabled = nativeEnableGamepadDirectInput();
|
||||
}
|
||||
|
||||
public static void sendData(int type, String data) {
|
||||
nativeSendData(false, type, data);
|
||||
}
|
||||
@@ -55,8 +47,5 @@ public class CallbackBridge {
|
||||
public static native boolean nativeSetInputReady(boolean ready);
|
||||
public static native String nativeClipboard(int action, byte[] copy);
|
||||
public static native void nativeSetGrabbing(boolean grab);
|
||||
public static native ByteBuffer nativeCreateGamepadButtonBuffer();
|
||||
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
|
||||
private static native boolean nativeEnableGamepadDirectInput();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.annotation.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.system.*;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
import static org.lwjgl.system.APIUtil.*;
|
||||
@@ -25,9 +24,8 @@ import java.util.*;
|
||||
|
||||
public class GLFW
|
||||
{
|
||||
static FloatBuffer joystickAxisData;
|
||||
static ByteBuffer joystickButtonData;
|
||||
static ByteBuffer empty = (ByteBuffer)ByteBuffer.allocate(0);
|
||||
static FloatBuffer joystickData = (FloatBuffer)FloatBuffer.allocate(8).flip();
|
||||
static ByteBuffer buttonData = (ByteBuffer)ByteBuffer.allocate(8).flip();
|
||||
/** The major version number of the GLFW library. This is incremented when the API is changed in non-compatible ways. */
|
||||
public static final int GLFW_VERSION_MAJOR = 3;
|
||||
|
||||
@@ -517,7 +515,6 @@ public class GLFW
|
||||
private static final String PROP_WINDOW_WIDTH = "glfwstub.windowWidth";
|
||||
private static final String PROP_WINDOW_HEIGHT= "glfwstub.windowHeight";
|
||||
public static long mainContext = 0;
|
||||
private static long gamepadDataPointer;
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -639,8 +636,6 @@ public class GLFW
|
||||
return win;
|
||||
}
|
||||
|
||||
private static native long internalGetGamepadDataPointer();
|
||||
|
||||
// Generated stub callback methods
|
||||
public static GLFWCharCallback glfwSetCharCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWcharfun") GLFWCharCallbackI cbfun) {
|
||||
GLFWCharCallback lastCallback = mGLFWCharCallback;
|
||||
@@ -810,10 +805,6 @@ public class GLFW
|
||||
mGLFWInitialTime = (double) System.nanoTime();
|
||||
long __functionAddress = Functions.Init;
|
||||
isGLFWReady = invokeI(__functionAddress) != 0;
|
||||
gamepadDataPointer = internalGetGamepadDataPointer();
|
||||
// NOTE: hardcoded order (also in android CallbackBridge)
|
||||
joystickAxisData = CallbackBridge.nativeCreateGamepadAxisBuffer().order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
||||
joystickButtonData = CallbackBridge.nativeCreateGamepadButtonBuffer();
|
||||
}
|
||||
return isGLFWReady;
|
||||
}
|
||||
@@ -1216,60 +1207,50 @@ public class GLFW
|
||||
}
|
||||
|
||||
public static boolean glfwJoystickPresent(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) {
|
||||
CallbackBridge.enableGamepadDirectInput();
|
||||
if(jid == 0) {
|
||||
return true;
|
||||
}else return false;
|
||||
}
|
||||
public static String glfwGetJoystickName(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) {
|
||||
return "Pojav XBOX 360 compatible gamepad";
|
||||
if(jid == 0) {
|
||||
return "AIC event bus controller";
|
||||
}else return null;
|
||||
}
|
||||
public static FloatBuffer glfwGetJoystickAxes(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) {
|
||||
return joystickAxisData;
|
||||
if(jid == 0) {
|
||||
return joystickData;
|
||||
}else return null;
|
||||
}
|
||||
public static ByteBuffer glfwGetJoystickButtons(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) {
|
||||
return joystickButtonData;
|
||||
if(jid == 0) {
|
||||
return buttonData;
|
||||
}else return null;
|
||||
}
|
||||
public static ByteBuffer glfwGetJoystickHats(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) {
|
||||
return empty; // Maybe implement this later?
|
||||
}else return null;
|
||||
public static ByteBuffer glfwGetjoystickHats(int jid) {
|
||||
return null;
|
||||
}
|
||||
public static boolean glfwJoystickIsGamepad(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) return true;
|
||||
if(jid == 0) return true;
|
||||
else return false;
|
||||
}
|
||||
public static String glfwGetJoystickGUID(int jid) {
|
||||
// Return Xbox 360 controller GUID
|
||||
if(jid == GLFW_JOYSTICK_1) return "030000005e0400008e02000056210000";
|
||||
if(jid == 0) return "aio0";
|
||||
else return null;
|
||||
}
|
||||
|
||||
private static long mUserPointer;
|
||||
|
||||
public static long glfwGetJoystickUserPointer(int jid) {
|
||||
return mUserPointer;
|
||||
return 0;
|
||||
}
|
||||
public static void glfwSetJoystickUserPointer(int jid, long pointer) {
|
||||
mUserPointer = pointer;
|
||||
|
||||
}
|
||||
public static boolean glfwUpdateGamepadMappings(ByteBuffer string) {
|
||||
return false;
|
||||
}
|
||||
public static String glfwGetGamepadName(int jid) {
|
||||
if(jid == GLFW_JOYSTICK_1) return "Pojav XBOX 360 compatible gamepad";
|
||||
else return null;
|
||||
return null;
|
||||
}
|
||||
public static boolean glfwGetGamepadState(int jid, GLFWGamepadState state) {
|
||||
if(jid != 0) return false;
|
||||
MemoryUtil.memCopy(gamepadDataPointer, state.address(), state.sizeof());
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Array version of: {@link #glfwGetVersion GetVersion} */
|
||||
@@ -1325,26 +1306,17 @@ public class GLFW
|
||||
*/
|
||||
|
||||
/** Array version of: {@link #glfwGetMonitorContentScale GetMonitorContentScale} */
|
||||
|
||||
/*
|
||||
public static void glfwGetMonitorContentScale(@NativeType("GLFWmonitor *") long monitor, @Nullable @NativeType("float *") float[] xscale, @Nullable @NativeType("float *") float[] yscale) {
|
||||
long __functionAddress = Functions.GetMonitorContentScale;
|
||||
if (CHECKS) {
|
||||
// check(monitor);
|
||||
checkSafe(xscale, 1);
|
||||
checkSafe(yscale, 1);
|
||||
}
|
||||
xscale[0] = 1;
|
||||
yscale[0] = 1;
|
||||
}
|
||||
|
||||
public static void glfwGetMonitorContentScale(@NativeType("GLFWmonitor *") long monitor, @NativeType("float *") @Nullable FloatBuffer xscale, @NativeType("float *") @Nullable FloatBuffer yscale) {
|
||||
if (CHECKS) {
|
||||
// check(monitor);
|
||||
checkSafe(xscale, 1);
|
||||
checkSafe(yscale, 1);
|
||||
}
|
||||
xscale.put(0, 1);
|
||||
yscale.put(0, 1);
|
||||
invokePPPV(monitor, xscale, yscale, __functionAddress);
|
||||
}
|
||||
*/
|
||||
|
||||
/** Array version of: {@link #glfwGetWindowPos GetWindowPos} */
|
||||
public static void glfwGetWindowPos(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("int *") int[] xpos, @Nullable @NativeType("int *") int[] ypos) {
|
||||
@@ -1404,7 +1376,7 @@ public class GLFW
|
||||
}
|
||||
invokePPPV(window, xscale, yscale, __functionAddress);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/** Array version of: {@link #glfwGetCursorPos GetCursorPos} */
|
||||
public static void glfwGetCursorPos(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("double *") double[] xpos, @Nullable @NativeType("double *") double[] ypos) {
|
||||
|
||||
Reference in new issue
Block a user