From 200a884589238d240c63bb3bdea0632a65300cf2 Mon Sep 17 00:00:00 2001 From: offtkp Date: Tue, 28 Nov 2023 14:05:51 +0200 Subject: [PATCH] Various cleanups --- .../panda3ds/pandroid/app/GameActivity.java | 2 +- .../com/panda3ds/pandroid/math/Vector2.java | 3 ++ .../panda3ds/pandroid/utils/Constants.java | 3 ++ .../pandroid/view/PandaGlRenderer.java | 29 +++++++++---------- .../pandroid/view/PandaGlSurfaceView.java | 4 --- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java index 60fe8724..5c234423 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java @@ -33,7 +33,7 @@ public class GameActivity extends BaseActivity { if(!intent.hasExtra(Constants.EXTRA_PATH)){ setContentView(new FrameLayout(this)); - Toast.makeText(this, "INVALID ROM PATH", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "Invalid rom path!", Toast.LENGTH_LONG).show(); finish(); return; } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/math/Vector2.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/math/Vector2.java index 8d413203..9c5b45b7 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/math/Vector2.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/math/Vector2.java @@ -2,9 +2,11 @@ package com.panda3ds.pandroid.math; public class Vector2 { public float x,y; + public Vector2(){ this(0.0f); } + public Vector2(float value){ this(value,value); } @@ -17,6 +19,7 @@ public class Vector2 { public float distanceTo(Vector2 vec){ return distance(x,y,vec.x, vec.y); } + public static float distance(float x, float y, float x2, float y2){ return (float) Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java index c8ba68cd..2e706530 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java @@ -18,6 +18,9 @@ public class Constants { public static final int INPUT_KEY_START = 1 << 3; public static final int INPUT_KEY_SELECT = 1 << 2; + public static final int N3DS_WIDTH = 400; + public static final int N3DS_HEIGHT = 240; + public static final String EXTRA_PATH = "path"; public static final String LOG_TAG = "Alber"; } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java index 4adce575..b6be4df2 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java @@ -10,6 +10,7 @@ import android.opengl.GLSurfaceView; import android.util.Log; import com.panda3ds.pandroid.AlberDriver; +import com.panda3ds.pandroid.utils.Constants; import java.util.ArrayList; @@ -69,43 +70,41 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer { AlberDriver.RunFrame(screenFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo); + if (screenWidth > screenHeight) { - int topDisplayWidth = (int) ((screenHeight / 240.0) * 400); + int topDisplayWidth = (int)((screenHeight / (float)Constants.N3DS_HEIGHT) * Constants.N3DS_WIDTH); int topDisplayHeight = screenHeight; - if (topDisplayWidth > (screenWidth*0.7)){ - topDisplayWidth = (int) (screenWidth * 0.7); - topDisplayHeight = (int) ((topDisplayWidth/400.0)*240); + if (topDisplayWidth > screenWidth * 0.7){ + topDisplayWidth = (int)(screenWidth * 0.7); + topDisplayHeight = (int)((topDisplayWidth / (float)Constants.N3DS_WIDTH) * Constants.N3DS_HEIGHT); } - int bottomDisplayHeight = (int) (((screenWidth-topDisplayWidth)/320)*240); + int bottomDisplayHeight = (int)(((screenWidth - topDisplayWidth) / 320) * Constants.N3DS_HEIGHT); + int topDisplayY = screenHeight - topDisplayHeight; + int bottomDisplayY = screenHeight - bottomDisplayHeight; - int topDisplayY = screenHeight-topDisplayHeight; - int bottomDisplayY = screenHeight-bottomDisplayHeight; - - glBlitFramebuffer(0, 240, - 400, 480, + glBlitFramebuffer(0, Constants.N3DS_HEIGHT, + Constants.N3DS_WIDTH, Constants.N3DS_HEIGHT * 2, 0, topDisplayY, topDisplayWidth,topDisplayY+topDisplayHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBlitFramebuffer( 40, 0, - 360, 240, + 360, Constants.N3DS_HEIGHT, topDisplayWidth, bottomDisplayY, screenWidth,bottomDisplayY+bottomDisplayHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); } else { - int h = (int) ((screenWidth / 400.0) * 480); - glBlitFramebuffer(0, 0, 400, 480, 0, screenHeight - h, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); + int h = (int)((screenWidth / (float)Constants.N3DS_WIDTH) * Constants.N3DS_HEIGHT * 2); + glBlitFramebuffer(0, 0, Constants.N3DS_WIDTH, Constants.N3DS_HEIGHT * 2, 0, screenHeight - h, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); } } } public void onSurfaceChanged(GL10 unused, int width, int height) { - glViewport(0, 0, width, height); screenWidth = width; screenHeight = height; - glDisable(GL_SCISSOR_TEST); } } \ No newline at end of file diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java index 35805657..3b5694ed 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java @@ -13,8 +13,4 @@ public class PandaGlSurfaceView extends GLSurfaceView { renderer = new PandaGlRenderer(romPath); setRenderer(renderer); } - - public PandaGlRenderer getRenderer() { - return renderer; - } } \ No newline at end of file