Skip to content

Commit

Permalink
Another Optimization
Browse files Browse the repository at this point in the history
I added Timer to anticipate that can be memory leak if it's running in-game. If someone in-game, the Task cancels itself, can be rescheduled after player exit their game and enters menu screen.
  • Loading branch information
WilloIzCitron committed Dec 28, 2024
1 parent ac82f85 commit 438cb82
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/bluearchive/ui/ArchivDBackground.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,28 @@ public static void buildL2D(String name) {
render.visible = false;

Events.on(EventType.ClientLoadEvent.class, e -> {
Events.run(EventType.Trigger.update, () -> frame.set(l2dLoaded.loadedL2ds.get((int) (Time.globalTime / l2dLoaded.frameSpeed) % l2dLoaded.loadedL2ds.size)));
boolean isRegionLoaded = false;
animBG.setFillParent(true);
group.addChildAt(0, animBG);
Log.infoTag("ArchiveDustry", "Background Loaded!");
Timer timer = Timer.instance();
Timer.Task task = new Timer.Task() {
@Override
public void run() {
if (!state.isMenu() || loadFragShow) {
//failsafe if it is still running in
return;
}
if(frame != null) {
animBG.getRegion().set(frame);
}
//Log.infoTag("ArchivDebug", "Background Running....");
if(!state.isMenu()) this.cancel();;
frame.set(l2dLoaded.loadedL2ds.get((int) (Time.globalTime / l2dLoaded.frameSpeed) % l2dLoaded.loadedL2ds.size));
animBG.getRegion().set(frame);
}
};
Events.run(EventType.Trigger.update, () -> {
if (!state.isMenu()) {
//failsafe if it is still running in
//Log.infoTag("ArchivDebug", "Background stopped fr");
return;
}
if(state.isMenu() & timer.isEmpty() || !task.isScheduled()) timer.scheduleTask(task, 0, 0.001f);
});
timer.scheduleTask(task, 0, 0.001f);
});
} else {
Expand Down

0 comments on commit 438cb82

Please sign in to comment.