Skip to content

Commit f41bc25

Browse files
committed
refactor: use Array to store Joints instead of manual linked list
1 parent ed0a632 commit f41bc25

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/World.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public final class World {
6464

6565
private Array<Body> bodies = new Array<>(WORLD_POOL_SIZE);
6666

67-
private Joint m_jointList = null;
67+
private Array<Joint> joints = new Array<>();
6868
private int jointCount = 0;
6969

7070
private final Vec2 gravity = new Vec2();
@@ -127,13 +127,7 @@ public <T extends Joint> T createJoint(JointDef<T> def) {
127127

128128
T j = Joint.create(this, def);
129129

130-
// Connect to the world list.
131-
j.m_prev = null;
132-
j.m_next = m_jointList;
133-
if (m_jointList != null) {
134-
m_jointList.m_prev = j;
135-
}
136-
m_jointList = j;
130+
joints.add(j);
137131
++jointCount;
138132

139133
// Connect to the bodies' doubly linked lists.
@@ -177,18 +171,7 @@ public void destroyJoint(Joint j) {
177171

178172
boolean collideConnected = j.getCollideConnected();
179173

180-
// Remove from the doubly linked list.
181-
if (j.m_prev != null) {
182-
j.m_prev.m_next = j.m_next;
183-
}
184-
185-
if (j.m_next != null) {
186-
j.m_next.m_prev = j.m_prev;
187-
}
188-
189-
if (j == m_jointList) {
190-
m_jointList = j.m_next;
191-
}
174+
joints.removeValueByIdentity(j);
192175

193176
// Disconnect from island graph.
194177
Body bodyA = j.getBodyA();
@@ -334,7 +317,7 @@ private void solve(TimeStep step) {
334317
for (Contact c = contactManager.contactList; c != null; c = c.m_next) {
335318
c.m_flags &= ~Contact.ISLAND_FLAG;
336319
}
337-
for (Joint j = m_jointList; j != null; j = j.m_next) {
320+
for (Joint j : joints) {
338321
j.m_islandFlag = false;
339322
}
340323

@@ -1149,16 +1132,6 @@ public Array<Body> getBodies() {
11491132
return bodies;
11501133
}
11511134

1152-
/**
1153-
* Get the world joint list. With the returned joint, use Joint.getNext to get the next joint in
1154-
* the world list. A null joint indicates the end of the list.
1155-
*
1156-
* @return the head of the world joint list.
1157-
*/
1158-
public Joint getJointList() {
1159-
return m_jointList;
1160-
}
1161-
11621135
/**
11631136
* Get the world contact list. With the returned contact, use Contact.getNext to get the next
11641137
* contact in the world list. A null contact indicates the end of the list.

fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/joints/Joint.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public static void destroy(Joint joint) {
2929
joint.destructor();
3030
}
3131

32-
public Joint m_prev = null;
33-
public Joint m_next = null;
3432
public final JointEdge m_edgeA = new JointEdge();
3533
public final JointEdge m_edgeB = new JointEdge();
3634
protected Body m_bodyA;

0 commit comments

Comments
 (0)