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

@ -15,12 +15,12 @@ namespace Log {
if constexpr (!enabled) return; if constexpr (!enabled) return;
std::va_list args; std::va_list args;
va_start(args, fmt); va_start(args, fmt);
#ifdef __ANDROID__ #ifdef __ANDROID__
__android_log_vprint(ANDROID_LOG_DEFAULT, "Panda3DS", fmt, args); __android_log_vprint(ANDROID_LOG_DEFAULT, "Panda3DS", fmt, args);
#else #else
std::vprintf(fmt, args); std::vprintf(fmt, args);
#endif #endif
va_end(args); va_end(args);
} }
}; };

View file

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

View file

@ -55,15 +55,15 @@ public class LoggerService extends Service {
errorTask.start(); errorTask.start();
outputTask.start(); outputTask.start();
Log.i(Constants.LOG_TAG, "STARTED LOGGER SERVICE"); Log.i(Constants.LOG_TAG, "Started logger service");
printDeviceAbout(); logDeviceInfo();
} catch (Exception e) { } catch (Exception e) {
stopSelf(); 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, "----------------------");
Log.i(Constants.LOG_TAG, "Android SDK: " + Build.VERSION.SDK_INT); Log.i(Constants.LOG_TAG, "Android SDK: " + Build.VERSION.SDK_INT);
Log.i(Constants.LOG_TAG, "Device: " + Build.DEVICE); 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, "Install location: " + info.installLocation);
Log.i(Constants.LOG_TAG, "App version: " + info.versionName + " (" + info.versionCode + ")"); Log.i(Constants.LOG_TAG, "App version: " + info.versionName + " (" + info.versionCode + ")");
} catch (Exception e) { } 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, "----------------------"); Log.i(Constants.LOG_TAG, "----------------------");
} }
@ -93,7 +93,7 @@ public class LoggerService extends Service {
@Override @Override
public void onDestroy() { public void onDestroy() {
Log.i(Constants.LOG_TAG, "FINISHED LOGGER SERVICE"); Log.i(Constants.LOG_TAG, "Logger service terminating");
errorTask.close(); errorTask.close();
outputTask.close(); outputTask.close();
try { try {

View file

@ -74,15 +74,17 @@ public class FileUtils {
parseFile(path).renameTo(newName); parseFile(path).renameTo(newName);
} }
public static void delete(String path){ public static void delete(String path) {
DocumentFile file = parseFile(path); DocumentFile file = parseFile(path);
if (file.exists()){
if (file.isDirectory()){ if (file.exists()) {
if (file.isDirectory()) {
String[] children = listFiles(path); String[] children = listFiles(path);
for (String child: children){ for (String child : children) {
delete(path+"/"+child); delete(path + "/" + child);
} }
} }
file.delete(); file.delete();
} }
} }

View file

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

View file

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

View file

@ -36,18 +36,19 @@ public class PerformanceView extends AppCompatTextView {
public void refresh(){ public void refresh(){
running = isShown(); running = isShown();
if (!running){ if (!running) {
return; return;
} }
String debug = ""; String debug = "";
int memoryTotalMb = (int) Math.round((PerformanceMonitor.getTotalMemory()/1024.0)/1024.0); // Calculate total memory in MB and the current memory usage
int memoryUsageMb = (int) Math.round((PerformanceMonitor.getUsageMemory()/1024.0)/1024.0); 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>FPS: </b>" + PerformanceMonitor.getFps() + "<br>";
debug += "<b>RAM: </b>"+Math.round(((float) memoryUsageMb / memoryTotalMb)*100)+"% ("+memoryUsageMb+"MB/"+memoryTotalMb+"MB)<br>"; debug += "<b>RAM: </b>" + Math.round(((float) memoryUsageMb / memoryTotalMb) * 100) + "% (" + memoryUsageMb + "MB/" + memoryTotalMb + "MB)<br>";
debug += "<b>BACKEND: </b>"+PerformanceMonitor.getBackend()+(GlobalConfig.get(GlobalConfig.KEY_SHADER_JIT) ? " + JIT" : "")+"<br>"; debug += "<b>BACKEND: </b>" + PerformanceMonitor.getBackend() + (GlobalConfig.get(GlobalConfig.KEY_SHADER_JIT) ? " + JIT" : "") + "<br>";
setText(Html.fromHtml(debug, Html.FROM_HTML_MODE_COMPACT)); setText(Html.fromHtml(debug, Html.FROM_HTML_MODE_COMPACT));
postDelayed(this::refresh, 250); postDelayed(this::refresh, 250);
} }
@ -55,7 +56,8 @@ public class PerformanceView extends AppCompatTextView {
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if (!running){
if (!running) {
refresh(); refresh();
} }
} }

View file

@ -52,6 +52,6 @@
<string name="pref_logger_service_title">Depuração</string> <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_logger_service_summary">Grave os registros para um arquivo.</string>
<string name="pref_shader_jit_title">Shader Jit</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> <string name="graphics">Gráficos</string>
</resources> </resources>

View file

@ -53,6 +53,6 @@
<string name="pref_logger_service_title">Logger</string> <string name="pref_logger_service_title">Logger</string>
<string name="pref_logger_service_summary">Store application logs to file.</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_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> <string name="graphics">Graphics</string>
</resources> </resources>