From 8e016c28da86423cd63288d9ea511863bf7a7eeb Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Thu, 8 Dec 2022 13:46:22 +0100 Subject: [PATCH] absolutely not broken build --- buildnumber.txt | 2 +- source/funkin/system/Main.hx | 8 +++++ source/funkin/system/MusicBeatState.hx | 43 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/buildnumber.txt b/buildnumber.txt index 6efa8688..dfde4f32 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1420 \ No newline at end of file +1429 \ No newline at end of file diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index e42747f5..eba8af5e 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -48,6 +48,10 @@ class Main extends Sprite // You can pretty much ignore everything from here on - your code should go in your states. + #if sys + public static var gameThreads:Array = []; + #end + public static function main():Void { Lib.current.addChild(new Main()); @@ -112,6 +116,10 @@ class Main extends Sprite public function loadGameSettings() { + #if sys + for(i in 0...4) + gameThreads.push(Thread.createWithEventLoop(function() {Thread.current().events.promise();})); + #end Paths.assetsTree = new AssetsLibraryList(); Logs.init(); diff --git a/source/funkin/system/MusicBeatState.hx b/source/funkin/system/MusicBeatState.hx index 59bb15e7..58b9c9a5 100644 --- a/source/funkin/system/MusicBeatState.hx +++ b/source/funkin/system/MusicBeatState.hx @@ -1,5 +1,7 @@ package funkin.system; +import sys.thread.Thread; +import flixel.FlxBasic; import funkin.scripting.DummyScript; import flixel.FlxState; import flixel.FlxSubState; @@ -145,7 +147,48 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver Logs.trace('State script successfully reloaded', WARNING, GREEN); } call("update", [elapsed]); + + #if sys + // 4 threads + var partLength = Math.ceil(members.length / 4); + var done = [for(i in 0...Main.gameThreads.length) false]; + for(part=>thread in Main.gameThreads) { + thread.events.run(function() { + var p:Int = part; + try { + var i:Int = partLength * p; + var num:Int = partLength * (p+1); + var basic:FlxBasic = null; + + while (i < num) + { + basic = members[i++]; + + if (basic != null && basic.exists && basic.active) + basic.update(elapsed); + } + done[p] = true; + } catch(e) { + trace(e); + done[p] = true; + } + }); + } + while(done.contains(false)) + Thread.current().events.wait(0.0001); + + if (tooltips != null) + tooltips.update(elapsed); + + if (_reload && _reload_countdown > 0) + { + _reload_countdown--; + if (_reload_countdown == 0) + reloadUI(); + } + #else super.update(elapsed); + #end } @:dox(hide) public function stepHit(curStep:Int):Void