Skip to content

Commit c236271

Browse files
authored
Merge pull request #100 from fastjengine/behavior-destroy
Add method calls to destroy behaviors in Scene/SimpleManager, fixes #99 Additions - BehaviorManager.destroyListenerList for destroying the behaviors of any BehaviorHandler's behavior listener list. - BehaviorHandler.destroyBehaviorListeners for calling the BehaviorManager's behavior destroying method. ## Bug Fixes - (#99) Added behavior destroy calls to both SimpleManager and Scene classes' `reset` methods.
2 parents f7d932d + c77be11 commit c236271

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/main/java/tech/fastj/systems/behaviors/BehaviorHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ default void updateBehaviorListeners() {
5252
BehaviorManager.updateBehaviorListeners(this);
5353
}
5454

55+
/** Destroys all behaviors in the behavior handler, without removing them. */
56+
default void destroyBehaviorListeners() {
57+
BehaviorManager.destroyListenerList(this);
58+
}
59+
5560
/** Removes all behavior listeners in the behavior handler. */
5661
default void clearBehaviorListeners() {
5762
BehaviorManager.clearListenerList(this);

src/main/java/tech/fastj/systems/behaviors/BehaviorManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public static void removeListenerList(BehaviorHandler behaviorHandler) {
7575
BehaviorListenerLists.remove(behaviorHandler);
7676
}
7777

78+
/**
79+
* Destroys all behaviors from the list aliased to the specified {@link BehaviorHandler}, without removing them.
80+
*
81+
* @param behaviorHandler The {@code BehaviorHandler} used as the alias to destroy all behavior listeners.
82+
*/
83+
public static void destroyListenerList(BehaviorHandler behaviorHandler) {
84+
for (GameObject listener : BehaviorListenerLists.get(behaviorHandler).values()) {
85+
listener.destroyAllBehaviors();
86+
}
87+
}
88+
7889
/**
7990
* Removes all elements from the list aliased to the specified {@link BehaviorHandler}.
8091
*

src/main/java/tech/fastj/systems/control/Scene.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void clearAllLists() {
122122
/** Resets the scene's state entirely. */
123123
public void reset() {
124124
this.setInitialized(false);
125+
this.destroyBehaviorListeners();
125126
this.clearAllLists();
126127
camera.reset();
127128
}

src/main/java/tech/fastj/systems/control/SimpleManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public Camera getCamera() {
8787
@Override
8888
public void reset() {
8989
camera.reset();
90+
this.destroyBehaviorListeners();
9091
inputManager.clearAllLists();
9192
drawableManager.clearAllLists();
9293
this.clearTaggableEntities();

0 commit comments

Comments
 (0)