From 715d2ba65fce941a1631266d57d349cdaae6f772 Mon Sep 17 00:00:00 2001 From: MoonDroid <81515012+moondroidcoder@users.noreply.github.com> Date: Fri, 27 Jun 2025 06:44:35 +0700 Subject: [PATCH 1/3] feat: Add DeviceUtil class --- source/funkin/util/DeviceUtil.hx | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 source/funkin/util/DeviceUtil.hx diff --git a/source/funkin/util/DeviceUtil.hx b/source/funkin/util/DeviceUtil.hx new file mode 100644 index 000000000..d628ffb84 --- /dev/null +++ b/source/funkin/util/DeviceUtil.hx @@ -0,0 +1,90 @@ +package funkin.util; + +import lime.system.System; + +class DeviceUtil +{ + // --- iPhone Number Detection --- + #if ios + public static var iPhoneNumber(get, never):Int; + + private static function get_iPhoneNumber():Int + { + // TODO: Add ipad detection gah + if (!model.startsWith("iPhone")) return 0; // Not an iPhone, must be an ipad!! + + return switch (model) + { + // iPhone 12 Series + case "iPhone13,1": 12; + case "iPhone13,2": 12; + case "iPhone13,3": 12; + case "iPhone13,4": 12; + + // iPhone 13 Series + case "iPhone14,4": 13; + case "iPhone14,5": 13; + case "iPhone14,2": 13; + case "iPhone14,3": 13; + + // iPhone 14 Series + case "iPhone14,7": 14; + case "iPhone14,8": 14; + case "iPhone15,2": 14; + case "iPhone15,3": 14; + + // iPhone 15 Series + case "iPhone15,4": 15; + case "iPhone15,5": 15; + case "iPhone16,1": 15; + case "iPhone16,2": 15; + + // iPhone 16 Series + case "iPhone17,1": 16; + case "iPhone17,5": 16; + case "iPhone17,4": 16; + case "iPhone17,3": 16; + case "iPhone17,2": 16; + + // Unknown or newer model fallback + default: + final parts = model.substr(6).split(","); + if (parts.length == 2) + { + final major = Std.parseInt(parts[0]); + final minor = Std.parseInt(parts[1]); + if (major != null && minor != null) + { + if (major > 17 || (major == 17 && minor > 5)) + { + return 100; // future device + } + } + } + return 0; // obsolete or unknown + } + } + #end + + // --- General Device Info --- + public static var osVersion(get, null):String; + + private static function get_osVersion():String + { + return System.platformVersion; + } + + public static var vendor(get, null):String; + + private static function get_vendor():String + { + return System.deviceVendor; + } + + public static var model(get, null):String; + + private static function get_model():String + { + return System.deviceModel; + } +} From bc4c944d4d3cfa45a93c02ab127ddfbd14fd3db2 Mon Sep 17 00:00:00 2001 From: MoonDroid <81515012+moondroidcoder@users.noreply.github.com> Date: Fri, 27 Jun 2025 07:28:53 +0700 Subject: [PATCH 2/3] Call GC after results if there is no stickers. --- source/funkin/play/ResultState.hx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/source/funkin/play/ResultState.hx b/source/funkin/play/ResultState.hx index f2f5bbb9f..314c2a3ed 100644 --- a/source/funkin/play/ResultState.hx +++ b/source/funkin/play/ResultState.hx @@ -48,6 +48,7 @@ import funkin.mobile.util.AdMobUtil; import funkin.mobile.util.InAppReviewUtil; #end #end +import funkin.util.DeviceUtil; /** * The state for the results screen after a song or week is finished. @@ -594,11 +595,12 @@ class ResultState extends MusicBeatSubState // ratingsPopin.animation.play("idle"); // ratingsPopin.visible = true; - ratingsPopin.animation.onFinish.add(anim -> { - // scorePopin.animation.play("score"); + ratingsPopin.animation.onFinish.add(anim -> + { + // scorePopin.animation.play("score"); - // scorePopin.visible = true; - }); + // scorePopin.visible = true; + }); } refresh(); @@ -1049,6 +1051,16 @@ class ResultState extends MusicBeatSubState } else { + FlxG.signals.preStateSwitch.addOnce(function() { + #if ios + trace(DeviceUtil.iPhoneNumber); + if (DeviceUtil.iPhoneNumber > 12) funkin.FunkinMemory.purgeCache(true); + else + funkin.FunkinMemory.purgeCache(); + #else + funkin.FunkinMemory.purgeCache(true); + #end + }); FlxG.switchState(() -> targetState); } } @@ -1069,6 +1081,16 @@ class ResultState extends MusicBeatSubState } else { + FlxG.signals.preStateSwitch.addOnce(function() { + #if ios + trace(DeviceUtil.iPhoneNumber); + if (DeviceUtil.iPhoneNumber > 12) funkin.FunkinMemory.purgeCache(true); + else + funkin.FunkinMemory.purgeCache(); + #else + funkin.FunkinMemory.purgeCache(true); + #end + }); FlxG.switchState(() -> targetState); } } From 42ec7f7796af9aae877b16141948dad463911062 Mon Sep 17 00:00:00 2001 From: MoonDroid <81515012+moondroidcoder@users.noreply.github.com> Date: Fri, 27 Jun 2025 07:31:32 +0700 Subject: [PATCH 3/3] Call GC only for IPhones above 12 --- source/funkin/ui/charSelect/CharacterUnlockState.hx | 8 ++++++++ source/funkin/ui/transition/stickers/StickerSubState.hx | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/source/funkin/ui/charSelect/CharacterUnlockState.hx b/source/funkin/ui/charSelect/CharacterUnlockState.hx index 4ea032f4a..5ae3a8c62 100644 --- a/source/funkin/ui/charSelect/CharacterUnlockState.hx +++ b/source/funkin/ui/charSelect/CharacterUnlockState.hx @@ -15,6 +15,7 @@ import funkin.data.freeplay.player.PlayerRegistry; import funkin.ui.mainmenu.MainMenuState; #if mobile import funkin.util.TouchUtil; +import funkin.util.DeviceUtil; #end using flixel.util.FlxSpriteUtil; @@ -125,7 +126,14 @@ class CharacterUnlockState extends MusicBeatState // Fade to black, then switch state. FlxG.camera.fade(FlxColor.BLACK, 0.75, false, () -> { funkin.FunkinMemory.clearFreeplay(); + #if ios + trace(DeviceUtil.iPhoneNumber); + if (DeviceUtil.iPhoneNumber > 12) funkin.FunkinMemory.purgeCache(true); + else + funkin.FunkinMemory.purgeCache(); + #else funkin.FunkinMemory.purgeCache(true); + #end FlxG.switchState(() -> nextState); }); } diff --git a/source/funkin/ui/transition/stickers/StickerSubState.hx b/source/funkin/ui/transition/stickers/StickerSubState.hx index 7dbd0f2b1..bf7e8db45 100644 --- a/source/funkin/ui/transition/stickers/StickerSubState.hx +++ b/source/funkin/ui/transition/stickers/StickerSubState.hx @@ -15,6 +15,7 @@ import funkin.ui.freeplay.FreeplayState; import funkin.ui.MusicBeatSubState; import funkin.ui.transition.stickers.StickerPack; import funkin.FunkinMemory; +import funkin.util.DeviceUtil; using Lambda; using StringTools; @@ -257,7 +258,14 @@ class StickerSubState extends MusicBeatSubState // FlxG.addChildBelowMouse(dipshit); */ FlxG.signals.preStateSwitch.addOnce(function() { + #if ios + trace(DeviceUtil.iPhoneNumber); + if (DeviceUtil.iPhoneNumber > 12) funkin.FunkinMemory.purgeCache(true); + else + funkin.FunkinMemory.purgeCache(); + #else funkin.FunkinMemory.purgeCache(true); + #end }); FlxG.switchState(() -> { // TODO: Rework this asset caching stuff