Revert "Add physics delta states (#5116)"

This reverts commit 1189613908.
This commit is contained in:
metalgearsloth
2024-05-17 09:25:57 +10:00
committed by GitHub
parent b48ee22800
commit 3c086d87dd
3 changed files with 18 additions and 98 deletions

View File

@@ -30,7 +30,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Robust.Shared.Physics.Components;
@@ -38,11 +37,6 @@ namespace Robust.Shared.Physics.Components;
[RegisterComponent, NetworkedComponent]
public sealed partial class PhysicsComponent : Component
{
/// <summary>
/// Last time the physics component requires a full dirty
/// </summary>
public GameTick FullUpdate = GameTick.Zero;
/// <summary>
/// Has this body been added to an island previously in this tick.
/// </summary>

View File

@@ -1,12 +1,13 @@
using System;
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Robust.Shared.Physics.Components;
[Serializable, NetSerializable]
public sealed class PhysicsComponentState(
public readonly record struct PhysicsComponentState(
bool CanCollide,
bool SleepingAllowed,
bool FixedRotation,
@@ -24,35 +25,11 @@ public sealed class PhysicsComponentState(
public readonly bool FixedRotation = FixedRotation;
public readonly BodyStatus Status = Status;
public Vector2 LinearVelocity = LinearVelocity;
public float AngularVelocity = AngularVelocity;
public readonly Vector2 LinearVelocity = LinearVelocity;
public readonly float AngularVelocity = AngularVelocity;
public readonly BodyType BodyType = BodyType;
public readonly float Friction = Friction;
public readonly float LinearDamping = LinearDamping;
public readonly float AngularDamping = AngularDamping;
}
[Serializable, NetSerializable]
public sealed class PhysicsDeltaState : IComponentState, IComponentDeltaState
{
public Vector2 LinearVelocity;
public float AngularVelocity;
public bool FullState => false;
public void ApplyToFullState(IComponentState fullState)
{
var state = (PhysicsComponentState)fullState;
state.LinearVelocity = LinearVelocity;
state.AngularVelocity = AngularVelocity;
}
public IComponentState CreateNewFullState(IComponentState fullState)
{
var state = (PhysicsComponentState) fullState;
return new PhysicsComponentState(state.CanCollide, state.SleepingAllowed, state.FixedRotation, state.Status,
LinearVelocity, AngularVelocity, state.BodyType, state.Friction, state.LinearDamping, state.AngularDamping);
}
}

View File

@@ -69,38 +69,21 @@ public partial class SharedPhysicsSystem
private void OnPhysicsGetState(EntityUid uid, PhysicsComponent component, ref ComponentGetState args)
{
if (args.FromTick <= component.FullUpdate)
{
args.State = new PhysicsComponentState(
component.CanCollide,
component.SleepingAllowed,
component.FixedRotation,
component.BodyStatus,
component.LinearVelocity,
component.AngularVelocity,
component.BodyType,
component._friction,
component.LinearDamping,
component.AngularDamping);
return;
}
args.State = new PhysicsDeltaState()
{
LinearVelocity = component.LinearVelocity,
AngularVelocity = component.AngularVelocity,
};
args.State = new PhysicsComponentState(
component.CanCollide,
component.SleepingAllowed,
component.FixedRotation,
component.BodyStatus,
component.LinearVelocity,
component.AngularVelocity,
component.BodyType,
component._friction,
component.LinearDamping,
component.AngularDamping);
}
private void OnPhysicsHandleState(EntityUid uid, PhysicsComponent component, ref ComponentHandleState args)
{
if (args.Current is PhysicsDeltaState delta)
{
component.LinearVelocity = delta.LinearVelocity;
component.AngularVelocity = delta.AngularVelocity;
return;
}
if (args.Current is not PhysicsComponentState newState)
return;
@@ -111,7 +94,7 @@ public partial class SharedPhysicsSystem
// So transform doesn't apply MapId in the HandleComponentState because ??? so MapId can still be 0.
// Fucking kill me, please. You have no idea deep the rabbit hole of shitcode goes to make this work.
_fixturesQuery.TryComp(uid, out var manager);
TryComp<FixturesComponent>(uid, out var manager);
SetLinearVelocity(uid, newState.LinearVelocity, body: component, manager: manager);
SetAngularVelocity(uid, newState.AngularVelocity, body: component, manager: manager);
@@ -295,7 +278,6 @@ public partial class SharedPhysicsSystem
if (((int) body.BodyType & (int) (BodyType.Kinematic | BodyType.Static)) != 0)
{
body._localCenter = Vector2.Zero;
FullDirty((uid, body));
Dirty(uid, body);
return;
}
@@ -331,7 +313,6 @@ public partial class SharedPhysicsSystem
// Update center of mass velocity.
body.LinearVelocity += Vector2Helpers.Cross(body.AngularVelocity, localCenter - oldCenter);
FullDirty((uid, body));
Dirty(uid, body);
}
@@ -358,9 +339,7 @@ public partial class SharedPhysicsSystem
body.AngularVelocity = value;
if (dirty)
{
Dirty(uid, body);
}
return true;
}
@@ -388,9 +367,7 @@ public partial class SharedPhysicsSystem
body.LinearVelocity = velocity;
if (dirty)
{
Dirty(uid, body);
}
return true;
}
@@ -403,10 +380,7 @@ public partial class SharedPhysicsSystem
body.AngularDamping = value;
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
[Obsolete("Use overload that takes EntityUid")]
@@ -423,10 +397,7 @@ public partial class SharedPhysicsSystem
body.LinearDamping = value;
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
[Obsolete("Use overload that takes EntityUid")]
@@ -471,7 +442,7 @@ public partial class SharedPhysicsSystem
// Update wake system last, if sleeping but still colliding.
if (!value && body.CanCollide)
_wakeSystem.UpdateCanCollide(ent, checkTerminating: false);
_wakeSystem.UpdateCanCollide(ent, checkTerminating: false, dirty: false);
if (updateSleepTime)
SetSleepTime(body, 0);
@@ -484,6 +455,7 @@ public partial class SharedPhysicsSystem
}
UpdateMapAwakeState(uid, body);
Dirty(ent);
}
public void TrySetBodyType(EntityUid uid, BodyType value, FixturesComponent? manager = null, PhysicsComponent? body = null, TransformComponent? xform = null)
@@ -540,10 +512,7 @@ public partial class SharedPhysicsSystem
body.BodyStatus = status;
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
[Obsolete("Use overload that takes EntityUid")]
@@ -602,10 +571,7 @@ public partial class SharedPhysicsSystem
}
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
return value;
}
@@ -620,10 +586,7 @@ public partial class SharedPhysicsSystem
ResetMassData(uid, manager: manager, body: body);
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
public void SetFriction(EntityUid uid, PhysicsComponent body, float value, bool dirty = true)
@@ -634,10 +597,7 @@ public partial class SharedPhysicsSystem
body._friction = value;
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
[Obsolete("Use overload that takes EntityUid")]
@@ -661,10 +621,7 @@ public partial class SharedPhysicsSystem
body.InvI = 1.0f / body._inertia;
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
}
@@ -694,10 +651,7 @@ public partial class SharedPhysicsSystem
body.SleepingAllowed = value;
if (dirty)
{
FullDirty((uid, body));
Dirty(uid, body);
}
}
public void SetSleepTime(PhysicsComponent body, float value)
@@ -820,9 +774,4 @@ public partial class SharedPhysicsSystem
{
// See client-side system
}
private void FullDirty(Entity<PhysicsComponent> entity)
{
entity.Comp.FullUpdate = _gameTiming.CurTick;
}
}