This commit is contained in:
wheremyfoodat 2024-02-01 17:12:46 +02:00
parent 130640152c
commit d1fecdd712
9 changed files with 47 additions and 37 deletions

View file

@ -16,9 +16,6 @@ JavaVM* jvm = nullptr;
#define AlberFunction(type, name) JNIEXPORT type JNICALL Java_com_panda3ds_pandroid_AlberDriver_##name
#define MAKE_SETTING(functionName, type, settingName) \
AlberFunction(void, functionName) (JNIEnv* env, jobject obj, type value) { emulator->getConfig().settingName = value; }
void throwException(JNIEnv* env, const char* message) {
jclass exceptionClass = env->FindClass("java/lang/RuntimeException");
env->ThrowNew(exceptionClass, message);
@ -38,8 +35,13 @@ JNIEnv* jniEnv() {
extern "C" {
#define MAKE_SETTING(functionName, type, settingName) \
AlberFunction(void, functionName) (JNIEnv* env, jobject obj, type value) { emulator->getConfig().settingName = value; }
MAKE_SETTING(setShaderJitEnabled, jboolean, shaderJitEnabled)
#undef MAKE_SETTING
AlberFunction(void, Setup)(JNIEnv* env, jobject obj) { env->GetJavaVM(&jvm); }
AlberFunction(void, Pause)(JNIEnv* env, jobject obj) { emulator->pause(); }
AlberFunction(void, Resume)(JNIEnv* env, jobject obj) { emulator->resume(); }

View file

@ -55,15 +55,15 @@ public class LoggerService extends Service {
errorTask.start();
outputTask.start();
Log.i(Constants.LOG_TAG, "STARTED LOGGER SERVICE");
printDeviceAbout();
Log.i(Constants.LOG_TAG, "Started logger service");
logDeviceInfo();
} catch (Exception e) {
stopSelf();
Log.e(Constants.LOG_TAG, "Failed to start LoggerService!");
Log.e(Constants.LOG_TAG, "Failed to start logger service");
}
}
private void printDeviceAbout() {
private void logDeviceInfo() {
Log.i(Constants.LOG_TAG, "----------------------");
Log.i(Constants.LOG_TAG, "Android SDK: " + Build.VERSION.SDK_INT);
Log.i(Constants.LOG_TAG, "Device: " + Build.DEVICE);
@ -76,7 +76,7 @@ public class LoggerService extends Service {
Log.i(Constants.LOG_TAG, "Install location: " + info.installLocation);
Log.i(Constants.LOG_TAG, "App version: " + info.versionName + " (" + info.versionCode + ")");
} catch (Exception e) {
Log.e(Constants.LOG_TAG, "Error on obtain package info: " + e);
Log.e(Constants.LOG_TAG, "Error obtaining package info: " + e);
}
Log.i(Constants.LOG_TAG, "----------------------");
}
@ -93,7 +93,7 @@ public class LoggerService extends Service {
@Override
public void onDestroy() {
Log.i(Constants.LOG_TAG, "FINISHED LOGGER SERVICE");
Log.i(Constants.LOG_TAG, "Logger service terminating");
errorTask.close();
outputTask.close();
try {

View file

@ -76,6 +76,7 @@ public class FileUtils {
public static void delete(String path) {
DocumentFile file = parseFile(path);
if (file.exists()) {
if (file.isDirectory()) {
String[] children = listFiles(path);
@ -83,6 +84,7 @@ public class FileUtils {
delete(path + "/" + child);
}
}
file.delete();
}
}

View file

@ -14,7 +14,7 @@ public class PerformanceMonitor {
private static int frames = 0;
private static long lastUpdate = 0;
private static long totalMemory = 1;
private static long availMemory = 0;
private static long availableMemory = 0;
public static void initialize(String backendName) {
fps = 1;
@ -35,21 +35,21 @@ public class PerformanceMonitor {
manager.getMemoryInfo(info);
totalMemory = info.totalMem;
availMemory = info.availMem;
} catch (Exception e) {/**/}
} catch (Exception e) {}
}
}
}
public static long getUsageMemory() {
return Math.max(1, totalMemory - availMemory);
public static long getUsedMemory() {
return Math.max(1, totalMemory - availableMemory);
}
public static long getTotalMemory() {
return totalMemory;
}
public static long getAvailMemory() {
return availMemory;
public static long getAvailableMemory() {
return availableMemory;
}
public static int getFps() {

View file

@ -40,9 +40,11 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
if (screenTexture != 0) {
glDeleteTextures(1, new int[] {screenTexture}, 0);
}
if (screenFbo != 0) {
glDeleteFramebuffers(1, new int[] {screenFbo}, 0);
}
PerformanceMonitor.destroy();
super.finalize();
}
@ -96,6 +98,7 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
GameUtils.removeGame(game);
GameUtils.addGame(GameMetadata.applySMDH(game, smdh));
}
PerformanceMonitor.initialize(getBackendName());
}
@ -119,6 +122,7 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
screenHeight - bottomScreen.bottom, GL_COLOR_BUFFER_BIT, GL_LINEAR
);
}
PerformanceMonitor.runFrame();
}

View file

@ -42,8 +42,9 @@ public class PerformanceView extends AppCompatTextView {
String debug = "";
int memoryTotalMb = (int) Math.round((PerformanceMonitor.getTotalMemory()/1024.0)/1024.0);
int memoryUsageMb = (int) Math.round((PerformanceMonitor.getUsageMemory()/1024.0)/1024.0);
// Calculate total memory in MB and the current memory usage
int memoryTotalMb = (int) Math.round(PerformanceMonitor.getTotalMemory() / (1024.0 * 1024.0));
int memoryUsageMb = (int) Math.round(PerformanceMonitor.getUsedMemory() / (1024.0 * 1024.0));
debug += "<b>FPS: </b>" + PerformanceMonitor.getFps() + "<br>";
debug += "<b>RAM: </b>" + Math.round(((float) memoryUsageMb / memoryTotalMb) * 100) + "% (" + memoryUsageMb + "MB/" + memoryTotalMb + "MB)<br>";
@ -55,6 +56,7 @@ public class PerformanceView extends AppCompatTextView {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!running) {
refresh();
}

View file

@ -52,6 +52,6 @@
<string name="pref_logger_service_title">Depuração</string>
<string name="pref_logger_service_summary">Grave os registros para um arquivo.</string>
<string name="pref_shader_jit_title">Shader Jit</string>
<string name="pref_shader_jit_summary">Usar recompilador de shaders</string>
<string name="pref_shader_jit_summary">Usar recompilador de shaders.</string>
<string name="graphics">Gráficos</string>
</resources>

View file

@ -53,6 +53,6 @@
<string name="pref_logger_service_title">Logger</string>
<string name="pref_logger_service_summary">Store application logs to file.</string>
<string name="pref_shader_jit_title">Shader JIT</string>
<string name="pref_shader_jit_summary">Use shader re-compiler</string>
<string name="pref_shader_jit_summary">Use shader recompiler.</string>
<string name="graphics">Graphics</string>
</resources>