mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-19 20:19:13 +12:00
Cleanup jni_driver
This commit is contained in:
parent
62880f0fd6
commit
c1162678bb
3 changed files with 40 additions and 158 deletions
|
@ -1,74 +1,74 @@
|
|||
#include <jni.h>
|
||||
#include <stdexcept>
|
||||
#include <android/log.h>
|
||||
#include <EGL/egl.h>
|
||||
#include "renderer_gl/renderer_gl.hpp"
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "emulator.hpp"
|
||||
#include "renderer_gl/renderer_gl.hpp"
|
||||
#include "services/hid.hpp"
|
||||
|
||||
std::unique_ptr<Emulator> emulator = nullptr;
|
||||
HIDService* hidService = nullptr;
|
||||
RendererGL* renderer = nullptr;
|
||||
bool romLoaded = false;
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Initialize(JNIEnv* env, jobject obj) {
|
||||
emulator = std::make_unique<Emulator>();
|
||||
if (emulator->getRendererType() != RendererType::OpenGL) {
|
||||
throw std::runtime_error("Renderer is not OpenGL");
|
||||
}
|
||||
renderer = static_cast<RendererGL*>(emulator->getRenderer());
|
||||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES Before %d.%d", GLVersion.major, GLVersion.minor);
|
||||
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(eglGetProcAddress))) {
|
||||
emulator = std::make_unique<Emulator>();
|
||||
|
||||
if (emulator->getRendererType() != RendererType::OpenGL) {
|
||||
throw std::runtime_error("Renderer is not OpenGL");
|
||||
}
|
||||
|
||||
renderer = static_cast<RendererGL*>(emulator->getRenderer());
|
||||
hidService = &emulator->getServiceManager().getHID();
|
||||
|
||||
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(eglGetProcAddress))) {
|
||||
throw std::runtime_error("OpenGL ES init failed");
|
||||
}
|
||||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES %d.%d", GLVersion.major, GLVersion.minor);
|
||||
|
||||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES %d.%d", GLVersion.major, GLVersion.minor);
|
||||
emulator->initGraphicsContext(nullptr);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_RunFrame(JNIEnv* env, jobject obj, jint fbo) {
|
||||
renderer->setFBO(fbo);
|
||||
renderer->resetStateManager();
|
||||
emulator->runFrame();
|
||||
|
||||
emulator->getServiceManager().getHID().updateInputs(emulator->getTicks());
|
||||
renderer->setFBO(fbo);
|
||||
renderer->resetStateManager();
|
||||
emulator->runFrame();
|
||||
|
||||
hidService->updateInputs(emulator->getTicks());
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Finalize(JNIEnv* env, jobject obj) {
|
||||
emulator = nullptr;
|
||||
renderer = nullptr;
|
||||
emulator = nullptr;
|
||||
hidService = nullptr;
|
||||
renderer = nullptr;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL Java_com_panda3ds_pandroid_AlberDriver_HasRomLoaded(JNIEnv* env, jobject obj) {
|
||||
return romLoaded;
|
||||
}
|
||||
extern "C" JNIEXPORT jboolean JNICALL Java_com_panda3ds_pandroid_AlberDriver_HasRomLoaded(JNIEnv* env, jobject obj) { return romLoaded; }
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_LoadRom(JNIEnv* env, jobject obj, jstring path) {
|
||||
const char* pathStr = env->GetStringUTFChars(path, nullptr);
|
||||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "Loading ROM %s", pathStr);
|
||||
romLoaded = emulator->loadROM(pathStr);
|
||||
env->ReleaseStringUTFChars(path, pathStr);
|
||||
const char* pathStr = env->GetStringUTFChars(path, nullptr);
|
||||
__android_log_print(ANDROID_LOG_INFO, "AlberDriver", "Loading ROM %s", pathStr);
|
||||
romLoaded = emulator->loadROM(pathStr);
|
||||
env->ReleaseStringUTFChars(path, pathStr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_TouchScreenDown(JNIEnv* env, jobject obj, jint x, jint y) {
|
||||
emulator->getServiceManager().getHID().setTouchScreenPress((u16)x, (u16)y);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_TouchScreenUp(JNIEnv* env, jobject obj) {
|
||||
emulator->getServiceManager().getHID().releaseTouchScreen();
|
||||
hidService->setTouchScreenPress((u16)x, (u16)y);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_TouchScreenUp(JNIEnv* env, jobject obj) { hidService->releaseTouchScreen(); }
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_KeyUp(JNIEnv* env, jobject obj, jint keyCode) {
|
||||
emulator->getServiceManager().getHID().releaseKey((u32)keyCode);
|
||||
hidService->releaseKey((u32)keyCode);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_KeyDown(JNIEnv* env, jobject obj, jint keyCode) {
|
||||
emulator->getServiceManager().getHID().pressKey((u32)keyCode);
|
||||
hidService->pressKey((u32)keyCode);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_SetCirclepadAxis(JNIEnv* env, jobject obj, jint x, jint y) {
|
||||
emulator->getServiceManager().getHID().setCirclepadX((s16)x);
|
||||
emulator->getServiceManager().getHID().setCirclepadY((s16)y);
|
||||
hidService->setCirclepadX((s16)x);
|
||||
hidService->setCirclepadY((s16)y);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class GameActivity extends BaseActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));;
|
||||
pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));
|
||||
|
||||
setContentView(R.layout.game_activity);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue