public override bool ParseBytesAndExecute(byte[] data) { if (data.Length != 8 + 1 + 8) { return(false); } long jid = Utilities.BytesToLong(Utilities.BytesPartial(data, 0, 8)); JointUpdateMode mode = (JointUpdateMode)data[8]; double val = Utilities.BytesToDouble(Utilities.BytesPartial(data, 8 + 1, 8)); InternalBaseJoint jointo = TheClient.TheRegion.GetJoint(jid); if (jointo == null) { return(false); } switch (mode) { case JointUpdateMode.SERVO_GOAL: (jointo as JointVehicleMotor).SetGoal(val); break; case JointUpdateMode.SERVO_SPEED: (jointo as JointVehicleMotor).SetCorrectiveSpeed(val); break; } return(true); }
public void AddJoint(InternalBaseJoint joint) { Joints.Add(joint); joint.One.Joints.Add(joint); joint.Two.Joints.Add(joint); joint.Enable(); if (joint is BaseJoint pjoint) { pjoint.CurrentJoint = pjoint.GetBaseJoint(); PhysicsWorld.Add(pjoint.CurrentJoint); } }
/// <summary> /// Adds a new joint to the region. /// </summary> /// <param name="joint">The joint to add.</param> public void AddJoint(InternalBaseJoint joint) { Joints.Add(joint); joint.One.Joints.Add(joint); joint.Two.Joints.Add(joint); joint.JID = jID++; joint.Enable(); if (joint is BaseJoint pjoint) { pjoint.CurrentJoint = pjoint.GetBaseJoint(); PhysicsWorld.Add(pjoint.CurrentJoint); } SendToAll(new AddJointPacketOut(joint)); }
public void DestroyJoint(InternalBaseJoint joint) { if (!Joints.Remove(joint)) { SysConsole.Output(OutputType.WARNING, "Destroyed non-existent joint?!"); } joint.One.Joints.Remove(joint); joint.Two.Joints.Remove(joint); joint.Disable(); if (joint is BaseJoint pjoint) { PhysicsWorld.Remove(pjoint.CurrentJoint); } }
/// <summary> /// Destroys a joint, removing it from the region. /// </summary> /// <param name="joint">The join to remove.</param> public void DestroyJoint(InternalBaseJoint joint) { Joints.Remove(joint); joint.One.Joints.Remove(joint); joint.Two.Joints.Remove(joint); joint.Disable(); if (joint is BaseJoint pjoint) { if (pjoint.CurrentJoint != null) { try { PhysicsWorld.Remove(pjoint.CurrentJoint); } catch (Exception ex) { // We don't really care... Utilities.CheckException(ex); } } } SendToAll(new DestroyJointPacketOut(joint)); }
public AddJointPacketOut(InternalBaseJoint joint) { UsageType = NetUsageType.ENTITIES; ID = ServerToClientPacket.ADD_JOINT; int len = 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4; // TODO: joint registry! if (joint is JointBallSocket) { Data = new byte[len + 24]; Data[0] = 0; ((JointBallSocket)joint).Position.ToDoubleBytes().CopyTo(Data, len); } else if (joint is JointSlider) { Data = new byte[len + 24]; Data[0] = 1; ((JointSlider)joint).Direction.ToDoubleBytes().CopyTo(Data, len); } else if (joint is JointDistance) { Data = new byte[len + 4 + 4 + 24 + 24]; Data[0] = 2; Utilities.FloatToBytes((float)((JointDistance)joint).Min).CopyTo(Data, len); Utilities.FloatToBytes((float)((JointDistance)joint).Max).CopyTo(Data, len + 4); ((JointDistance)joint).Ent1Pos.ToDoubleBytes().CopyTo(Data, len + 4 + 4); ((JointDistance)joint).Ent2Pos.ToDoubleBytes().CopyTo(Data, len + 4 + 4 + 24); } else if (joint is JointPullPush) { Data = new byte[len + 24 + 1]; Data[0] = 3; ((JointPullPush)joint).Axis.ToDoubleBytes().CopyTo(Data, len); Data[len + 24] = (byte)(((JointPullPush)joint).Mode ? 1 : 0); } else if (joint is JointForceWeld) { Data = new byte[len]; Data[0] = 4; } else if (joint is JointSpinner) { Data = new byte[len + 24]; Data[0] = 5; ((JointSpinner)joint).Direction.ToDoubleBytes().CopyTo(Data, len); } else if (joint is JointTwist) { Data = new byte[len + 24 + 24]; Data[0] = 6; ((JointTwist)joint).AxisOne.ToDoubleBytes().CopyTo(Data, len); ((JointTwist)joint).AxisTwo.ToDoubleBytes().CopyTo(Data, len + 24); } else if (joint is JointWeld) { Data = new byte[len]; Data[0] = 7; } else if (joint is JointVehicleMotor) { Data = new byte[len + 24 + 1]; Data[0] = 8; ((JointVehicleMotor)joint).Direction.ToDoubleBytes().CopyTo(Data, len); Data[len + 24] = (byte)(((JointVehicleMotor)joint).IsSteering ? 1 : 0); } else if (joint is JointLAxisLimit) { Data = new byte[len + 24 + 24 + 24 + 4 + 4]; Data[0] = 9; ((JointLAxisLimit)joint).CPos1.ToDoubleBytes().CopyTo(Data, len); ((JointLAxisLimit)joint).CPos2.ToDoubleBytes().CopyTo(Data, len + 24); ((JointLAxisLimit)joint).Axis.ToDoubleBytes().CopyTo(Data, len + 24 + 24); Utilities.FloatToBytes((float)((JointLAxisLimit)joint).Min).CopyTo(Data, len + 24 + 24 + 24); Utilities.FloatToBytes((float)((JointLAxisLimit)joint).Max).CopyTo(Data, len + 24 + 24 + 24 + 4); } else if (joint is JointSwivelHinge) { Data = new byte[len + 24 + 24]; Data[0] = 10; ((JointSwivelHinge)joint).WorldHinge.ToDoubleBytes().CopyTo(Data, len); ((JointSwivelHinge)joint).WorldTwist.ToDoubleBytes().CopyTo(Data, len + 24); } else if (joint is ConstWheelStepUp) { Data = new byte[len + 4]; Data[0] = 11; Utilities.FloatToBytes((float)((ConstWheelStepUp)joint).Height).CopyTo(Data, len); } else if (joint is ConnectorBeam) { Data = new byte[len + 4 * 4 + 1]; Data[0] = 12; Utilities.FloatToBytes(((ConnectorBeam)joint).color.R).CopyTo(Data, len); Utilities.FloatToBytes(((ConnectorBeam)joint).color.G).CopyTo(Data, len + 4); Utilities.FloatToBytes(((ConnectorBeam)joint).color.B).CopyTo(Data, len + 4 * 2); Utilities.FloatToBytes(((ConnectorBeam)joint).color.A).CopyTo(Data, len + 4 * 3); Data[len + 4 * 4] = (byte)((ConnectorBeam)joint).type; } else if (joint is JointFlyingDisc) { Data = new byte[len]; Data[0] = 13; } else if (joint is JointNoCollide) { Data = new byte[len]; Data[0] = 14; } else if (joint is JointHinge) { Data = new byte[len + 24]; Data[0] = 15; ((JointHinge)joint).WorldHinge.ToDoubleBytes().CopyTo(Data, len); } Utilities.LongToBytes(joint.One.EID).CopyTo(Data, 1); Utilities.LongToBytes(joint.Two.EID).CopyTo(Data, 1 + 8); Utilities.LongToBytes(joint.JID).CopyTo(Data, 1 + 8 + 8); joint.One.GetPosition().ToDoubleBytes().CopyTo(Data, 1 + 8 + 8 + 8); BEPUutilities.Quaternion quat = joint.One.GetOrientation(); Utilities.FloatToBytes((float)quat.X).CopyTo(Data, 1 + 8 + 8 + 8 + 24); Utilities.FloatToBytes((float)quat.Y).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4); Utilities.FloatToBytes((float)quat.Z).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4); Utilities.FloatToBytes((float)quat.W).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4); joint.Two.GetPosition().ToDoubleBytes().CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4); BEPUutilities.Quaternion quat2 = joint.Two.GetOrientation(); Utilities.FloatToBytes((float)quat2.X).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24); Utilities.FloatToBytes((float)quat2.Y).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4); Utilities.FloatToBytes((float)quat2.Z).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4); Utilities.FloatToBytes((float)quat2.W).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4); }
public DestroyJointPacketOut(InternalBaseJoint joint) { UsageType = NetUsageType.ENTITIES; ID = ServerToClientPacket.DESTROY_JOINT; Data = Utilities.LongToBytes(joint.JID); }