Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/languages/en/Options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@

<str id="songOffsetAffectEditors-name">Offset in Charter</str>
<str id="songOffsetAffectEditors-desc">If checked, this will enable the Song Offset option in the Chart Editor too.</str>

<str id="legacyMemoryCounter-name">Legacy Memory Counter</str>
<str id="legacyMemoryCounter-desc">If checked, the memory counter will show the Haxe GC memory usage and its peak (the original behavior) instead of the working set memory seen in Task Manager.</str>
</group>

</language>
5 changes: 4 additions & 1 deletion assets/languages/es/Options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
<str id="charterAutoSaveWarningTime-desc">Esto controla por cuánto tiempo te advertirá el editor antes de autoguardar (en segundos..., 0 para desactivar)</str>

<str id="charterAutoSavesSeparateFolder-name">Carpeta de Autoguardados</str>
<str id="charterAutoSavesSeparateFolder-desc">Si está activado, el autoguardado se guardará en otra carpeta con su fecha en vez de sobreescribir el archivo actual. (song/autosaves/)</str> </group>
<str id="charterAutoSavesSeparateFolder-desc">Si está activado, el autoguardado se guardará en otra carpeta con su fecha en vez de sobreescribir el archivo actual. (song/autosaves/)</str>

<str id="legacyMemoryCounter-name">Contador de Memoria Clásico</str>
<str id="legacyMemoryCounter-desc">Si está activado, el contador de memoria mostrará el uso de memoria del GC de Haxe y su máximo (el comportamiento original) en vez de la memoria de trabajo vista en el Administrador de Tareas.</str> </group>

</language>
3 changes: 3 additions & 0 deletions assets/languages/it/Options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@

<str id="songOffsetAffectEditors-name">Offset Editor Chart</str>
<str id="songOffsetAffectEditors-desc">Se abilitato, questo attiverà l'opzione Offset Canzone anche nel Editor Chart.</str>

<str id="legacyMemoryCounter-name">Contatore Memoria Classico</str>
<str id="legacyMemoryCounter-desc">Se attivato, il contatore di memoria mostrerà l'uso di memoria del GC di Haxe e il suo picco (il comportamento originale) invece della memoria di lavoro vista nel Task Manager.</str>
</group>
</language>
3 changes: 3 additions & 0 deletions assets/languages/pl/Options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@

<str id="charterAutoSavesSeparateFolder-name">Folder Autozapisów</str>
<str id="charterAutoSavesSeparateFolder-desc">Jeśli włączone, Edytor będzie zapisywać pliki w osobnym folderze, zamiast nadpisywania aktualnego pliku. (song/autosaves/)</str>

<str id="legacyMemoryCounter-name">Klasyczny Licznik Pamięci</str>
<str id="legacyMemoryCounter-desc">Jeśli włączone, licznik pamięci pokaże użycie pamięci GC Haxe i jego szczyt (oryginalne zachowanie) zamiast pamięci roboczej widocznej w Menedżerze Zadań.</str>
</group>

</language>
3 changes: 3 additions & 0 deletions assets/languages/pt/Options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@

<str id="songOffsetAffectEditors-name">Atraso no Mapeador</str>
<str id="songOffsetAffectEditors-desc">Se marcado, irá ativar o Atraso da Música no Editor de Mapas, também.</str>

<str id="legacyMemoryCounter-name">Contador de Memória Clássico</str>
<str id="legacyMemoryCounter-desc">Se marcado, o contador de memória mostrará o uso de memória do GC de Haxe e o seu máximo (o comportamento original) em vez da memória de trabalho vista no Gerenciador de Tarefas.</str>
</group>

</language>
48 changes: 45 additions & 3 deletions source/funkin/backend/system/framerate/MemoryCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,57 @@ class MemoryCounter extends Sprite {
addChild(label);
}
memoryPeakText.alpha = 0.5;
#if !(cpp && (windows || mac || linux))
memoryPeakText.visible = false;
#end
}

public function reload() {}

private var usingLegacy:Bool = false;

public override function __enterFrame(t:Int) {
if (alpha <= 0.05) return;
super.__enterFrame(t);

#if (cpp && (windows || mac || linux))
var legacy = funkin.options.Options.legacyMemoryCounter;

if (legacy) {
if (legacy != usingLegacy) {
usingLegacy = legacy;
memoryPeak = 0;
}

final mem = MemoryUtil.currentMemUsage();
if (memoryPeak < mem) memoryPeak = mem;
if (mem == memory) {
updateLabelPosition();
return;
}

memory = mem;
memoryPeakText.visible = true;
memoryText.text = CoolUtil.getSizeString(memory);
memoryPeakText.text = ' / ${CoolUtil.getSizeString(memoryPeak)}';
} else {
if (legacy != usingLegacy) usingLegacy = legacy;

final gcMem = MemoryUtil.currentMemUsage();
final osMem = MemoryUtil.currentProcessMemUsage();

if (gcMem == memory && osMem == memoryPeak) {
updateLabelPosition();
return;
}

memory = gcMem;
memoryPeak = osMem;
memoryPeakText.visible = true;
memoryText.text = CoolUtil.getSizeString(gcMem);
memoryPeakText.text = ' / ${CoolUtil.getSizeString(osMem)}';
}
#else
final mem = MemoryUtil.currentMemUsage();

if (mem == memory) {
Expand All @@ -44,9 +87,8 @@ class MemoryCounter extends Sprite {
}

memory = mem;
if (memoryPeak < memory) memoryPeak = memory;
memoryText.text = CoolUtil.getSizeString(memory);
memoryPeakText.text = ' / ${CoolUtil.getSizeString(memoryPeak)}';
memoryText.text = CoolUtil.getSizeString(mem);
#end

updateLabelPosition();
}
Expand Down
17 changes: 17 additions & 0 deletions source/funkin/backend/utils/MemoryUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ final class MemoryUtil {
#end
}

/**
* Gets the current process memory usage (Working Set / RSS) from the OS.
* This is much more granular than Haxe GC memory and updates more frequently.
* Returns the value in bytes, matching what you see in Task Manager / Activity Monitor.
*/
public static inline function currentProcessMemUsage():Float {
#if (cpp && windows)
return funkin.backend.utils.native.Windows.getCurrentProcessMemory();
#elseif (cpp && mac)
return funkin.backend.utils.native.Mac.getCurrentProcessMemory();
#elseif (cpp && linux)
return funkin.backend.utils.native.Linux.getCurrentProcessMemory();
#else
return currentMemUsage();
#end
}


/**
* Gets the memory type of the system.
Expand Down
20 changes: 20 additions & 0 deletions source/funkin/backend/utils/native/Linux.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,25 @@ final class Linux {
{
return 0;
}

@:functionCode('
FILE *status = fopen("/proc/self/status", "r");
if (status == NULL) return 0.0;

char line[256];
while (fgets(line, sizeof(line), status)) {
long rss;
if (sscanf(line, "VmRSS: %ld kB", &rss) == 1) {
fclose(status);
return (double)(rss * 1024); // kB -> bytes
}
}
fclose(status);
return 0.0;
')
public static function getCurrentProcessMemory():Float
{
return 0;
}
}
#end
14 changes: 14 additions & 0 deletions source/funkin/backend/utils/native/Mac.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import funkin.backend.utils.NativeAPI.CodeCursor;
import openfl.ui.Mouse;

@:headerInclude('sys/sysctl.h')
@:headerInclude('mach/mach.h')
@:dox(hide)
final class Mac
{
Expand All @@ -23,6 +24,19 @@ final class Mac
return 0;
}

@:functionCode('
task_basic_info_data_t info;
mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &count) == KERN_SUCCESS) {
return (double)info.resident_size;
}
return 0.0;
')
public static function getCurrentProcessMemory():Float
{
return 0;
}

public static function setMouseCursorIcon(icon:CodeCursor):Void
{
final valid:Bool = external.ExternalMac.setCursorIcon(icon.toInt(), null, 0, 0);
Expand Down
13 changes: 13 additions & 0 deletions source/funkin/backend/utils/native/Windows.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import funkin.backend.utils.NativeAPI.MessageBoxIcon;
#include <wingdi.h>
#include <shellapi.h>
#include <uxtheme.h>
#include <psapi.h>

#define SAFE_RELEASE(punk) \\
if ((punk) != NULL) \\
Expand Down Expand Up @@ -267,5 +268,17 @@ final class Windows {
{
return 0;
}

@:functionCode("
PROCESS_MEMORY_COUNTERS_EX pmc;
if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc))) {
return (double)pmc.WorkingSetSize;
}
return 0.0;
")
public static function getCurrentProcessMemory():Float
{
return 0;
}
}
#end
1 change: 1 addition & 0 deletions source/funkin/options/Options.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Options
public static var devMode:Bool = false;
public static var betaUpdates:Bool = false;
public static var splashesEnabled:Bool = true;
public static var legacyMemoryCounter:Bool = false;
@:dox(hide) @:doNotSave public static var hitWindow:Float = 250; // DEPRECATED
public static var songOffset:Float = 0;
public static var framerate:Int = 120;
Expand Down
3 changes: 3 additions & 0 deletions source/funkin/options/categories/DebugOptions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ class DebugOptions extends TreeMenuScreen {
add(new NumOption(getNameID("charterAutoSaveWarningTime"), getDescID("charterAutoSaveWarningTime"), 0, 15, 1, "charterAutoSaveWarningTime"));
add(new Checkbox(getNameID("charterAutoSavesSeparateFolder"), getDescID("charterAutoSavesSeparateFolder"), "charterAutoSavesSeparateFolder"));
add(new Checkbox(getNameID("songOffsetAffectEditors"), getDescID("songOffsetAffectEditors"), "songOffsetAffectEditors"));
#if (cpp && (windows || mac || linux))
add(new Checkbox(getNameID("legacyMemoryCounter"), getDescID("legacyMemoryCounter"), "legacyMemoryCounter"));
#end
}
}