Skip to content

Commit

Permalink
sequence fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyn0x8 committed Nov 25, 2024
1 parent f400aae commit b8d8f5a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions scripts/cynlib/sequence/modules/Sequence.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class CL_Sequence extends ScriptedModule {
function(timer:FlxTimer):Void {
event.callback();
obj.timers.remove(timer);

if (obj.completed()) {
obj.destroy();
}
}
));
}
Expand Down
33 changes: 23 additions & 10 deletions scripts/cynlib/sequence/modules/SongSequence.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ class CL_SongSequence extends ScriptedModule {
var obj:Dynamic = {
timers: new Array(),

startTime: Conductor.get_instance().songPosition,
curTime: Math.NEGATIVE_INFINITY,
startTime: 0,

running: true,
running: false,

toRemove: new Array(),

exists: true
};
Expand Down Expand Up @@ -69,20 +72,30 @@ class CL_SongSequence extends ScriptedModule {
return completed;
};

obj.update = function(elapsed:Float):Void {
obj.update = function():Void {
if (!obj.exists || !obj.get_running()) {
return;
}

var len:Int = obj.timers.length;
for (i in 0...len) {
var timer:SequenceEvent = obj.timers[len - 1 - i];
if (timer.time + obj.startTime > Conductor.get_instance().songPosition) {
var songPosition:Float = Conductor.get_instance().songPosition;
if (songPosition < obj.curTime) { // went back in time??
obj.destroy();
return;
}

obj.curTime = songPosition;

for (timer in obj.timers) {
if (obj.curTime > timer.time + obj.startTime) {
timer.callback();
obj.timers.remove(timer);
obj.toRemove.push(timer);
}
}

while (obj.toRemove.length > 0) {
obj.timers.remove(obj.toRemove.pop());
}

if (obj.completed()) {
obj.destroy();
}
Expand All @@ -106,7 +119,7 @@ class CL_SongSequence extends ScriptedModule {

for (event in events) {
event.time *= mult * 1000;
timers.push(event);
obj.timers.push(event);
}

obj.set_running(start);
Expand All @@ -121,7 +134,7 @@ class CL_SongSequence extends ScriptedModule {
private var alive:Array<SongSequence> = new Array();
override public function onUpdate(event:UpdateScriptEvent):Void {
for (obj in alive) {
obj.update(event.elapsed);
obj.update();
}
}

Expand Down

0 comments on commit b8d8f5a

Please sign in to comment.