Added torque syncing to client in TileMechanical

This commit is contained in:
Robert S 2014-06-10 10:14:59 -04:00
parent f02912e7a4
commit a90702fa27
2 changed files with 12 additions and 3 deletions

View file

@ -26,11 +26,12 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj, IVectorWorld
public boolean doDebug = false; public boolean doDebug = false;
/** Used to note that you should trigger a packet update for rotation */ /** Used to note that you should trigger a packet update for rotation */
public boolean markRotationUpdate = false; public boolean markRotationUpdate = false;
public boolean markTorqueUpdate = false;
/** Which section of debug is enabled */ /** Which section of debug is enabled */
public int debugCue = 0, maxDebugCue = 1, minDebugCue = 0; public int debugCue = 0, maxDebugCue = 1, minDebugCue = 0;
public static final int UPDATE_DEBUG = 0, CONNECTION_DEBUG = 1; public static final int UPDATE_DEBUG = 0, CONNECTION_DEBUG = 1;
/** Rotational Force */ /** Rotational Force */
public double torque = 0; public double torque = 0, prevTorque;
/** Rotational speed */ /** Rotational speed */
public double prevAngularVelocity, angularVelocity = 0; public double prevAngularVelocity, angularVelocity = 0;
/** Rotational acceleration */ /** Rotational acceleration */
@ -124,6 +125,12 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj, IVectorWorld
markRotationUpdate = true; markRotationUpdate = true;
} }
if (Math.abs(prevTorque - torque) > 0.01f)
{
prevTorque = torque;
markTorqueUpdate = true;
}
//----------------------------------- //-----------------------------------
// Loss calculations // Loss calculations
//----------------------------------- //-----------------------------------

View file

@ -63,10 +63,11 @@ public abstract class TileMechanical extends TileBase implements INodeProvider,
mechanicalNode.update(); mechanicalNode.update();
if (!this.getWorldObj().isRemote) if (!this.getWorldObj().isRemote)
{ {
if (mechanicalNode.markRotationUpdate && ticks % 3 == 0) if (ticks % 3 == 0 && (mechanicalNode.markTorqueUpdate || mechanicalNode.markRotationUpdate))
{ {
sendRotationPacket(); sendRotationPacket();
mechanicalNode.markRotationUpdate = false; mechanicalNode.markRotationUpdate = false;
mechanicalNode.markTorqueUpdate = false;
} }
} }
} }
@ -89,7 +90,7 @@ public abstract class TileMechanical extends TileBase implements INodeProvider,
private void sendRotationPacket() private void sendRotationPacket()
{ {
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_VELOCITY, this, mechanicalNode.angularVelocity), worldObj, new Vector3(this), 20); PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_VELOCITY, this, mechanicalNode.angularVelocity, mechanicalNode.torque), worldObj, new Vector3(this), 20);
} }
@Override @Override
@ -107,6 +108,7 @@ public abstract class TileMechanical extends TileBase implements INodeProvider,
else if (id == PACKET_VELOCITY) else if (id == PACKET_VELOCITY)
{ {
mechanicalNode.angularVelocity = data.readDouble(); mechanicalNode.angularVelocity = data.readDouble();
mechanicalNode.torque = data.readDouble();
return true; return true;
} }
} }