using System.Collections.Generic; using Global.Shared.API; using Global.Shared.Plugin; using Sandbox.Game.Entities; using Sandbox.Game.Entities.Character; using VRage.Game.Components; using VRageMath; namespace Global.Shared.OcTree.Data { public class ControllableEntityData : IControllableEntityData, IOcTreeData { public ControllableEntityData(IMyControllableEntity entity) { Entity = entity; Id = entity.Entity.EntityId; Recompute(); entity.Entity.PositionComp.OnPositionChanged += PositionChanged; } public IMyControllableEntity Entity { get; set; } public long Id { get; } public List ChildIds { get; } = new List(); public long Flags { get; private set; } public BoundingBoxD BoundingBox { get; private set; } public void Recompute() { Flags = PlayerFlag.None; Flags |= Entity is MyCharacter ? PlayerFlag.Character : PlayerFlag.Controlled; BoundingBox = Entity.Entity.PositionComp.WorldAABB; } public void Update() { Recompute(); } public void Dispose() { Entity.Entity.PositionComp.OnPositionChanged -= PositionChanged; Entity = null; BoundingBox = default; } private void PositionChanged(MyPositionComponentBase obj) { GlobalStatic.OcTreeHandler.CharacterTree.Update(Id); } } }