Skip to content

Commit

Permalink
fix lod reload on web + some antialiasing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 22, 2024
1 parent 5e740cf commit 8d3783a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
12 changes: 10 additions & 2 deletions source/funkin/Preferences.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package funkin;

typedef ArrayPref = {array:Array<String>, value:String};

class Preferences {
class Preferences
{
public static var prefsArray:Array<String>;
public static var preferences:Map<String, Dynamic>;
public static var prefsLabels:Map<String, String>;
Expand Down Expand Up @@ -106,10 +107,17 @@ class Preferences {
public static inline function updateGpuTextures():Void
#if !(hl || web) AssetManager.gpuTextures = getPref('gpu-textures'); #else {} #end

public static inline function updateAntialiasing():Void {
var anti:Bool = FlxSprite.defaultAntialiasing = getPref('antialiasing');
for (key => data in NoteUtil.skinSpriteMap) {
data.baseSprite.antialiasing = data.skinJson.antialiasing ? anti : false;
}
}

public static function effectPrefs():Void {
updateFramerate();
updateFpsCounter();
FlxSprite.defaultAntialiasing = getPref('antialiasing');
updateAntialiasing();
AssetManager.setLodQuality(getPref('quality'));
updateGpuTextures();
}
Expand Down
32 changes: 20 additions & 12 deletions source/funkin/states/options/items/PrefItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum PrefType {
class PrefItem extends FlxSpriteGroup {
private var usePrefs:Bool = true;
private var settingTxt:Alphabet;
public var type:PrefType = null;
public var type:PrefType;

private var checkboxSpr:FunkinSprite; //Bool
public var numSetSpr:Alphabet; //Number
Expand Down Expand Up @@ -59,19 +59,25 @@ class PrefItem extends FlxSpriteGroup {
}
}

inline public function getArrIndex() {
inline public function getArrIndex():Int {
return array.indexOf(prefValue);
}

function applyAntiGroup(members:Array<Dynamic>, anti:Bool = true) {
for (i in members) {
switch(Type.typeof(i)) {
case TClass(FunkinSprite):
i.antialiasing = anti;
case TClass(FlxTypedGroup) | TClass(PrefItem):
applyAntiGroup(i.members ?? i.group.members, anti);
default:
}
function applyAntiGroup(basic:Dynamic, anti:Bool):Void
{
if (basic.flixelType == GROUP) {
for (member in cast(basic.members, Array<Dynamic>))
applyAntiGroup(member, anti);

return;
}

if (basic is FlxSprite) {
basic.antialiasing = anti;
if (basic.flixelType == SPRITEGROUP) {
for (member in cast(basic.group.members, Array<Dynamic>))
applyAntiGroup(member, anti);
}
}
}

Expand All @@ -95,7 +101,9 @@ class PrefItem extends FlxSpriteGroup {
case "fps-counter": Preferences.updateFpsCounter();
case "resolution": Preferences.updateResolution();
case "gpu-textures": Preferences.updateGpuTextures();
case "antialiasing": applyAntiGroup(FlxG.state.members, cast prefValue);
case "antialiasing":
Preferences.updateAntialiasing();
applyAntiGroup(FlxG.state, cast prefValue);
}
}

Expand Down
3 changes: 1 addition & 2 deletions source/funkin/util/NoteUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ class NoteUtil

final key:String = 'skins/$skin/${skinJson.imagePath}';
final lod:Int = LodLevel.resolve(skinJson.allowLod);
final antialiasing:Bool = skinJson.antialiasing ? Preferences.getPref("antialiasing") : false;

final sprite = new FlxSpriteExt().loadImage(key, false, null, null, lod);
sprite.setScale(skinJson.scale);
sprite.antialiasing = antialiasing;
sprite.antialiasing = skinJson.antialiasing ? Preferences.getPref("antialiasing") : false;

skinJson.anims.fastForEach((anim, i) -> {
sprite.addAnim(anim.animName, anim.animFile, anim.framerate, anim.loop, anim.indices, anim.offsets);
Expand Down
8 changes: 7 additions & 1 deletion source/funkin/util/backend/AssetManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ class AssetManager
public static var staticAssets:Array<String> = [];
public static var tempAssets:Array<String> = [];

public static inline function clearAllCache(?clearGraphics:Bool, ?clearSounds:Bool):Void {
public static inline function clearAllCache(?clearGraphics:Bool, ?clearSounds:Bool):Void
{
#if web
AlphabetFont.cachedAlphabets.clear();
NoteUtil.skinSpriteMap.clear();
#end

clearStaticCache(false, clearGraphics, clearSounds);
clearTempCache(false, clearGraphics, clearSounds);
CoolUtil.gc(true);
Expand Down
1 change: 1 addition & 0 deletions source/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import funkin.objects.Character;
import funkin.objects.HealthIcon;

//Alphabet
import funkin.objects.alphabet.AlphabetFont;
import funkin.objects.alphabet.Alphabet;
import funkin.objects.alphabet.MenuAlphabet;
import funkin.objects.alphabet.TypedAlphabet;
Expand Down

0 comments on commit 8d3783a

Please sign in to comment.