standalone conductor update??
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package funkin.system;
|
||||
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
import flixel.FlxG;
|
||||
import funkin.system.Song.SwagSong;
|
||||
|
||||
/**
|
||||
@@ -36,6 +38,29 @@ class Conductor
|
||||
* Current position of the song, in milliseconds.
|
||||
*/
|
||||
public static var songPosition:Float;
|
||||
|
||||
|
||||
/**
|
||||
* Current step
|
||||
*/
|
||||
public static var curStep:Int = 0;
|
||||
|
||||
/**
|
||||
* Current beat
|
||||
*/
|
||||
public static var curBeat:Int = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Current step, as a `Float` (ex: 4.94, instead of 4)
|
||||
*/
|
||||
public static var curStepFloat:Float = 0;
|
||||
|
||||
/**
|
||||
* Current beat, as a `Float` (ex: 1.24, instead of 1)
|
||||
*/
|
||||
public static var curBeatFloat:Float = 0;
|
||||
|
||||
|
||||
@:dox(hide) public static var lastSongPos:Float;
|
||||
@:dox(hide) public static var offset:Float = 0;
|
||||
@@ -52,7 +77,7 @@ class Conductor
|
||||
public static function reset() {
|
||||
songPosition = lastSongPos = 0;
|
||||
bpmChangeMap = [];
|
||||
changeBPM(100);
|
||||
changeBPM(0);
|
||||
}
|
||||
/**
|
||||
* Maps BPM changes from a song.
|
||||
@@ -85,6 +110,59 @@ class Conductor
|
||||
trace("new BPM map BUDDY " + bpmChangeMap);
|
||||
}
|
||||
|
||||
public static function init() {
|
||||
FlxG.signals.preUpdate.add(update);
|
||||
reset();
|
||||
}
|
||||
|
||||
private static function update() {
|
||||
var elapsed = FlxG.elapsed;
|
||||
|
||||
if (FlxG.sound.music == null || !FlxG.sound.music.playing) return;
|
||||
if (FlxG.state != null && FlxG.state is MusicBeatState && cast(FlxG.state, MusicBeatState).cancelConductorUpdate) return;
|
||||
if (lastSongPos != (lastSongPos = FlxG.sound.music.time)) {
|
||||
// update conductor
|
||||
songPosition = FlxG.sound.music.time;
|
||||
} else {
|
||||
songPosition += elapsed * 1000;
|
||||
}
|
||||
|
||||
if (bpm > 0) {
|
||||
// updates curbeat and stuff
|
||||
var lastChange:BPMChangeEvent = {
|
||||
stepTime: 0,
|
||||
songTime: 0,
|
||||
bpm: 0
|
||||
}
|
||||
for (change in Conductor.bpmChangeMap)
|
||||
{
|
||||
if (Conductor.songPosition >= change.songTime)
|
||||
lastChange = change;
|
||||
}
|
||||
|
||||
curStepFloat = lastChange.stepTime + ((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet);
|
||||
curBeatFloat = curStepFloat / 4;
|
||||
|
||||
if (curStep != (curStep = Std.int(curStepFloat))) {
|
||||
// updates step
|
||||
var updateBeat = curBeat != (curBeat = Std.int(curBeatFloat));
|
||||
|
||||
if (FlxG.state is IBeatReceiver) {
|
||||
var state = FlxG.state;
|
||||
while(state != null) {
|
||||
if (FlxG.state is IBeatReceiver) {
|
||||
var st = cast(FlxG.state, IBeatReceiver);
|
||||
st.stepHit(curStep);
|
||||
if (updateBeat)
|
||||
st.beatHit(curBeat);
|
||||
}
|
||||
state = state.subState;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function changeBPM(newBpm:Float)
|
||||
{
|
||||
bpm = newBpm;
|
||||
|
||||
@@ -71,6 +71,10 @@ class FramerateField extends TextField {
|
||||
text.push('CODENAME ENGINE ALPHA - BUILD ${funkin.macros.BuildCounterMacro.getBuildNumber()}');
|
||||
#end
|
||||
if (debugMode) {
|
||||
text.push('======');
|
||||
text.push('Current Song Position: ${Conductor.songPosition} (${Conductor.curBeat} beats - ${Conductor.curStep} steps)');
|
||||
text.push('Current BPM: ${Conductor.bpm}');
|
||||
text.push('======');
|
||||
text.push('System: ${lime.system.System.platformLabel} ${lime.system.System.platformVersion}');
|
||||
text.push('Objs in state: ${FlxG.state.members.length}');
|
||||
text.push('Nb cameras: ${FlxG.cameras.list.length}');
|
||||
|
||||
@@ -133,6 +133,7 @@ class Main extends Sprite
|
||||
|
||||
Options.load();
|
||||
|
||||
Conductor.init();
|
||||
AudioSwitchFix.init();
|
||||
WindowsAPI.setDarkMode(true);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import flixel.math.FlxMath;
|
||||
import flixel.util.FlxTimer;
|
||||
import funkin.options.PlayerSettings;
|
||||
|
||||
class MusicBeatState extends FlxUIState
|
||||
class MusicBeatState extends FlxUIState implements IBeatReceiver
|
||||
{
|
||||
private var lastBeat:Float = 0;
|
||||
private var lastStep:Float = 0;
|
||||
@@ -42,6 +42,11 @@ class MusicBeatState extends FlxUIState
|
||||
*/
|
||||
public var controls(get, never):Controls;
|
||||
|
||||
/**
|
||||
* Whenever the Conductor auto update should be enabled or not.
|
||||
*/
|
||||
public var cancelConductorUpdate:Bool = false;
|
||||
|
||||
inline function get_controls():Controls
|
||||
return PlayerSettings.player1.controls;
|
||||
|
||||
@@ -55,45 +60,16 @@ class MusicBeatState extends FlxUIState
|
||||
//everyStep();
|
||||
var oldStep:Int = curStep;
|
||||
|
||||
updateCurStep();
|
||||
updateBeat();
|
||||
|
||||
if (oldStep != curStep && curStep > 0)
|
||||
stepHit();
|
||||
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
private function updateBeat():Void
|
||||
{
|
||||
curBeat = Math.floor(curBeatFloat = (curStepFloat / 4));
|
||||
}
|
||||
|
||||
private function updateCurStep():Void
|
||||
{
|
||||
var lastChange:BPMChangeEvent = {
|
||||
stepTime: 0,
|
||||
songTime: 0,
|
||||
bpm: 0
|
||||
}
|
||||
for (i in 0...Conductor.bpmChangeMap.length)
|
||||
{
|
||||
if (Conductor.songPosition >= Conductor.bpmChangeMap[i].songTime)
|
||||
lastChange = Conductor.bpmChangeMap[i];
|
||||
}
|
||||
|
||||
curStep = Math.floor(curStepFloat = lastChange.stepTime + ((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet));
|
||||
}
|
||||
|
||||
@:dox(hide) public function stepHit():Void
|
||||
@:dox(hide) public function stepHit(curStep:Int):Void
|
||||
{
|
||||
for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep);
|
||||
|
||||
if (curStep % 4 == 0)
|
||||
beatHit();
|
||||
}
|
||||
|
||||
@:dox(hide) public function beatHit():Void
|
||||
@:dox(hide) public function beatHit(curBeat:Int):Void
|
||||
{
|
||||
for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.system;
|
||||
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
import funkin.system.Conductor.BPMChangeEvent;
|
||||
import funkin.system.Conductor;
|
||||
import funkin.options.PlayerSettings;
|
||||
@@ -7,7 +8,7 @@ import flixel.FlxG;
|
||||
import flixel.FlxSubState;
|
||||
import flixel.math.FlxMath;
|
||||
|
||||
class MusicBeatSubstate extends FlxSubState
|
||||
class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
|
||||
{
|
||||
public function new()
|
||||
{
|
||||
@@ -43,42 +44,16 @@ class MusicBeatSubstate extends FlxSubState
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
//everyStep();
|
||||
var oldStep:Int = curStep;
|
||||
|
||||
updateCurStep();
|
||||
curBeat = Math.floor(curStep / 4);
|
||||
|
||||
if (oldStep != curStep && curStep > 0)
|
||||
stepHit();
|
||||
|
||||
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
private function updateCurStep():Void
|
||||
{
|
||||
var lastChange:BPMChangeEvent = {
|
||||
stepTime: 0,
|
||||
songTime: 0,
|
||||
bpm: 0
|
||||
}
|
||||
for (i in 0...Conductor.bpmChangeMap.length)
|
||||
{
|
||||
if (Conductor.songPosition > Conductor.bpmChangeMap[i].songTime)
|
||||
lastChange = Conductor.bpmChangeMap[i];
|
||||
}
|
||||
|
||||
curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet);
|
||||
@:dox(hide) public function stepHit(curStep:Int):Void
|
||||
{
|
||||
//do literally nothing neither dumbass
|
||||
}
|
||||
|
||||
@:dox(hide) public function stepHit():Void
|
||||
{
|
||||
if (curStep % 4 == 0)
|
||||
beatHit();
|
||||
}
|
||||
|
||||
@:dox(hide) public function beatHit():Void
|
||||
@:dox(hide) public function beatHit(curBeat:Int):Void
|
||||
{
|
||||
//do literally nothing dumbass
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user