Skip to content

Commit

Permalink
More peach fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Dec 8, 2023
1 parent 00bf1bc commit a78a1a0
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = getIntent();
if (!intent.hasExtra(Constants.EXTRA_PATH)) {
if (!intent.hasExtra(Constants.ACTIVITY_PARAMETER_PATH)) {
setContentView(new FrameLayout(this));
Toast.makeText(this, "Invalid rom path!", Toast.LENGTH_LONG).show();
finish();
return;
}

PandaGlSurfaceView pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));
PandaGlSurfaceView pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.ACTIVITY_PARAMETER_PATH));

setContentView(R.layout.game_activity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import com.panda3ds.pandroid.utils.PathUtils;

public class MainActivity extends BaseActivity {
private static final int PICK_3DS_ROM = 2;
private static final int PICK_ROM = 2;
private static final int PERMISSION_REQUEST_CODE = 3;

private void openFile() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, PICK_3DS_ROM);
startActivityForResult(intent, PICK_ROM);
}

@Override
Expand All @@ -46,11 +46,11 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_3DS_ROM) {
if (requestCode == PICK_ROM) {
if (resultCode == RESULT_OK) {
String path = PathUtils.getPath(getApplicationContext(), data.getData());
Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show();
startActivity(new Intent(this, GameActivity.class).putExtra(Constants.EXTRA_PATH, path));
startActivity(new Intent(this, GameActivity.class).putExtra(Constants.ACTIVITY_PARAMETER_PATH, path));
}
super.onActivityResult(requestCode, resultCode, data);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package com.panda3ds.pandroid.utils;

public class Constants {
public static final int INPUT_KEY_A = 1 << 0;
public static final int INPUT_KEY_B = 1 << 1;
public static final int INPUT_KEY_SELECT = 1 << 2;
public static final int INPUT_KEY_START = 1 << 3;
public static final int INPUT_KEY_RIGHT = 1 << 4;
public static final int INPUT_KEY_LEFT = 1 << 5;
public static final int INPUT_KEY_UP = 1 << 6;
public static final int INPUT_KEY_DOWN = 1 << 7;
public static final int INPUT_KEY_LEFT = 1 << 5;
public static final int INPUT_KEY_RIGHT = 1 << 4;

public static final int INPUT_KEY_A = 1;
public static final int INPUT_KEY_B = 1 << 1;
public static final int INPUT_KEY_X = 1 << 10;
public static final int INPUT_KEY_Y = 1 << 11;

public static final int INPUT_KEY_R = 1 << 8;
public static final int INPUT_KEY_L = 1 << 9;

public static final int INPUT_KEY_START = 1 << 3;
public static final int INPUT_KEY_SELECT = 1 << 2;
public static final int INPUT_KEY_X = 1 << 10;
public static final int INPUT_KEY_Y = 1 << 11;

public static final int N3DS_WIDTH = 400;
public static final int N3DS_HALF_HEIGHT = 240;
public static final int N3DS_FULL_HEIGHT = 480;
public static final int N3DS_FULL_HEIGHT = N3DS_HALF_HEIGHT * 2;

public static final String EXTRA_PATH = "path";
public static final String ACTIVITY_PARAMETER_PATH = "path";
public static final String LOG_TAG = "pandroid";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

public class PathUtils {
public static String getPath(final Context context, final Uri uri) {
// DocumentProvider
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) {
if (isExternalStorageDocument(uri)) { // ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Expand All @@ -33,14 +32,12 @@ public static String getPath(final Context context, final Uri uri) {
return System.getenv(storageDefinition) + "/" + split[1];
}

} else if (isDownloadsDocument(uri)) { // DownloadsProvider

} else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

return getDataColumn(context, contentUri, null, null);

} else if (isMediaDocument(uri)) { // MediaProvider
} else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Expand All @@ -56,18 +53,13 @@ public static String getPath(final Context context, final Uri uri) {

final String selection = "_id=?";
final String[] selectionArgs = new String[] {split[1]};

return getDataColumn(context, contentUri, selection, selectionArgs);
}

} else if ("content".equalsIgnoreCase(uri.getScheme())) { // MediaStore (and general)

// Return the remote address
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
if (isGooglePhotosUri(uri)) return uri.getLastPathSegment();

return getDataColumn(context, uri, null, null);

} else if ("file".equalsIgnoreCase(uri.getScheme())) { // File
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}

Expand All @@ -78,7 +70,6 @@ public static String getDataColumn(Context context, Uri uri, String selection, S
Cursor cursor = null;
final String column = "_data";
final String[] projection = {column};

try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public void onSurfaceCreated(GL10 unused, EGLConfig config) {
Log.i(Constants.LOG_TAG, glGetString(GL_EXTENSIONS));
Log.w(Constants.LOG_TAG, glGetString(GL_VERSION));

int[] version = new int[2];
glGetIntegerv(GL_MAJOR_VERSION, version, 0);
glGetIntegerv(GL_MINOR_VERSION, version, 1);

if (version[0] < 3 || (version[0] == 3 && version[1] < 1)) {
Log.e(Constants.LOG_TAG, "OpenGL 3.1 or higher is required");
}

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private void processTouch(boolean up, float x, float y, int index) {
int[] globalPosition = new int[2];
getLocationInWindow(globalPosition);

int action = TouchEvent.ACTION_MOVE;

TouchType action = TouchType.ACTION_MOVE;
if ((!activeTouchEvents.containsKey(index))) {
if (up) return;
ControllerNode node = null;
Expand All @@ -97,13 +96,13 @@ private void processTouch(boolean up, float x, float y, int index) {
}
if (node != null) {
activeTouchEvents.put(index, node);
action = TouchEvent.ACTION_DOWN;
action = TouchType.ACTION_DOWN;
} else {
return;
}
}

if (up) action = TouchEvent.ACTION_UP;
if (up) action = TouchType.ACTION_UP;

ControllerNode node = activeTouchEvents.get(index);
Vector2 pos = node.getPosition();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.panda3ds.pandroid.view.controller;

public class TouchEvent {
public static final int ACTION_DOWN = 0;
public static final int ACTION_MOVE = 1;
public static final int ACTION_UP = 2;

private final int action;
private final TouchType action;
private final float x, y;

public float getX() { return x; }

public float getY() { return y; }

public int getAction() { return action; }
public TouchType getAction() { return action; }

public TouchEvent(float x, float y, int action) {
public TouchEvent(float x, float y, TouchType action) {
this.x = x;
this.y = y;
this.action = action;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.panda3ds.pandroid.view.controller;

public enum TouchType {
ACTION_DOWN,
ACTION_MOVE,
ACTION_UP
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.controller.TouchType;
import com.panda3ds.pandroid.view.controller.listeners.ButtonStateListener;

public class Button extends BasicControllerNode {
Expand Down Expand Up @@ -58,8 +59,8 @@ public Vector2 getSize() {

@Override
public void onTouch(TouchEvent event) {
pressed = event.getAction() != TouchEvent.ACTION_UP;
setAlpha(pressed ? 0.2F : 1.0F);
pressed = event.getAction() != TouchType.ACTION_UP;
setAlpha(pressed ? 0.2f : 1.0f);
if (stateListener != null) {
stateListener.onButtonPressedChange(this, pressed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.controller.TouchType;
import com.panda3ds.pandroid.view.controller.listeners.JoystickListener;

public class Joystick extends BasicControllerNode implements ControllerNode {
Expand Down Expand Up @@ -47,20 +48,20 @@ public void onDrawForeground(Canvas canvas) {

int analogIconSize = width - getPaddingLeft();

float middleIconSize = analogIconSize / 2.0F;
float middle = width / 2.0F;
float middleIconSize = analogIconSize / 2.0f;
float middle = width / 2.0f;

float maxDistance = (middle - middleIconSize) * 0.9F;
float maxDistance = (middle - middleIconSize) * 0.9f;

float tx = maxDistance * axisX;
float ty = maxDistance * axisY;

float radius = Vector2.distance(0.0F, 0.0F, Math.abs(tx), Math.abs(ty));
float radius = Vector2.distance(0.0f, 0.0f, Math.abs(tx), Math.abs(ty));
radius = Math.min(maxDistance, radius);

double deg = Math.atan2(ty, tx) * (180.0 / Math.PI);
float rx = (float) (radius * Math.cos(Math.PI * 2 * deg / 360.0));
float ry = (float) (radius * Math.sin(Math.PI * 2 * deg / 360.0));
float rx = (float) (radius * Math.cos(2 * Math.PI * deg / 360.0));
float ry = (float) (radius * Math.sin(2 * Math.PI * deg / 360.0));

axisX = Math.max(-1.0f, Math.min(1.0f, axisX));
axisY = Math.max(-1.0f, Math.min(1.0f, axisY));
Expand All @@ -77,7 +78,7 @@ public void onDrawForeground(Canvas canvas) {
}
}

public Vector2 getAxis() { return new Vector2(Math.max(-1.0F, Math.min(1.0F, axisX)), Math.max(-1.0F, Math.min(1.0F, axisY))); }
public Vector2 getAxis() { return new Vector2(Math.max(-1.0f, Math.min(1.0f, axisX)), Math.max(-1.0f, Math.min(1.0f, axisY))); }

public void setJoystickListener(JoystickListener joystickListener) { this.joystickListener = joystickListener; }

Expand All @@ -89,7 +90,7 @@ public Vector2 getSize() {

@Override
public void onTouch(TouchEvent event) {
float middle = width / 2.0F;
float middle = width / 2.0f;

float x = event.getX();
float y = event.getY();
Expand All @@ -101,7 +102,7 @@ public void onTouch(TouchEvent event) {

axisY = ((y - middle) / middle);

if (event.getAction() == TouchEvent.ACTION_UP) {
if (event.getAction() == TouchType.ACTION_UP) {
axisX = 0;
axisY = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.controller.TouchType;
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;

public interface TouchScreenNodeImpl extends ControllerNode {
Expand All @@ -28,7 +29,7 @@ default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event) {
view.setTag(R.id.TagEventHasDown, true);
}

if (hasDownEvent && event.getAction() == TouchEvent.ACTION_UP) {
if (hasDownEvent && event.getAction() == TouchType.ACTION_UP) {
AlberDriver.TouchScreenUp();
view.setTag(R.id.TagEventHasDown, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class DefaultScreenLayout implements ConsoleLayout {
private final Rect topDisplay = new Rect();
private final Rect bottomDisplay = new Rect();

private final Vector2 screenSize = new Vector2(1.0F, 1.0F);
private final Vector2 topSourceSize = new Vector2(1.0F, 1.0F);
private final Vector2 bottomSourceSize = new Vector2(1.0F, 1.0F);
private final Vector2 screenSize = new Vector2(1.0f, 1.0f);
private final Vector2 topSourceSize = new Vector2(1.0f, 1.0f);
private final Vector2 bottomSourceSize = new Vector2(1.0f, 1.0f);

@Override
public void update(int screenWidth, int screenHeight) {
Expand Down

0 comments on commit a78a1a0

Please sign in to comment.