@@ 26,6 26,7 @@ import com.badlogic.gdx.physics.box2d.Tr
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool.Poolable;
import com.badlogic.gdx.utils.Pools;
+import net.dermetfan.gdx.physics.box2d.Box2DUtils;
import net.dermetfan.gdx.physics.box2d.WorldObserver.BodyChange;
import net.dermetfan.kryonet.box2d.multiplayer.UpdateProposer.Callback;
import net.dermetfan.kryonet.box2d.multiplayer.WorldUpdater;
@@ 120,6 121,9 @@ public class ProposingBody implements Po
}
public boolean setGravityScale(float scale) {
+ if(body.getGravityScale() == scale)
+ return true;
+
BodyChange change = Pools.obtain(BodyChange.class);
change.newGravityScale = scale;
@@ 139,6 143,9 @@ public class ProposingBody implements Po
}
public boolean setAngularDamping(float angularDamping) {
+ if(body.getAngularDamping() == angularDamping)
+ return true;
+
BodyChange change = Pools.obtain(BodyChange.class);
change.newAngularDamping = angularDamping;
@@ 158,6 165,9 @@ public class ProposingBody implements Po
}
public boolean setLinearVelocity(Vector2 v) {
+ if(v.equals(body.getLinearVelocity()))
+ return true;
+
BodyChange change = Pools.obtain(BodyChange.class);
change.newLinearVelocity = v;
@@ 177,12 187,239 @@ public class ProposingBody implements Po
}
public boolean setLinearVelocity(float vX, float vY) {
- Vector2 v = Pools.obtain(Vector2.class).set(vX, vY);
- boolean accepted = setLinearVelocity(v);
- Pools.free(v);
+ Vector2 linearVelocity = body.getLinearVelocity();
+ return linearVelocity.x == vX && linearVelocity.y == vY || setLinearVelocity(linearVelocity.set(vX, vY));
+ }
+
+ public boolean setAngularVelocity(float omega) {
+ if(omega == body.getAngularVelocity())
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newAngularVelocity = omega;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setAngularVelocity(omega);
+ return accepted;
+ }
+
+ public boolean setLinearDamping(float linearDamping) {
+ if(linearDamping == body.getLinearDamping())
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newLinearDamping = linearDamping;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setLinearDamping(linearDamping);
+ return accepted;
+ }
+
+ public boolean setSleepingAllowed(boolean flag) {
+ if(body.isSleepingAllowed() == flag)
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newSleepingAllowed = flag;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setSleepingAllowed(flag);
+ return accepted;
+ }
+
+ public boolean setBullet(boolean flag) {
+ if(body.isBullet() == flag)
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newBullet = flag;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setBullet(flag);
+ return accepted;
+ }
+
+ public boolean setAwake(boolean flag) {
+ if(body.isAwake() == flag)
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newAwake = flag;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setAwake(flag);
return accepted;
}
+ public boolean setActive(boolean flag) {
+ if(body.isActive() == flag)
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newActive = flag;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setActive(flag);
+ return accepted;
+ }
+
+ public boolean setFixedRotation(boolean flag) {
+ if(body.isFixedRotation() == flag)
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newFixedRotation = flag;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setFixedRotation(flag);
+ return accepted;
+ }
+
+ public boolean setType(BodyType type) {
+ if(body.getType() == type)
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newType = type;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setType(type);
+ return accepted;
+ }
+
+ public boolean setMassData(MassData data) {
+ if(Box2DUtils.equals(body.getMassData(), data))
+ return true;
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newMassData = data;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setMassData(data);
+ return accepted;
+ }
+
+ public boolean setTransform(float x, float y, float angle) {
+ Transform transform = body.getTransform();
+ if(transform.vals[Transform.POS_X] == x && transform.vals[Transform.POS_Y] == y && transform.getRotation() == angle)
+ return true;
+
+ transform.vals[Transform.POS_X] = x;
+ transform.vals[Transform.POS_Y] = y;
+ transform.setRotation(angle);
+
+ BodyChange change = Pools.obtain(BodyChange.class);
+ change.newTransform = transform;
+
+ @SuppressWarnings("unchecked")
+ Change<Body> update = Pools.obtain(Change.class);
+ update.setObjectHash(objectHash);
+ update.setChange(change);
+
+ boolean accepted = world.proposeBlocking(update, world.getConnection());
+
+ Pools.free(change);
+ Pools.free(update);
+
+ if(accepted)
+ body.setTransform(x, y, angle);
+ return accepted;
+ }
+
+ public boolean setTransform(Vector2 position, float angle) {
+ return setTransform(position.x, position.y, angle);
+ }
+
// local delegates
public void applyTorque(float torque, boolean wake) {body.applyTorque(torque, wake);}
@@ 203,32 440,22 @@ public class ProposingBody implements Po
public float getAngularVelocity() {return body.getAngularVelocity();}
- public void setAngularVelocity(float omega) {body.setAngularVelocity(omega);}
-
public void applyLinearImpulse(float impulseX, float impulseY, float pointX, float pointY, boolean wake) {body.applyLinearImpulse(impulseX, impulseY, pointX, pointY, wake);}
public Vector2 getWorldPoint(Vector2 localPoint) {return body.getWorldPoint(localPoint);}
public float getLinearDamping() {return body.getLinearDamping();}
- public void setLinearDamping(float linearDamping) {body.setLinearDamping(linearDamping);}
-
public boolean isSleepingAllowed() {return body.isSleepingAllowed();}
- public void setSleepingAllowed(boolean flag) {body.setSleepingAllowed(flag);}
-
public Vector2 getLinearVelocityFromWorldPoint(Vector2 worldPoint) {return body.getLinearVelocityFromWorldPoint(worldPoint);}
public void applyLinearImpulse(Vector2 impulse, Vector2 point, boolean wake) {body.applyLinearImpulse(impulse, point, wake);}
public boolean isBullet() {return body.isBullet();}
- public void setBullet(boolean flag) {body.setBullet(flag);}
-
public boolean isAwake() {return body.isAwake();}
- public void setAwake(boolean flag) {body.setAwake(flag);}
-
public float getAngle() {return body.getAngle();}
public Array<Fixture> getFixtureList() {return body.getFixtureList();}
@@ 237,8 464,6 @@ public class ProposingBody implements Po
public boolean isActive() {return body.isActive();}
- public void setActive(boolean flag) {body.setActive(flag);}
-
public Array<JointEdge> getJointList() {return body.getJointList();}
public void applyForceToCenter(float forceX, float forceY, boolean wake) {body.applyForceToCenter(forceX, forceY, wake);}
@@ 249,8 474,6 @@ public class ProposingBody implements Po
public boolean isFixedRotation() {return body.isFixedRotation();}
- public void setFixedRotation(boolean flag) {body.setFixedRotation(flag);}
-
public void applyAngularImpulse(float impulse, boolean wake) {body.applyAngularImpulse(impulse, wake);}
public Object getUserData() {return body.getUserData();}
@@ 259,26 482,16 @@ public class ProposingBody implements Po
public BodyType getType() {return body.getType();}
- public void setType(BodyType type) {body.setType(type);}
-
public void applyForce(float forceX, float forceY, float pointX, float pointY, boolean wake) {body.applyForce(forceX, forceY, pointX, pointY, wake);}
- public void resetMassData() {body.resetMassData();}
-
public Vector2 getWorldVector(Vector2 localVector) {return body.getWorldVector(localVector);}
public MassData getMassData() {return body.getMassData();}
- public void setMassData(MassData data) {body.setMassData(data);}
-
- public void setTransform(Vector2 position, float angle) {body.setTransform(position, angle);}
-
public Vector2 getPosition() {return body.getPosition();}
public void applyForceToCenter(Vector2 force, boolean wake) {body.applyForceToCenter(force, wake);}
- public void setTransform(float x, float y, float angle) {body.setTransform(x, y, angle);}
-
public Vector2 getLinearVelocityFromLocalPoint(Vector2 localPoint) {return body.getLinearVelocityFromLocalPoint(localPoint);}
public Vector2 getLocalCenter() {return body.getLocalCenter();}