IActionQueue ticking Optimisations

This commit is contained in:
bigguy345 committed 2025-07-07 12:23:34 +03:00
1 parent 3e6b37ac05
commit 25ab7b2f71
2 files changed
+18 -19

No files matched your search

@@ -265,6 +265,9 @@ public class Action implements IAction {
if (duration == 0 && onStart != null)
execute("start", this::executeOnStart);
if (done)
return;
duration++;
if (startAfterTicks > 0) {
@@ -257,34 +257,30 @@ public class ActionQueue implements IActionQueue {
///////////////////////////////////////////////////
// Handling
protected boolean tick(Action a) {
a.tick();
if (a.isDone()) {
if (a.onDone != null)
a.execute("done", a::executeOnDone);
a.kill();
return true;
}
return false;
}
protected void tick() {
if (!isWorking || isDead)
return;
if (!isParallel) {
IAction current = getCurrentAction();
if (current instanceof Action) {
Action cab = (Action) current;
cab.tick();
if (cab.isDone()) {
if (cab.onDone != null)
cab.execute("task", cab::executeOnDone);
cab.kill();
if (tick((Action) getCurrentAction()))
queue.pollFirst();
}
}
} else {
Iterator<IAction> pit = queue.iterator();
while (pit.hasNext()) {
Action a = (Action) pit.next();
a.tick();
if (a.isDone()) {
if (a.onDone != null)
a.execute("complete", a::executeOnDone);
a.kill();
while (pit.hasNext())
if (tick((Action) pit.next()))
pit.remove();
}
}
}
killWhenEmpty();