mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
Android: Toast when ROM fails to load
This commit is contained in:
parent
b256c89e23
commit
a797297105
4 changed files with 42 additions and 13 deletions
|
@ -81,10 +81,12 @@ AlberFunction(void, Finalize)(JNIEnv* env, jobject obj) {
|
||||||
|
|
||||||
AlberFunction(jboolean, HasRomLoaded)(JNIEnv* env, jobject obj) { return romLoaded; }
|
AlberFunction(jboolean, HasRomLoaded)(JNIEnv* env, jobject obj) { return romLoaded; }
|
||||||
|
|
||||||
AlberFunction(void, LoadRom)(JNIEnv* env, jobject obj, jstring path) {
|
AlberFunction(jboolean, LoadRom)(JNIEnv* env, jobject obj, jstring path) {
|
||||||
const char* pathStr = env->GetStringUTFChars(path, nullptr);
|
const char* pathStr = env->GetStringUTFChars(path, nullptr);
|
||||||
romLoaded = emulator->loadROM(pathStr);
|
romLoaded = emulator->loadROM(pathStr);
|
||||||
env->ReleaseStringUTFChars(path, pathStr);
|
env->ReleaseStringUTFChars(path, pathStr);
|
||||||
|
|
||||||
|
return romLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
AlberFunction(void, LoadLuaScript)(JNIEnv* env, jobject obj, jstring script) {
|
AlberFunction(void, LoadLuaScript)(JNIEnv* env, jobject obj, jstring script) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class AlberDriver {
|
||||||
public static native void Initialize();
|
public static native void Initialize();
|
||||||
public static native void RunFrame(int fbo);
|
public static native void RunFrame(int fbo);
|
||||||
public static native boolean HasRomLoaded();
|
public static native boolean HasRomLoaded();
|
||||||
public static native void LoadRom(String path);
|
public static native boolean LoadRom(String path);
|
||||||
public static native void Finalize();
|
public static native void Finalize();
|
||||||
|
|
||||||
public static native void KeyDown(int code);
|
public static native void KeyDown(int code);
|
||||||
|
|
|
@ -2,20 +2,23 @@ package com.panda3ds.pandroid.view;
|
||||||
|
|
||||||
import static android.opengl.GLES32.*;
|
import static android.opengl.GLES32.*;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
import com.panda3ds.pandroid.AlberDriver;
|
import com.panda3ds.pandroid.AlberDriver;
|
||||||
|
import com.panda3ds.pandroid.data.SMDH;
|
||||||
import com.panda3ds.pandroid.data.config.GlobalConfig;
|
import com.panda3ds.pandroid.data.config.GlobalConfig;
|
||||||
|
import com.panda3ds.pandroid.data.game.GameMetadata;
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
import com.panda3ds.pandroid.utils.GameUtils;
|
import com.panda3ds.pandroid.utils.GameUtils;
|
||||||
import com.panda3ds.pandroid.utils.PerformanceMonitor;
|
import com.panda3ds.pandroid.utils.PerformanceMonitor;
|
||||||
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
||||||
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
|
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
|
||||||
import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout;
|
import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout;
|
||||||
import com.panda3ds.pandroid.data.SMDH;
|
|
||||||
import com.panda3ds.pandroid.data.game.GameMetadata;
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
|
@ -25,9 +28,11 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
|
||||||
private int screenWidth, screenHeight;
|
private int screenWidth, screenHeight;
|
||||||
private int screenTexture;
|
private int screenTexture;
|
||||||
public int screenFbo;
|
public int screenFbo;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
PandaGlRenderer(String romPath) {
|
PandaGlRenderer(Context context, String romPath) {
|
||||||
super();
|
super();
|
||||||
|
this.context = context;
|
||||||
this.romPath = romPath;
|
this.romPath = romPath;
|
||||||
|
|
||||||
screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
|
screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
|
||||||
|
@ -84,7 +89,29 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
|
||||||
|
|
||||||
AlberDriver.Initialize();
|
AlberDriver.Initialize();
|
||||||
AlberDriver.setShaderJitEnabled(GlobalConfig.get(GlobalConfig.KEY_SHADER_JIT));
|
AlberDriver.setShaderJitEnabled(GlobalConfig.get(GlobalConfig.KEY_SHADER_JIT));
|
||||||
AlberDriver.LoadRom(romPath);
|
|
||||||
|
// If loading the ROM failed, display an error message and early exit
|
||||||
|
if (!AlberDriver.LoadRom(romPath)) {
|
||||||
|
// Get a handler that can be used to post to the main thread
|
||||||
|
Handler mainHandler = new Handler(context.getMainLooper());
|
||||||
|
|
||||||
|
Runnable runnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context, "Failed to load ROM! Make sure it's a valid 3DS ROM and that storage permissions are configured properly.",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mainHandler.post(runnable);
|
||||||
|
|
||||||
|
GameMetadata game = GameUtils.getCurrentGame();
|
||||||
|
GameUtils.removeGame(game);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Load the SMDH
|
// Load the SMDH
|
||||||
byte[] smdhData = AlberDriver.GetSmdh();
|
byte[] smdhData = AlberDriver.GetSmdh();
|
||||||
|
@ -93,7 +120,7 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
|
||||||
} else {
|
} else {
|
||||||
SMDH smdh = new SMDH(smdhData);
|
SMDH smdh = new SMDH(smdhData);
|
||||||
Log.i(Constants.LOG_TAG, "Loaded rom SDMH");
|
Log.i(Constants.LOG_TAG, "Loaded rom SDMH");
|
||||||
Log.i(Constants.LOG_TAG, String.format("Are you playing '%s' published by '%s'", smdh.getTitle(), smdh.getPublisher()));
|
Log.i(Constants.LOG_TAG, String.format("You are playing '%s' published by '%s'", smdh.getTitle(), smdh.getPublisher()));
|
||||||
GameMetadata game = GameUtils.getCurrentGame();
|
GameMetadata game = GameUtils.getCurrentGame();
|
||||||
GameUtils.removeGame(game);
|
GameUtils.removeGame(game);
|
||||||
GameUtils.addGame(GameMetadata.applySMDH(game, smdh));
|
GameUtils.addGame(GameMetadata.applySMDH(game, smdh));
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class PandaGlSurfaceView extends GLSurfaceView implements TouchScreenNode
|
||||||
if (Debug.isDebuggerConnected()) {
|
if (Debug.isDebuggerConnected()) {
|
||||||
setDebugFlags(DEBUG_LOG_GL_CALLS);
|
setDebugFlags(DEBUG_LOG_GL_CALLS);
|
||||||
}
|
}
|
||||||
renderer = new PandaGlRenderer(romPath);
|
renderer = new PandaGlRenderer(getContext(), romPath);
|
||||||
setRenderer(renderer);
|
setRenderer(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue