Refactored Ghost Entities
Game Context was creating an empty OrbitalEntity for every planet; this was an ugly hack so I refactored it, as well as refactoring some object references to GUIDs as they should be
This commit is contained in:
parent
35fb4381ed
commit
4f29bf24d0
13 changed files with 199 additions and 191 deletions
|
|
@ -10,8 +10,10 @@ using Unity.Mathematics;
|
|||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject,
|
||||
Union(0, typeof(Ship)),
|
||||
Union(1, typeof(OrbitalEntity)),
|
||||
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<Entity>))]
|
||||
public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
|
||||
public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
|
||||
{
|
||||
[IgnoreMember] public Dictionary<IAnalogBehavior, float> AxisOverrides = new Dictionary<IAnalogBehavior, float>();
|
||||
[IgnoreMember] public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
|
||||
|
|
@ -24,6 +26,9 @@ public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
|
|||
[IgnoreMember] public Dictionary<IAnalogBehavior, float> Axes;
|
||||
public readonly List<ItemInstance> Cargo;
|
||||
public readonly List<Gear> EquippedItems;
|
||||
public Entity Parent;
|
||||
public List<Entity> Children = new List<Entity>();
|
||||
public Guid Zone;
|
||||
|
||||
[IgnoreMember] protected List<IBehavior> Behaviors;
|
||||
|
||||
|
|
@ -37,6 +42,7 @@ public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
|
|||
|
||||
public Entity(GameContext context, Gear hull, IEnumerable<Gear> items, IEnumerable<ItemInstance> cargo)
|
||||
{
|
||||
ID = Guid.NewGuid();
|
||||
Context = context;
|
||||
|
||||
EquippedItems = items.ToList();
|
||||
|
|
@ -72,7 +78,8 @@ public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
|
|||
{
|
||||
Mass = Hull?.Mass ?? 0 +
|
||||
EquippedItems.Sum(i => i.Mass) +
|
||||
Cargo.Sum(ii => ii.Mass);
|
||||
Cargo.Sum(ii => ii.Mass) +
|
||||
Children.Sum(c=>c.Mass);
|
||||
|
||||
SpecificHeat = (Hull?.HeatCapacity ?? 0) +
|
||||
EquippedItems.Sum(i => i.HeatCapacity) +
|
||||
|
|
@ -108,6 +115,12 @@ public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
|
|||
|
||||
foreach (var item in EquippedItems.Where(item => item.ItemData.Performance(Temperature) < .01f))
|
||||
item.Durability -= delta;
|
||||
|
||||
if (Parent != null)
|
||||
{
|
||||
Position = Parent.Position;
|
||||
Velocity = Parent.Velocity;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
|
|
|
|||
Loading…
Reference in a new issue