diff --git a/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Body.java b/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Body.java index 967c05fc9..3a12f3528 100644 --- a/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Body.java +++ b/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Body.java @@ -28,7 +28,7 @@ * @author Daniel Murphy */ public final class Body { - static final int e_islandFlag = 0x0001; + private static final int e_islandFlag = 0x0001; private static final int e_awakeFlag = 0x0002; private static final int e_autoSleepFlag = 0x0004; @@ -939,6 +939,26 @@ public void setBullet(boolean flag) { } } + boolean isIslandFlagOff() { + return (m_flags & e_islandFlag) == 0; + } + + boolean isIslandFlagOn() { + return (m_flags & e_islandFlag) != 0; + } + + boolean isIslandFlagOn2() { + return (m_flags & e_islandFlag) == e_islandFlag; + } + + void setIslandFlag(boolean flag) { + if (flag) { + m_flags |= e_islandFlag; + } else { + m_flags &= ~e_islandFlag; + } + } + /** * You can disable sleeping on this body. * If you disable sleeping, the body will be woken. diff --git a/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Island.java b/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Island.java index e4c1a436f..29731144b 100644 --- a/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Island.java +++ b/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/Island.java @@ -530,7 +530,7 @@ private void report(ContactVelocityConstraint[] constraints) { void resetFlagsAndSynchronizeBroadphaseProxies() { for (int i = 0; i < bodyCount; ++i) { Body body = bodies[i]; - body.m_flags &= ~Body.e_islandFlag; + body.setIslandFlag(false); if (body.getType() != BodyType.DYNAMIC) { continue; @@ -550,7 +550,7 @@ void postSolveCleanup() { // Allow static bodies to participate in other islands. Body b = bodies[i]; if (b.getType() == BodyType.STATIC) { - b.m_flags &= ~Body.e_islandFlag; + b.setIslandFlag(false); } } } diff --git a/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/World.java b/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/World.java index e38ad7e2b..47240a700 100644 --- a/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/World.java +++ b/fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/World.java @@ -308,7 +308,7 @@ private void solve(TimeStep step) { // Clear all the island flags. for (Body b : bodies) { - b.m_flags &= ~Body.e_islandFlag; + b.setIslandFlag(false); } for (Contact c = contactManager.contactList; c != null; c = c.m_next) { c.m_flags &= ~Contact.ISLAND_FLAG; @@ -324,7 +324,7 @@ private void solve(TimeStep step) { } for (Body seed : bodies) { - if ((seed.m_flags & Body.e_islandFlag) == Body.e_islandFlag) { + if (seed.isIslandFlagOn2()) { continue; } @@ -341,7 +341,7 @@ private void solve(TimeStep step) { island.clear(); int stackCount = 0; stack[stackCount++] = seed; - seed.m_flags |= Body.e_islandFlag; + seed.setIslandFlag(true); // Perform a depth first search (DFS) on the constraint graph. while (stackCount > 0) { @@ -386,13 +386,13 @@ private void solve(TimeStep step) { Body other = ce.other; // Was the other body already added to this island? - if ((other.m_flags & Body.e_islandFlag) == Body.e_islandFlag) { + if (other.isIslandFlagOn2()) { continue; } assert stackCount < stackSize; stack[stackCount++] = other; - other.m_flags |= Body.e_islandFlag; + other.setIslandFlag(true); } // Search all joints connect to this body. @@ -411,13 +411,13 @@ private void solve(TimeStep step) { island.add(je.joint); je.joint.m_islandFlag = true; - if ((other.m_flags & Body.e_islandFlag) == Body.e_islandFlag) { + if (other.isIslandFlagOn2()) { continue; } assert stackCount < stackSize; stack[stackCount++] = other; - other.m_flags |= Body.e_islandFlag; + other.setIslandFlag(true); } } island.solve(step, gravity, allowSleep); @@ -428,7 +428,7 @@ private void solve(TimeStep step) { // Synchronize fixtures, check for out of range bodies. for (Body b : bodies) { // If a body was not in an island then it did not move. - if ((b.m_flags & Body.e_islandFlag) == 0) { + if (b.isIslandFlagOff()) { continue; } @@ -459,7 +459,7 @@ private void solveTOI(final TimeStep step) { if (stepComplete) { for (Body b : bodies) { - b.m_flags &= ~Body.e_islandFlag; + b.setIslandFlag(false); b.m_sweep.alpha0 = 0.0f; } @@ -613,8 +613,8 @@ private void solveTOI(final TimeStep step) { island.add(bB); island.add(minContact); - bA.m_flags |= Body.e_islandFlag; - bB.m_flags |= Body.e_islandFlag; + bA.setIslandFlag(true); + bB.setIslandFlag(true); minContact.m_flags |= Contact.ISLAND_FLAG; // Get contacts on bodyA and bodyB. @@ -654,7 +654,7 @@ private void solveTOI(final TimeStep step) { // Tentatively advance the body to the TOI. backup1.set(other.m_sweep); - if ((other.m_flags & Body.e_islandFlag) == 0) { + if (other.isIslandFlagOff()) { other.advance(minAlpha); } @@ -680,12 +680,12 @@ private void solveTOI(final TimeStep step) { island.add(contact); // Has the other body already been added to the island? - if ((other.m_flags & Body.e_islandFlag) != 0) { + if (other.isIslandFlagOn()) { continue; } // Add the other body to the island. - other.m_flags |= Body.e_islandFlag; + other.setIslandFlag(true); if (other.getType() != BodyType.STATIC) { other.setAwake(true);