public override void FlipY(bool relativeToSub) { base.FlipY(relativeToSub); if (Prefab.CanSpriteFlipY) { SpriteEffects ^= SpriteEffects.FlipVertically; } if (StairDirection != Direction.None) { StairDirection = StairDirection == Direction.Left ? Direction.Right : Direction.Left; Bodies.ForEach(b => GameMain.World.RemoveBody(b)); Bodies.Clear(); bodyDebugDimensions.Clear(); CreateStairBodies(); } if (HasBody) { CreateSections(); UpdateSections(); } }
public void RemoveAllBodies() { foreach (var body in Bodies) { body.RemoveAllBoxes(); } Bodies.Clear(); }
/// <summary> /// Clear all data /// </summary> public static void ClearAllData() { // Deal with active bodies first RemoveActive(); ClearActive(); // Clear both the lists Bodies.Clear(); }
private void UpdateSections() { if (Bodies == null) { return; } foreach (Body b in Bodies) { GameMain.World.RemoveBody(b); } Bodies.Clear(); bodyDebugDimensions.Clear(); #if CLIENT convexHulls?.ForEach(ch => ch.Remove()); convexHulls?.Clear(); #endif bool hasHoles = false; var mergedSections = new List <WallSection>(); for (int i = 0; i < Sections.Length; i++) { // if there is a gap and we have sections to merge, do it. if (SectionBodyDisabled(i)) { hasHoles = true; if (!mergedSections.Any()) { continue; } var mergedRect = GenerateMergedRect(mergedSections); mergedSections.Clear(); CreateRectBody(mergedRect, createConvexHull: true); } else { mergedSections.Add(Sections[i]); } } // take care of any leftover pieces if (mergedSections.Count > 0) { var mergedRect = GenerateMergedRect(mergedSections); CreateRectBody(mergedRect, createConvexHull: true); } //if the section has holes (or is just one big hole with no bodies), //we need a sensor for repairtools to be able to target the structure if (hasHoles || !Bodies.Any()) { Body sensorBody = CreateRectBody(rect, createConvexHull: false); sensorBody.CollisionCategories = Physics.CollisionRepair; sensorBody.IsSensor = true; } }
/** Remove all bodies from physics world. */ public virtual void RemoveAllBodies() { foreach (var child in Bodies) { RemoveBodyOrDelay(child); child._world = null; } Bodies.Clear(); }
public void Clear() { Bodies.Clear(); Velocities.Clear(); Contacts.Clear(); foreach (var state in ContactStates) { for (int i = 0; i < state.contactCount; i++) { ContactState.Free(state.contacts[i]); } ContactConstraintState.Free(state); // Array.Clear(state.contacts, 0, state.contactCount); } ContactStates.Clear(); }
public override void ReadData(BinaryReader stream, IDictionary <object, object> userdata, int totalSize) { UnknownFloat1 = stream.ReadSingle(); UnknownVector1 = stream.ReadVec4AsVec3(); UnknownVector2 = stream.ReadVec4AsVec3(); Usage = stream.ReadSizedString(); UnknownString = stream.ReadSizedString(); UnknownGuid = stream.ReadGuid(); int num = stream.ReadInt32(); Bodies.Clear(); Bodies.Capacity = num; for (int i = 0; i < num; i++) { var body = new Body(); body.UnknownString1 = stream.ReadSizedString(); body.UnknownBool = stream.ReadBoolean(); body.UnknownString2 = stream.ReadSizedString(); body.UnknownString3 = stream.ReadSizedString(); body.UnknownFloat1 = stream.ReadSingle(); body.UnknownVector1 = stream.ReadVec4AsVec3(); body.UnknownVector2 = stream.ReadVec4AsVec3(); body.UnknownFloat2 = stream.ReadSingle(); body.UnknownVector3 = stream.ReadVec4AsVec3(); body.UnknownVector4 = stream.ReadVec4AsVec3(); body.UnknownFloat3 = stream.ReadSingle(); body.UnknownFloat4 = stream.ReadSingle(); Bodies.Add(body); } UnknownInt = stream.ReadInt32(); num = stream.ReadInt32(); Constraints.Clear(); Constraints.Capacity = num; for (int i = 0; i < num; i++) { var version = stream.ReadUInt32(); var type = stream.ReadSizedString(); var s1 = stream.ReadSizedString(); var s2 = stream.ReadSizedString(); var s3 = stream.ReadSizedString(); var tf = stream.ReadTransform(); Constraint constraint = null; switch (type) { case HingeJointConstraint.TYPE: var hinge = new HingeJointConstraint(); hinge.UnknownFloat1 = stream.ReadSingle(); hinge.UnknownFloat2 = stream.ReadSingle(); constraint = hinge; break; case D6JointConstraint.TYPE: var d6 = new D6JointConstraint(); d6.Constraint1 = stream.ReadSizedString(); d6.Constraint2 = stream.ReadSizedString(); d6.Constraint3 = stream.ReadSizedString(); d6.Constraint4 = stream.ReadSizedString(); d6.Constraint5 = stream.ReadSizedString(); d6.Constraint6 = stream.ReadSizedString(); d6.UnknownFloat1 = stream.ReadSingle(); d6.UnknownFloat2 = stream.ReadSingle(); d6.UnknownFloat3 = stream.ReadSingle(); d6.UnknownFloat4 = stream.ReadSingle(); d6.UnknownFloat5 = stream.ReadSingle(); constraint = d6; break; case IKConstraint.TYPE: var ik = new IKConstraint(); ik.UnknownUint = stream.ReadUInt32(); ik.UnknownFloat1 = stream.ReadSingle(); ik.UnknownFloat2 = stream.ReadSingle(); ik.UnknownFloat3 = stream.ReadSingle(); ik.UnknownFloat4 = stream.ReadSingle(); constraint = ik; break; default: throw new Exception("Unknown constraint type: " + type); } constraint.UnknownString1 = s1; constraint.UnknownString2 = s2; constraint.UnknownString3 = s3; constraint.UnknownTransform = tf; Constraints.Add(constraint); } }
public override void ReadData(BinaryReader stream, IDictionary <object, object> userdata, int totalSize) { BoundingBoxPadding = stream.ReadSingle(); BoundingBoxMin = stream.ReadVec4AsVec3(); BoundingBoxMax = stream.ReadVec4AsVec3(); Usage = stream.ReadSizedString(); UnknownString = stream.ReadSizedString(); UnknownGuid = stream.ReadGuid(); int num = stream.ReadInt32(); Bodies.Clear(); Bodies.Capacity = num; for (int i = 0; i < num; i++) { var body = new Body(); body.BoneName = stream.ReadSizedString(); body.EnableBlend = stream.ReadBoolean(); body.Type = stream.ReadSizedString(); body.BodyType = stream.ReadSizedString(); body.Mass = stream.ReadSingle(); body.RagdollPosition1 = stream.ReadVec4AsVec3(); body.RagdollPosition2 = stream.ReadVec4AsVec3(); body.RagdollRadius = stream.ReadSingle(); body.CollisionPosition1 = stream.ReadVec4AsVec3(); body.CollisionPosition2 = stream.ReadVec4AsVec3(); body.CollisionRadius = stream.ReadSingle(); body.CollisionMaxRadius = stream.ReadSingle(); Bodies.Add(body); } UnknownInt = stream.ReadInt32(); num = stream.ReadInt32(); Constraints.Clear(); Constraints.Capacity = num; for (int i = 0; i < num; i++) { var version = stream.ReadUInt32(); var type = stream.ReadSizedString(); var s1 = stream.ReadSizedString(); var s2 = stream.ReadSizedString(); var s3 = stream.ReadSizedString(); var rot = stream.ReadQuat(); var pos = stream.ReadVec4AsVec3(); Constraint constraint = null; switch (type) { case HingeJointConstraint.TYPE: var hinge = new HingeJointConstraint(); hinge.UnknownFloat1 = stream.ReadSingle(); hinge.UnknownFloat2 = stream.ReadSingle(); constraint = hinge; break; case D6JointConstraint.TYPE: var d6 = new D6JointConstraint(); d6.AxisLockX = stream.ReadSizedString(); d6.AxisLockY = stream.ReadSizedString(); d6.AxisLockZ = stream.ReadSizedString(); d6.TwistLock = stream.ReadSizedString(); d6.Swing1Lock = stream.ReadSizedString(); d6.Swing2Lock = stream.ReadSizedString(); d6.AxisLimit = stream.ReadSingle(); d6.TwistLowerLimit = stream.ReadSingle(); d6.TwistUpperLimit = stream.ReadSingle(); d6.Swing1Limit = stream.ReadSingle(); d6.Swing2Limit = stream.ReadSingle(); constraint = d6; break; case IKConstraint.TYPE: var ik = new IKConstraint(); ik.UnknownUint = stream.ReadUInt32(); ik.Swing1Limit = stream.ReadSingle(); ik.Swing2Limit = stream.ReadSingle(); ik.TwistLowerLimit = stream.ReadSingle(); ik.TwistUpperLimit = stream.ReadSingle(); constraint = ik; break; default: throw new Exception("Unknown constraint type: " + type); } constraint.Name = s1; constraint.Bone1 = s2; constraint.Bone2 = s3; constraint.EntitySpaceRotation = rot; constraint.Position = pos; Constraints.Add(constraint); } }