Skip to content

Commit c10aaaf

Browse files
committed
change behaviors list to array list
1 parent cc0fc99 commit c10aaaf

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/main/java/tech/fastj/graphics/game/GameObject.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import tech.fastj.graphics.Drawable;
44
import tech.fastj.systems.behaviors.Behavior;
55
import tech.fastj.systems.behaviors.BehaviorHandler;
6-
import tech.fastj.systems.collections.ManagedList;
76
import tech.fastj.systems.control.GameHandler;
87

98
import java.awt.Graphics2D;
9+
import java.util.ArrayList;
1010
import java.util.List;
1111
import java.util.Objects;
1212

@@ -22,11 +22,11 @@
2222
*/
2323
public abstract class GameObject extends Drawable {
2424

25-
private final ManagedList<Behavior> behaviors;
25+
private final List<Behavior> behaviors;
2626

2727
/** Initializes {@link GameObject} internals. */
2828
protected GameObject() {
29-
behaviors = new ManagedList<>();
29+
behaviors = new ArrayList<>();
3030
}
3131

3232
/** {@return the gmae object's {@link Behavior behaviors}} */
@@ -36,34 +36,27 @@ public List<Behavior> getBehaviors() {
3636

3737
/** Calls the {@link Behavior#init(GameObject)} method for each of the {@link GameObject game object}'s behaviors. */
3838
public void initBehaviors() {
39-
behaviors.run(list -> {
40-
for (Behavior behavior : list) {
41-
behavior.init(this);
42-
}
43-
});
39+
for (Behavior behavior : behaviors) {
40+
behavior.init(this);
41+
}
4442
}
4543

4644
/** Calls the {@link Behavior#fixedUpdate(GameObject)} method for each of the {@link GameObject game object}'s behaviors. */
4745
public void fixedUpdateBehaviors() {
48-
behaviors.run(list -> {
49-
for (Behavior behavior : list) {
50-
behavior.fixedUpdate(this);
51-
}
52-
});
46+
for (Behavior behavior : behaviors) {
47+
behavior.fixedUpdate(this);
48+
}
5349
}
5450

5551
/** Calls the {@link Behavior#update(GameObject)} method for each of the {@link GameObject game object}'s behaviors. */
5652
public void updateBehaviors() {
57-
behaviors.run(list -> {
58-
for (Behavior behavior : list) {
59-
behavior.update(this);
60-
}
61-
});
53+
for (Behavior behavior : behaviors) {
54+
behavior.update(this);
55+
}
6256
}
6357

6458
/** Calls the {@link Behavior#destroy()} method for each of the {@link GameObject game object}'s behaviors. */
6559
public synchronized void destroyAllBehaviors() {
66-
behaviors.shutdownNow();
6760
for (Behavior behavior : behaviors) {
6861
behavior.destroy();
6962
}

src/test/java/unittest/testcases/graphics/game/GameObjectTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ void tryUpdateBehaviorWithoutInitializing_shouldThrowNullPointerException() {
196196
MockBehavior mockBehavior = new MockBehavior();
197197
Scene mockScene = new MockEmptyScene();
198198

199-
gameObject.addBehavior(mockBehavior, mockScene);
200-
201-
Throwable exception = assertThrows(IllegalStateException.class, gameObject::fixedUpdateBehaviors, "Trying to update the behavior without initializing it should throw a null pointer exception on the Pointf, wrapped in an illegal state exception.");
202-
assertEquals(NullPointerException.class, exception.getCause().getClass(), "The underlying exception should be a null pointer exception.");
199+
gameObject.addBehavior(mockBehavior, mockScene); // pointf is null here
200+
assertThrows(NullPointerException.class, gameObject::fixedUpdateBehaviors, "Trying to update the behavior without initializing it should throw a null pointer exception on the Pointf.");
203201
}
204202
}

0 commit comments

Comments
 (0)