Skip to content

Commit 27145ee

Browse files
committed
fix: stop processing ActionCallbackQueue when changing scene
(LeaveAction)
1 parent 4d0c4b3 commit 27145ee

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

blade-engine/src/com/bladecoder/engine/actions/ActionCallbackQueue.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import com.badlogic.gdx.utils.Json;
2222
import com.badlogic.gdx.utils.JsonValue;
23+
import com.bladecoder.engine.model.Scene;
24+
import com.bladecoder.engine.model.World;
2325
import com.bladecoder.engine.util.ActionCallbackSerialization;
2426

2527
/**
@@ -50,8 +52,15 @@ public static void run() {
5052
runQueue.addAll(queue);
5153
queue.clear();
5254

53-
for(ActionCallback cb: runQueue)
55+
// TOFIX Quick hack to stop processing when changing scene
56+
Scene scn = World.getInstance().getCurrentScene();
57+
58+
for(ActionCallback cb: runQueue) {
5459
cb.resume();
60+
61+
if(scn != World.getInstance().getCurrentScene())
62+
break;
63+
}
5564

5665
runQueue.clear();
5766
}

blade-engine/src/com/bladecoder/engine/actions/LeaveAction.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.bladecoder.engine.model.World;
2222

2323

24-
public class LeaveAction implements Action {
24+
public class LeaveAction implements Action, ActionCallback {
2525
public static final String INFO = "Change the current scene.";
2626
public static final Param[] PARAMS = {
2727
new Param("scene", "The target scene", Type.SCENE, true),
@@ -32,10 +32,16 @@ public class LeaveAction implements Action {
3232
@Override
3333
public boolean run(ActionCallback cb) {
3434

35-
World.getInstance().setCurrentScene(scene);
35+
// Queue the setCurrentScene to execute at the end of world update
36+
ActionCallbackQueue.add(this);
3637

3738
return false;
3839
}
40+
41+
@Override
42+
public void resume() {
43+
World.getInstance().setCurrentScene(scene);
44+
}
3945

4046
@Override
4147
public void setParams(HashMap<String, String> params) {

blade-engine/src/com/bladecoder/engine/model/World.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,6 @@ public void update(float delta) {
208208
return;
209209

210210
timeOfGame += delta;
211-
212-
ActionCallbackQueue.run();
213-
214-
// Check because the ActionCallbackQueue can call to setCurrentScene()
215-
if (assetState != AssetState.LOADED)
216-
return;
217211

218212
getCurrentScene().update(delta);
219213
textManager.update(delta);
@@ -222,6 +216,8 @@ public void update(float delta) {
222216
if (!transition.isFinish()) {
223217
transition.update(delta);
224218
}
219+
220+
ActionCallbackQueue.run();
225221
}
226222

227223
@Override

0 commit comments

Comments
 (0)