From c050ea73cebfb2721fac08bbcc3c5025c8245b7c Mon Sep 17 00:00:00 2001 From: NeeEoo Date: Fri, 1 Dec 2023 02:57:17 +0100 Subject: [PATCH] Small optimizations --- commandline/Main.hx | 194 +++++++++--------- commandline/commands/Compiler.hx | 58 +++--- commandline/commands/Update.hx | 78 +++---- libs.xml | 2 +- .../backend/system/framerate/SystemInfo.hx | 3 +- source/funkin/game/HudCamera.hx | 8 +- source/funkin/game/NoteGroup.hx | 10 +- source/funkin/game/StrumLine.hx | 12 +- 8 files changed, 186 insertions(+), 179 deletions(-) diff --git a/commandline/Main.hx b/commandline/Main.hx index 4efd742d7..6d628cf3c 100644 --- a/commandline/Main.hx +++ b/commandline/Main.hx @@ -3,111 +3,111 @@ package; import commands.*; class Main { - public static var commands:Array = []; + public static var commands:Array = []; - public static function initCommands() { - commands = [ - { - names: ["setup"], - doc: "Setups (or updates) all libraries required for the engine.", - func: Update.main, - dDoc: "This command runs through all libraries in libs.xml, and install them.\nIf they're already installed, they will be updated." - }, - { - names: ["help", null], - doc: "Shows help. Pass a command name to get additional help.", - func: help, - dDoc: "Usage: help \n\nFor example, use \"cne help test\" to get additional help on the test command." - }, - { - names: ["test"], - doc: "Creates a non final test build, then runs it.", - func: Compiler.test, - dDoc: "Usage: test \n" + - "\nThis will create a quick debug build binded to the source then run it, which means:" + - "\n- The assets WON'T be copied over - Assets will be read from the game's source." + - "\n- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets" + - "\n- This build will also use the mods folder from the source directory." + - "\n\nIf you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"" + - "\nAdditional arguments will be sent to the lime compiler." - }, - { - names: ["build"], - doc: "Creates a non final test build, without running it.", - func: Compiler.build, - dDoc: "Usage: build \n" + - "\nThis will create a quick debug build binded to the source then run it, which means:" + - "\n- The assets WON'T be copied over - Assets will be read from the game's source." + - "\n- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets" + - "\n- This build will also use the mods folder from the source directory." + - "\n\nIf you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"" + - "\nAdditional arguments will be sent to the lime compiler." - }, - { - names: ["release"], - doc: "Creates a final non debug build, containing all assets.", - func: Compiler.release, - dDoc: "Usage: release \n" + - "\nThis will create a final ready-for-release build, which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff." - }, - { - names: ["test-release"], - doc: "Creates a final non debug build, containing all assets.", - func: Compiler.testRelease, - dDoc: "Usage: release \n" + - "\nThis will create and run a final ready-for-release build, which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff." - } - ]; - } + public static function initCommands() { + commands = [ + { + names: ["setup"], + doc: "Setups (or updates) all libraries required for the engine.", + func: Update.main, + dDoc: "This command runs through all libraries in libs.xml, and install them.\nIf they're already installed, they will be updated." + }, + { + names: ["help", null], + doc: "Shows help. Pass a command name to get additional help.", + func: help, + dDoc: "Usage: help \n\nFor example, use \"cne help test\" to get additional help on the test command." + }, + { + names: ["test"], + doc: "Creates a non final test build, then runs it.", + func: Compiler.test, + dDoc: "Usage: test \n" + + "\nThis will create a quick debug build binded to the source then run it, which means:" + + "\n- The assets WON'T be copied over - Assets will be read from the game's source." + + "\n- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets" + + "\n- This build will also use the mods folder from the source directory." + + "\n\nIf you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"" + + "\nAdditional arguments will be sent to the lime compiler." + }, + { + names: ["build"], + doc: "Creates a non final test build, without running it.", + func: Compiler.build, + dDoc: "Usage: build \n" + + "\nThis will create a quick debug build binded to the source then run it, which means:" + + "\n- The assets WON'T be copied over - Assets will be read from the game's source." + + "\n- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets" + + "\n- This build will also use the mods folder from the source directory." + + "\n\nIf you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"" + + "\nAdditional arguments will be sent to the lime compiler." + }, + { + names: ["release"], + doc: "Creates a final non debug build, containing all assets.", + func: Compiler.release, + dDoc: "Usage: release \n" + + "\nThis will create a final ready-for-release build, which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff." + }, + { + names: ["test-release"], + doc: "Creates a final non debug build, containing all assets.", + func: Compiler.testRelease, + dDoc: "Usage: release \n" + + "\nThis will create and run a final ready-for-release build, which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff." + } + ]; + } - public static function main() { - initCommands(); - var args = Sys.args(); - var commandName = args.shift(); - if (commandName != null) - commandName = commandName.toLowerCase(); - for(c in commands) { - if (c.names.contains(commandName)) { - c.func(args); - return; - } - } - } + public static function main() { + initCommands(); + var args = Sys.args(); + var commandName = args.shift(); + if (commandName != null) + commandName = commandName.toLowerCase(); + for(c in commands) { + if (c.names.contains(commandName)) { + c.func(args); + return; + } + } + } - public static function help(args:Array) { - var cmdName = args.shift(); - if (cmdName != null) { - cmdName = cmdName.toLowerCase(); + public static function help(args:Array) { + var cmdName = args.shift(); + if (cmdName != null) { + cmdName = cmdName.toLowerCase(); - var matchingCommand = null; - for(c in commands) if (c.names.contains(cmdName)) { - matchingCommand = c; - break; - } + var matchingCommand = null; + for(c in commands) if (c.names.contains(cmdName)) { + matchingCommand = c; + break; + } - if (matchingCommand == null) { - Sys.println('help - Command named ${cmdName} not found.'); - return; - } + if (matchingCommand == null) { + Sys.println('help - Command named ${cmdName} not found.'); + return; + } - Sys.println('${matchingCommand.names.join(", ")}'); - Sys.println("---"); - Sys.println(matchingCommand.dDoc); + Sys.println('${matchingCommand.names.join(", ")}'); + Sys.println("---"); + Sys.println(matchingCommand.dDoc); - return; - } - // shows help - Sys.println("Codename Engine Command Line utility"); - Sys.println('Available commands (${commands.length}):\n'); - for(line in commands) { - Sys.println('${line.names.join(", ")} - ${line.doc}'); - } - } + return; + } + // shows help + Sys.println("Codename Engine Command Line utility"); + Sys.println('Available commands (${commands.length}):\n'); + for(line in commands) { + Sys.println('${line.names.join(", ")} - ${line.doc}'); + } + } } typedef Command = { - var names:Array; - var func:Array->Void; - var ?doc:String; - var ?dDoc:String; + var names:Array; + var func:Array->Void; + var ?doc:String; + var ?dDoc:String; } \ No newline at end of file diff --git a/commandline/commands/Compiler.hx b/commandline/commands/Compiler.hx index 0e0eb6921..620007230 100644 --- a/commandline/commands/Compiler.hx +++ b/commandline/commands/Compiler.hx @@ -1,35 +1,35 @@ package commands; class Compiler { - public static function test(args:Array) { - __build(args, ["test", getBuildTarget(), "-D", "TEST_BUILD"]); - } - public static function build(args:Array) { - __build(args, ["build", getBuildTarget(), "-D", "TEST_BUILD"]); - } - public static function release(args:Array) { - __build(args, ["build", getBuildTarget()]); - } - public static function testRelease(args:Array) { - __build(args, ["test", getBuildTarget()]); - } + public static function test(args:Array) { + __build(args, ["test", getBuildTarget(), "-D", "TEST_BUILD"]); + } + public static function build(args:Array) { + __build(args, ["build", getBuildTarget(), "-D", "TEST_BUILD"]); + } + public static function release(args:Array) { + __build(args, ["build", getBuildTarget()]); + } + public static function testRelease(args:Array) { + __build(args, ["test", getBuildTarget()]); + } - private static function __build(args:Array, arg:Array) { - for(a in args) - arg.push(a); - Sys.command("lime", arg); - } + private static function __build(args:Array, arg:Array) { + for(a in args) + arg.push(a); + Sys.command("lime", arg); + } - private static function getBuildTarget() { - return switch(Sys.systemName()) { - case "Windows": - "windows"; - case "Mac": - "macos"; - case "Linux": - "linux"; - case def: - def.toLowerCase(); - } - } + private static function getBuildTarget() { + return switch(Sys.systemName()) { + case "Windows": + "windows"; + case "Mac": + "macos"; + case "Linux": + "linux"; + case def: + def.toLowerCase(); + } + } } \ No newline at end of file diff --git a/commandline/commands/Update.hx b/commandline/commands/Update.hx index f829131fa..82a412a7c 100644 --- a/commandline/commands/Update.hx +++ b/commandline/commands/Update.hx @@ -7,15 +7,15 @@ import sys.io.Process; import sys.FileSystem; class Update { - public static function main(args:Array) { + public static function main(args:Array) { prettyPrint("Preparing installation..."); // to prevent messing with currently installed libs - if (!FileSystem.exists('.haxelib')) - FileSystem.createDirectory('.haxelib'); - - var libs:Array = []; - var libsXML:Access = new Access(Xml.parse(File.getContent('./libs.xml')).firstElement()); + if (!FileSystem.exists('.haxelib')) + FileSystem.createDirectory('.haxelib'); + + var libs:Array = []; + var libsXML:Access = new Access(Xml.parse(File.getContent('./libs.xml')).firstElement()); for (libNode in libsXML.elements) { var lib:Library = { @@ -33,23 +33,23 @@ class Update { libs.push(lib); } - for(lib in libs) { - // install libs - var globalism = lib.global == "true" ? "--global" : ""; - switch(lib.type) { - case "lib": - prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}"...'); - Sys.command('haxelib $globalism install ${lib.name} ${lib.version != null ? " " + lib.version : " "}'); - case "git": - prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}" from git url "${lib.url}"'); - if (lib.ref != null) - Sys.command('haxelib $globalism git ${lib.name} ${lib.url} ${lib.ref}'); - else - Sys.command('haxelib $globalism git ${lib.name} ${lib.url}'); - default: - prettyPrint('Cannot resolve library of type "${lib.type}"'); - } - } + for(lib in libs) { + // install libs + var globalism = lib.global == "true" ? "--global" : ""; + switch(lib.type) { + case "lib": + prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}"...'); + Sys.command('haxelib $globalism install ${lib.name} ${lib.version != null ? " " + lib.version : " "}'); + case "git": + prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}" from git url "${lib.url}"'); + if (lib.ref != null) + Sys.command('haxelib $globalism git ${lib.name} ${lib.url} ${lib.ref}'); + else + Sys.command('haxelib $globalism git ${lib.name} ${lib.url}'); + default: + prettyPrint('Cannot resolve library of type "${lib.type}"'); + } + } var proc = new Process('haxe --version'); proc.exitCode(true); @@ -76,24 +76,24 @@ class Update { } } } - } + } - public static function prettyPrint(text:String) { - var header = "══════"; - for(i in 0...(text.length-(text.lastIndexOf("\n")+1))) - header += "═"; - Sys.println(""); - Sys.println('╔$header╗'); - Sys.println('║ $text ║'); - Sys.println('╚$header╝'); - } + public static function prettyPrint(text:String) { + var header = "══════"; + for(i in 0...(text.length-(text.lastIndexOf("\n")+1))) + header += "═"; + Sys.println(""); + Sys.println('╔$header╗'); + Sys.println('║ $text ║'); + Sys.println('╚$header╝'); + } } typedef Library = { - var name:String; - var type:String; - var ?global:String; - var ?version:String; - var ?ref:String; - var ?url:String; + var name:String; + var type:String; + var ?global:String; + var ?version:String; + var ?ref:String; + var ?url:String; } diff --git a/libs.xml b/libs.xml index b6e8f9987..79f071fca 100644 --- a/libs.xml +++ b/libs.xml @@ -2,7 +2,7 @@ - + diff --git a/source/funkin/backend/system/framerate/SystemInfo.hx b/source/funkin/backend/system/framerate/SystemInfo.hx index e4c8c389f..0d2bc73a5 100644 --- a/source/funkin/backend/system/framerate/SystemInfo.hx +++ b/source/funkin/backend/system/framerate/SystemInfo.hx @@ -116,7 +116,8 @@ class SystemInfo extends FramerateCategory { } static function formatSysInfo() { - if (osInfo != "Unknown") __formattedSysText = 'System: $osInfo'; + __formattedSysText = ""; + if (osInfo != "Unknown") __formattedSysText += 'System: $osInfo'; if (cpuName != "Unknown") __formattedSysText += '\nCPU: $cpuName ${openfl.system.Capabilities.cpuArchitecture} ${(openfl.system.Capabilities.supports64BitProcesses ? '64-Bit' : '32-Bit')}'; if (gpuName != cpuName || vRAM != "Unknown") { var gpuNameKnown = gpuName != "Unknown" && gpuName != cpuName; diff --git a/source/funkin/game/HudCamera.hx b/source/funkin/game/HudCamera.hx index 9c59e08b7..c0b6c48ef 100644 --- a/source/funkin/game/HudCamera.hx +++ b/source/funkin/game/HudCamera.hx @@ -29,10 +29,10 @@ import openfl.Vector; class HudCamera extends FlxCamera { public var downscroll:Bool = false; - public override function update(elapsed:Float) { - super.update(elapsed); - // flipY = downscroll; - } + //public override function update(elapsed:Float) { + // super.update(elapsed); + // // flipY = downscroll; + //} // public override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, diff --git a/source/funkin/game/NoteGroup.hx b/source/funkin/game/NoteGroup.hx index ca617eec1..546f2bbe3 100644 --- a/source/funkin/game/NoteGroup.hx +++ b/source/funkin/game/NoteGroup.hx @@ -7,6 +7,7 @@ class NoteGroup extends FlxTypedGroup { var __loopSprite:Note; var i:Int = 0; var __currentlyLooping:Bool = false; + var __time:Float = -1.0; /** * How many ms it should show a note before it should be hit @@ -36,12 +37,13 @@ class NoteGroup extends FlxTypedGroup { public override function update(elapsed:Float) { i = length-1; __loopSprite = null; + __time = Conductor.songPosition; while(i >= 0) { __loopSprite = members[i--]; if (__loopSprite == null || !__loopSprite.exists || !__loopSprite.active) { continue; } - if (__loopSprite.strumTime - Conductor.songPosition > limit) + if (__loopSprite.strumTime - __time > limit) break; __loopSprite.update(elapsed); } @@ -56,11 +58,12 @@ class NoteGroup extends FlxTypedGroup { i = length-1; __loopSprite = null; + __time = Conductor.songPosition; while(i >= 0) { __loopSprite = members[i--]; if (__loopSprite == null || !__loopSprite.exists || !__loopSprite.visible) continue; - if (__loopSprite.strumTime - Conductor.songPosition > limit) break; + if (__loopSprite.strumTime - __time > limit) break; __loopSprite.draw(); } __currentlyLooping = oldCur; @@ -71,6 +74,7 @@ class NoteGroup extends FlxTypedGroup { public override function forEach(noteFunc:Note->Void, recursive:Bool = false) { i = length-1; __loopSprite = null; + __time = Conductor.songPosition; var oldCur = __currentlyLooping; __currentlyLooping = true; @@ -79,7 +83,7 @@ class NoteGroup extends FlxTypedGroup { __loopSprite = members[i--]; if (__loopSprite == null || !__loopSprite.exists) continue; - if (__loopSprite.strumTime - Conductor.songPosition > limit) break; + if (__loopSprite.strumTime - __time > limit) break; noteFunc(__loopSprite); } __currentlyLooping = oldCur; diff --git a/source/funkin/game/StrumLine.hx b/source/funkin/game/StrumLine.hx index ec8060c9a..f46c14e6f 100644 --- a/source/funkin/game/StrumLine.hx +++ b/source/funkin/game/StrumLine.hx @@ -175,17 +175,19 @@ class StrumLine extends FlxTypedGroup { onNoteUpdate.dispatch(PlayState.instance.__updateNote_event); if (PlayState.instance.__updateNote_event.cancelled) return; + var songPosition = Conductor.songPosition; + if (PlayState.instance.__updateNote_event.__updateHitWindow) { - daNote.canBeHit = (daNote.strumTime > Conductor.songPosition - (PlayState.instance.hitWindow * daNote.latePressWindow) - && daNote.strumTime < Conductor.songPosition + (PlayState.instance.hitWindow * daNote.earlyPressWindow)); + daNote.canBeHit = (daNote.strumTime > songPosition - (PlayState.instance.hitWindow * daNote.latePressWindow) + && daNote.strumTime < songPosition + (PlayState.instance.hitWindow * daNote.earlyPressWindow)); - if (daNote.strumTime < Conductor.songPosition - PlayState.instance.hitWindow && !daNote.wasGoodHit) + if (daNote.strumTime < songPosition - PlayState.instance.hitWindow && !daNote.wasGoodHit) daNote.tooLate = true; } - if (cpu && PlayState.instance.__updateNote_event.__autoCPUHit && !daNote.wasGoodHit && daNote.strumTime < Conductor.songPosition) PlayState.instance.goodNoteHit(this, daNote); + if (cpu && PlayState.instance.__updateNote_event.__autoCPUHit && !daNote.wasGoodHit && daNote.strumTime < songPosition) PlayState.instance.goodNoteHit(this, daNote); - if (daNote.wasGoodHit && daNote.isSustainNote && daNote.strumTime + (daNote.sustainLength) < Conductor.songPosition) { + if (daNote.wasGoodHit && daNote.isSustainNote && daNote.strumTime + (daNote.sustainLength) < songPosition) { deleteNote(daNote); return; }