mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-03 10:37:05 +02:00
Code was changed so that time starts at tick zero, and all entities are initialized in the space between tick 0 to 1. This was a solution to the fact fromSequence was including entities with lastStateUpdate tick one less than the actual sequence number. This is purely an issue about when exactly the game does its logic relative to the tick signals, ie positive or negative edge of the tick. Right now the game is set up to run the game logic on the positive edge of a Tick (enforced by GameLoop). The second big part is that an empty collection takes 5ish bytes more than a null collection in the NetSerializer, even though they are conceptually the same thing in a game state. This PR puts null checks around everything and allows GameStates to have whole sections of itself null. This reduced the payload size of an empty game state from 49B to 15B. This PR also fixes the bug where the physics system marks every movable entity as dirty every tick.
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
/// <summary>
|
|
/// Contains physical properties of the entity. This component registers the entity
|
|
/// in the physics system as a dynamic ridged body object that has physics. This behavior overrides
|
|
/// the BoundingBoxComponent behavior of making the entity static.
|
|
/// </summary>
|
|
internal class PhysicsComponent : Component
|
|
{
|
|
/// <inheritdoc />
|
|
public override string Name => "Physics";
|
|
|
|
/// <inheritdoc />
|
|
public override uint? NetID => NetIDs.PHYSICS;
|
|
|
|
/// <inheritdoc />
|
|
public override Type StateType => typeof(PhysicsComponentState);
|
|
|
|
/// <summary>
|
|
/// Current mass of the entity in kg.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public float Mass { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Current velocity of the entity.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public Vector2 Velocity { get; private set; }
|
|
|
|
/// <inheritdoc />
|
|
public override void Initialize()
|
|
{
|
|
// This component requires that the entity has an AABB.
|
|
if (!Owner.HasComponent<BoundingBoxComponent>())
|
|
Logger.Error($"[ECS] {Owner.Prototype.Name} - {nameof(PhysicsComponent)} requires {nameof(BoundingBoxComponent)}. ");
|
|
|
|
base.Initialize();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
|
{
|
|
if (curState == null)
|
|
return;
|
|
|
|
var newState = (PhysicsComponentState)curState;
|
|
Mass = newState.Mass / 1000f; // gram to kilogram
|
|
Velocity = newState.Velocity;
|
|
}
|
|
}
|
|
}
|