Cleanup + Optimization
This commit is contained in:
@@ -73,7 +73,7 @@ class Flx3DCamera extends FlxCamera {
|
||||
var context = new AssetLoaderContext();
|
||||
var noExt = Path.withoutExtension(assetPath);
|
||||
trace(noExt);
|
||||
context.mapUrlToData('${Path.withoutDirectory(noExt)}.mtl', '$noExt.mtl');
|
||||
context.mapUrlToData(Path.withoutDirectory(noExt) + '.mtl', noExt + '.mtl');
|
||||
|
||||
var material:TextureMaterial = null;
|
||||
if (texturePath != null)
|
||||
|
||||
@@ -46,7 +46,7 @@ class Flx3DView extends FlxView3D {
|
||||
var context = new AssetLoaderContext();
|
||||
var noExt = Path.withoutExtension(assetPath);
|
||||
trace(noExt);
|
||||
context.mapUrlToData('${Path.withoutDirectory(noExt)}.mtl', '$noExt.mtl');
|
||||
context.mapUrlToData(Path.withoutDirectory(noExt) + '.mtl', noExt + '.mtl');
|
||||
|
||||
var material:TextureMaterial = null;
|
||||
if (texturePath != null)
|
||||
|
||||
@@ -86,7 +86,7 @@ class ModsFolder {
|
||||
var mods:Array<String> = [];
|
||||
#if MOD_SUPPORT
|
||||
for(modFolder in FileSystem.readDirectory(modsPath)) {
|
||||
if (FileSystem.isDirectory('${modsPath}${modFolder}')) {
|
||||
if (FileSystem.isDirectory(modsPath + modFolder)) {
|
||||
mods.push(modFolder);
|
||||
} else {
|
||||
var ext = Path.extension(modFolder).toLowerCase();
|
||||
|
||||
@@ -239,7 +239,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
Logs.traceColored([
|
||||
Logs.logText('${fileName}: ', GREEN),
|
||||
Logs.logText(fileName + ': ', GREEN),
|
||||
Logs.logText(Std.string(v))
|
||||
], TRACE);
|
||||
}
|
||||
|
||||
@@ -36,20 +36,20 @@ class MainState extends FlxState {
|
||||
var _highPriorityAddons:Array<String> = [];
|
||||
var _noPriorityAddons:Array<String> = [];
|
||||
if (FileSystem.exists(ModsFolder.addonsPath) && FileSystem.isDirectory(ModsFolder.addonsPath)) {
|
||||
for(i=>addon in [for(dir in FileSystem.readDirectory(ModsFolder.addonsPath)) if (FileSystem.isDirectory('${ModsFolder.addonsPath}$dir')) dir]) {
|
||||
for(i=>addon in [for(dir in FileSystem.readDirectory(ModsFolder.addonsPath)) if (FileSystem.isDirectory(ModsFolder.addonsPath + dir)) dir]) {
|
||||
if (addon.startsWith("[LOW]")) _lowPriorityAddons.insert(0, addon);
|
||||
else if (addon.startsWith("[HIGH]")) _highPriorityAddons.insert(0, addon);
|
||||
else _noPriorityAddons.insert(0, addon);
|
||||
}
|
||||
for (addon in _lowPriorityAddons)
|
||||
Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.addonsPath}$addon', StringTools.ltrim(addon.substr("[LOW]".length))));
|
||||
Paths.assetsTree.addLibrary(ModsFolder.loadModLib(ModsFolder.addonsPath + addon, StringTools.ltrim(addon.substr("[LOW]".length))));
|
||||
}
|
||||
if (ModsFolder.currentModFolder != null)
|
||||
Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.modsPath}${ModsFolder.currentModFolder}', ModsFolder.currentModFolder));
|
||||
Paths.assetsTree.addLibrary(ModsFolder.loadModLib(ModsFolder.modsPath + ModsFolder.currentModFolder, ModsFolder.currentModFolder));
|
||||
|
||||
if (FileSystem.exists(ModsFolder.addonsPath) && FileSystem.isDirectory(ModsFolder.addonsPath)){
|
||||
for (addon in _noPriorityAddons) Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.addonsPath}$addon', addon));
|
||||
for (addon in _highPriorityAddons) Paths.assetsTree.addLibrary(ModsFolder.loadModLib('${ModsFolder.addonsPath}$addon', StringTools.ltrim(addon.substr("[HIGH]".length))));
|
||||
for (addon in _noPriorityAddons) Paths.assetsTree.addLibrary(ModsFolder.loadModLib(ModsFolder.addonsPath + addon, addon));
|
||||
for (addon in _highPriorityAddons) Paths.assetsTree.addLibrary(ModsFolder.loadModLib(ModsFolder.addonsPath + addon, StringTools.ltrim(addon.substr("[HIGH]".length))));
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class Framerate extends Sprite {
|
||||
x = 10 + offset.x;
|
||||
y = 2 + offset.y;
|
||||
|
||||
var width = Math.max(fpsCounter.width, #if SHOW_BUILD_ON_FPS Math.max(memoryCounter.width, codenameBuildField.width) #else memoryCounter.width #end) + (x*2);
|
||||
var width = MathUtil.maxSmart(fpsCounter.width, memoryCounter.width #if SHOW_BUILD_ON_FPS , codenameBuildField.width #end) + (x*2);
|
||||
var height = #if SHOW_BUILD_ON_FPS codenameBuildField.y + codenameBuildField.height #else memoryCounter.y + memoryCounter.height #end;
|
||||
bgSprite.x = -x;
|
||||
bgSprite.y = offset.x;
|
||||
|
||||
@@ -271,7 +271,8 @@ class CoolUtil
|
||||
public static function getSizeString(size:Float):String {
|
||||
var rSize:Float = size;
|
||||
var label:Int = 0;
|
||||
while(rSize > 1024 && label < sizeLabels.length-1) {
|
||||
var len = sizeLabels.length;
|
||||
while(rSize > 1024 && label < len-1) {
|
||||
label++;
|
||||
rSize /= 1024;
|
||||
}
|
||||
@@ -711,7 +712,7 @@ class CoolUtil
|
||||
* Gets the macro class created by hscript-improved for an abstract / enum
|
||||
*/
|
||||
@:noUsing public static inline function getMacroAbstractClass(className:String) {
|
||||
return Type.resolveClass('${className}_HSC');
|
||||
return Type.resolveClass(className + '_HSC');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,13 @@ class DrawUtil {
|
||||
}
|
||||
|
||||
public static function destroyDrawers() {
|
||||
dot.destroy(); line.destroy();
|
||||
dot = null; line = null;
|
||||
if(dot != null) {
|
||||
dot.destroy();
|
||||
dot = null;
|
||||
}
|
||||
if(line != null) {
|
||||
line.destroy();
|
||||
line = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package funkin.backend.utils;
|
||||
|
||||
import haxe.macro.Expr;
|
||||
|
||||
class MathUtil {
|
||||
public static function maxInt(...args:Int):Int {
|
||||
var max = args[0];
|
||||
for(i in 1...args.length) {
|
||||
var arg = args[i];
|
||||
if(arg > max)
|
||||
max = arg;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public static function minInt(...args:Int):Int {
|
||||
var min = args[0];
|
||||
for(i in 1...args.length) {
|
||||
var arg = args[i];
|
||||
if(arg < min)
|
||||
min = arg;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public static function maxFloat(...args:Float):Float {
|
||||
var max = args[0];
|
||||
for(i in 1...args.length) {
|
||||
var arg = args[i];
|
||||
if(arg > max)
|
||||
max = arg;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public static function minFloat(...args:Float):Float {
|
||||
var min = args[0];
|
||||
for(i in 1...args.length) {
|
||||
var arg = args[i];
|
||||
if(arg < min)
|
||||
min = arg;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to `Math.max` but with infinite amount of arguments
|
||||
* Uses `CoolUtil.maxInt` if theres only int arguments
|
||||
*
|
||||
* Might not preserve the order of arguments, please test this.
|
||||
*
|
||||
* Dont use this in hscript, it doesnt work, it only works on compile time
|
||||
**/
|
||||
@:dox(hide) public static macro function maxSmart(..._args:Expr):Expr {
|
||||
return genericMinMaxSmart(_args.toArray(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to `Math.min` but with infinite amount of arguments
|
||||
* Uses `CoolUtil.minInt` if theres only int arguments
|
||||
*
|
||||
* Might not preserve the order of arguments, please test this.
|
||||
*
|
||||
* Dont use this in hscript, it doesnt work, it only works on compile time
|
||||
**/
|
||||
@:dox(hide) public static macro function minSmart(..._args:Expr):Expr {
|
||||
return genericMinMaxSmart(_args.toArray(), false);
|
||||
}
|
||||
|
||||
#if macro
|
||||
@:dox(hide) private static function genericMinMaxSmart(_args:Array<Expr>, isMax:Bool):Expr {
|
||||
var args = _args.copy();
|
||||
if (args.length == 0) return macro 0;
|
||||
|
||||
var isFloat = true;
|
||||
var isInt = true;
|
||||
|
||||
for(arg in args) {
|
||||
if(isInt)
|
||||
isInt = arg.expr.match(EConst(CInt(_)));
|
||||
if(isFloat)
|
||||
isFloat = arg.expr.match(EConst(CFloat(_)));
|
||||
}
|
||||
|
||||
var funcPath = isInt ? "funkin.backend.utils.CoolUtil.maxInt" : "Math.max";
|
||||
if (!isMax) funcPath = isInt ? "funkin.backend.utils.CoolUtil.minInt" : "Math.min";
|
||||
|
||||
var func = funcPath.split(".");
|
||||
|
||||
function nested(lst:Array<Expr>):Expr {
|
||||
if (lst.length == 1) {
|
||||
return macro ${lst[0]};
|
||||
} else if (lst.length == 2) {
|
||||
return macro $p{func}(${lst[0]}, ${lst[1]});
|
||||
} else {
|
||||
var mid = Std.int(lst.length / 2);
|
||||
return macro $p{func}(${nested(lst.slice(0, mid))}, ${nested(lst.slice(mid, lst.length))});
|
||||
}
|
||||
}
|
||||
|
||||
var expr = nested(args);
|
||||
|
||||
//var printer = new haxe.macro.Printer();
|
||||
//trace(printer.printExpr(expr));
|
||||
|
||||
return macro $expr;
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -1038,10 +1038,14 @@ class StageEditor extends UIState {
|
||||
|
||||
if(sprite is FunkinSprite) {
|
||||
var sprite:FunkinSprite = cast sprite;
|
||||
var maxX = Math.max(Math.max(corners[0].x, corners[1].x), Math.max(corners[2].x, corners[3].x));
|
||||
var maxY = Math.max(Math.max(corners[0].y, corners[1].y), Math.max(corners[2].y, corners[3].y));
|
||||
var minX = Math.min(Math.min(corners[0].x, corners[1].x), Math.min(corners[2].x, corners[3].x));
|
||||
var minY = Math.min(Math.min(corners[0].y, corners[1].y), Math.min(corners[2].y, corners[3].y));
|
||||
var corner0 = corners[0];
|
||||
var corner1 = corners[1];
|
||||
var corner2 = corners[2];
|
||||
var corner3 = corners[3];
|
||||
var maxX = MathUtil.maxSmart(corner0.x, corner1.x, corner2.x, corner3.x);
|
||||
var maxY = MathUtil.maxSmart(corner0.y, corner1.y, corner2.y, corner3.y);
|
||||
var minX = MathUtil.minSmart(corner0.x, corner1.x, corner2.x, corner3.x);
|
||||
var minY = MathUtil.minSmart(corner0.y, corner1.y, corner2.y, corner3.y);
|
||||
|
||||
if(!sprite.extra.exists(exID("bounds"))) {
|
||||
sprite.extra.set(exID("bounds"), new FlxRect());
|
||||
|
||||
@@ -109,10 +109,10 @@ class UISliceSprite extends UISprite {
|
||||
bottom = frames.frames[framesOffset + 7];
|
||||
bottomright = frames.frames[framesOffset + 8];
|
||||
|
||||
leftWidth = Std.int(Math.max(topleft.frame.width, Math.max(middleleft.frame.width, bottomleft.frame.width)));
|
||||
rightWidth = Std.int(Math.max(topright.frame.width, Math.max(middleright.frame.width, bottomright.frame.width)));
|
||||
topHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height)));
|
||||
bottomHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height)));
|
||||
leftWidth = Std.int(MathUtil.maxSmart(topleft.frame.width, middleleft.frame.width, bottomleft.frame.width));
|
||||
rightWidth = Std.int(MathUtil.maxSmart(topright.frame.width, middleright.frame.width, bottomright.frame.width));
|
||||
topHeight = Std.int(MathUtil.maxSmart(topleft.frame.height, top.frame.height, topright.frame.height));
|
||||
bottomHeight = Std.int(MathUtil.maxSmart(topleft.frame.height, top.frame.height, topright.frame.height));
|
||||
|
||||
__meshDirty = true;
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ class OldUISliceSprite extends UISprite {
|
||||
bottom = frames.frames[framesOffset + 7];
|
||||
bottomright = frames.frames[framesOffset + 8];
|
||||
|
||||
leftWidth = Std.int(Math.max(topleft.frame.width, Math.max(middleleft.frame.width, bottomleft.frame.width)));
|
||||
rightWidth = Std.int(Math.max(topright.frame.width, Math.max(middleright.frame.width, bottomright.frame.width)));
|
||||
topHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height)));
|
||||
bottomHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height)));
|
||||
leftWidth = Std.int(MathUtil.maxSmart(topleft.frame.width, middleleft.frame.width, bottomleft.frame.width));
|
||||
rightWidth = Std.int(MathUtil.maxSmart(topright.frame.width, middleright.frame.width, bottomright.frame.width));
|
||||
topHeight = Std.int(MathUtil.maxSmart(topleft.frame.height, top.frame.height, topright.frame.height));
|
||||
bottomHeight = Std.int(MathUtil.maxSmart(topleft.frame.height, top.frame.height, topright.frame.height));
|
||||
}
|
||||
|
||||
public override function draw() @:privateAccess {
|
||||
|
||||
@@ -221,7 +221,7 @@ class FreeplayState extends MusicBeatState
|
||||
}
|
||||
|
||||
scoreText.text = "PERSONAL BEST:" + lerpScore;
|
||||
scoreBG.scale.set(Math.max(Math.max(diffText.width, scoreText.width), coopText.width) + 8, (coopText.visible ? coopText.y + coopText.height : 66));
|
||||
scoreBG.scale.set(MathUtil.maxSmart(diffText.width, scoreText.width, coopText.width) + 8, (coopText.visible ? coopText.y + coopText.height : 66));
|
||||
scoreBG.updateHitbox();
|
||||
scoreBG.x = FlxG.width - scoreBG.width;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user