Files
QuartZ-dump/GlobalTorch/Overwrites/MyEntitiesButBetter.cs
2024-12-29 21:15:58 +01:00

366 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRageMath;
namespace Global
{
public class MyEntitiesButBetter : IMyEntities
{
private readonly List<IMyEntity> _entities = new List<IMyEntity>();
private readonly List<long> _entityIds = new List<long>();
private readonly IMyEntities m_entities;
public MyEntitiesButBetter(IMyEntities mEntities)
{
m_entities = mEntities;
}
public bool TryGetEntityById(long id, out IMyEntity entity)
{
return m_entities.TryGetEntityById(id, out entity);
}
public bool TryGetEntityById(long? id, out IMyEntity entity)
{
return m_entities.TryGetEntityById(id, out entity);
}
public bool TryGetEntityByName(string name, out IMyEntity entity)
{
return m_entities.TryGetEntityByName(name, out entity);
}
public bool EntityExists(string name)
{
return m_entities.EntityExists(name);
}
public void AddEntity(IMyEntity entity, bool insertIntoScene = true)
{
m_entities.AddEntity(entity, insertIntoScene);
}
public IMyEntity CreateFromObjectBuilder(MyObjectBuilder_EntityBase objectBuilder)
{
return m_entities.CreateFromObjectBuilder(objectBuilder);
}
public IMyEntity CreateFromObjectBuilderAndAdd(MyObjectBuilder_EntityBase objectBuilder)
{
return m_entities.CreateFromObjectBuilderAndAdd(objectBuilder);
}
public void RemoveEntity(IMyEntity entity)
{
m_entities.RemoveEntity(entity);
}
public bool IsSpherePenetrating(ref BoundingSphereD bs)
{
return m_entities.IsSpherePenetrating(ref bs);
}
public Vector3D? FindFreePlace(Vector3D basePos, float radius, int maxTestCount = 20, int testsPerDistance = 5,
float stepSize = 1)
{
return m_entities.FindFreePlace(basePos, radius, maxTestCount, testsPerDistance, stepSize);
}
public void GetInflatedPlayerBoundingBox(ref BoundingBox playerBox, float inflation)
{
m_entities.GetInflatedPlayerBoundingBox(ref playerBox, inflation);
}
public void GetInflatedPlayerBoundingBox(ref BoundingBoxD playerBox, float inflation)
{
m_entities.GetInflatedPlayerBoundingBox(ref playerBox, inflation);
}
public bool IsInsideVoxel(Vector3 pos, Vector3 hintPosition, out Vector3 lastOutsidePos)
{
return m_entities.IsInsideVoxel(pos, hintPosition, out lastOutsidePos);
}
public bool IsInsideVoxel(Vector3D pos, Vector3D hintPosition, out Vector3D lastOutsidePos)
{
return m_entities.IsInsideVoxel(pos, hintPosition, out lastOutsidePos);
}
public bool IsWorldLimited()
{
return m_entities.IsWorldLimited();
}
public float WorldHalfExtent()
{
return m_entities.WorldHalfExtent();
}
public float WorldSafeHalfExtent()
{
return m_entities.WorldSafeHalfExtent();
}
public bool IsInsideWorld(Vector3D pos)
{
return m_entities.IsInsideWorld(pos);
}
public bool IsRaycastBlocked(Vector3D pos, Vector3D target)
{
return m_entities.IsRaycastBlocked(pos, target);
}
public void SetEntityName(IMyEntity IMyEntity, bool possibleRename = true)
{
m_entities.SetEntityName(IMyEntity, possibleRename);
}
public bool IsNameExists(IMyEntity entity, string name)
{
return m_entities.IsNameExists(entity, name);
}
public void RemoveFromClosedEntities(IMyEntity entity)
{
m_entities.RemoveFromClosedEntities(entity);
}
public void RemoveName(IMyEntity entity)
{
m_entities.RemoveName(entity);
}
public bool Exist(IMyEntity entity)
{
return m_entities.Exist(entity);
}
public void MarkForClose(IMyEntity entity)
{
m_entities.MarkForClose(entity);
}
public void RegisterForUpdate(IMyEntity entity)
{
m_entities.RegisterForUpdate(entity);
}
public void RegisterForDraw(IMyEntity entity)
{
m_entities.RegisterForDraw(entity);
}
public void UnregisterForUpdate(IMyEntity entity, bool immediate = false)
{
m_entities.UnregisterForUpdate(entity, immediate);
}
public void UnregisterForDraw(IMyEntity entity)
{
m_entities.UnregisterForDraw(entity);
}
public IMyEntity GetIntersectionWithSphere(ref BoundingSphereD sphere)
{
return m_entities.GetIntersectionWithSphere(ref sphere);
}
public IMyEntity GetIntersectionWithSphere(ref BoundingSphereD sphere, IMyEntity ignoreEntity0,
IMyEntity ignoreEntity1)
{
return m_entities.GetIntersectionWithSphere(ref sphere, ignoreEntity0, ignoreEntity1);
}
public IMyEntity GetIntersectionWithSphere(ref BoundingSphereD sphere, IMyEntity ignoreEntity0,
IMyEntity ignoreEntity1,
bool ignoreVoxelMaps, bool volumetricTest, bool excludeEntitiesWithDisabledPhysics = false,
bool ignoreFloatingObjects = true, bool ignoreHandWeapons = true)
{
return m_entities.GetIntersectionWithSphere(
ref sphere, ignoreEntity0, ignoreEntity1, ignoreVoxelMaps, volumetricTest,
excludeEntitiesWithDisabledPhysics, ignoreFloatingObjects, ignoreHandWeapons);
}
public IMyEntity GetEntityById(long entityId)
{
return m_entities.GetEntityById(entityId);
}
public IMyEntity GetEntityById(long? entityId)
{
return m_entities.GetEntityById(entityId);
}
public bool EntityExists(long entityId)
{
return m_entities.EntityExists(entityId);
}
public bool EntityExists(long? entityId)
{
return m_entities.EntityExists(entityId);
}
public IMyEntity GetEntityByName(string name)
{
return m_entities.GetEntityByName(name);
}
public void SetTypeHidden(Type type, bool hidden)
{
m_entities.SetTypeHidden(type, hidden);
}
public bool IsTypeHidden(Type type)
{
return m_entities.IsTypeHidden(type);
}
public bool IsVisible(IMyEntity entity)
{
return m_entities.IsVisible(entity);
}
public void UnhideAllTypes()
{
m_entities.UnhideAllTypes();
}
public void RemapObjectBuilderCollection(IEnumerable<MyObjectBuilder_EntityBase> objectBuilders)
{
m_entities.RemapObjectBuilderCollection(objectBuilders);
}
public void RemapObjectBuilder(MyObjectBuilder_EntityBase objectBuilder)
{
m_entities.RemapObjectBuilder(objectBuilder);
}
public IMyEntity CreateFromObjectBuilderNoinit(MyObjectBuilder_EntityBase objectBuilder)
{
return m_entities.CreateFromObjectBuilderNoinit(objectBuilder);
}
public void EnableEntityBoundingBoxDraw(IMyEntity entity, bool enable, Vector4? color = null,
float lineWidth = 0.01f,
Vector3? inflateAmount = null)
{
m_entities.EnableEntityBoundingBoxDraw(entity, enable, color, lineWidth, inflateAmount);
}
public IMyEntity GetEntity(Func<IMyEntity, bool> match)
{
return m_entities.GetEntity(match);
}
public void GetEntities(HashSet<IMyEntity> entities, Func<IMyEntity, bool> collect = null)
{
m_entities.GetEntities(entities, collect);
}
public List<IMyEntity> GetIntersectionWithSphere(ref BoundingSphereD sphere, IMyEntity ignoreEntity0,
IMyEntity ignoreEntity1,
bool ignoreVoxelMaps, bool volumetricTest)
{
return m_entities.GetIntersectionWithSphere(ref sphere,
ignoreEntity0, ignoreEntity1, ignoreVoxelMaps, volumetricTest);
}
public List<IMyEntity> GetEntitiesInAABB(ref BoundingBoxD boundingBox)
{
return m_entities.GetEntitiesInAABB(ref boundingBox);
}
// public List<IMyEntity> GetEntitiesInSphere(ref BoundingSphereD boundingSphere)
// {
// var ents = MyGlobalGateway.OcTreeManager.GridTree.GetExact(_entityIds, boundingSphere);
// foreach (var ent in ents) _entities.Add(GetEntityById(ent));
// ents.Clear();
// return _entities;
// }
public List<IMyEntity> GetElementsInBox(ref BoundingBoxD boundingBox)
{
return m_entities.GetElementsInBox(ref boundingBox);
}
// public List<IMyEntity> GetTopMostEntitiesInSphere(ref BoundingSphereD boundingSphere)
// {
// var ents = MyGlobalGateway.OcTreeManager.GridTree.GetExact(_entityIds, boundingSphere);
// foreach (var ent in ents) _entities.Add(GetEntityById(ent));
// ents.Clear();
// ents = MyGlobalGateway.OcTreeManager.CharacterTree.GetExact(_entityIds, boundingSphere);
// foreach (var ent in ents) _entities.Add(GetEntityById(ent));
// ents.Clear();
// return _entities;
// }
//
// public List<IMyEntity> GetTopMostEntitiesInBox(ref BoundingBoxD boundingBox)
// {
// var ents = MyGlobalGateway.OcTreeManager.GridTree.GetExact(_entityIds, boundingBox);
// foreach (var ent in ents) _entities.Add(GetEntityById(ent));
// ents.Clear();
// ents = MyGlobalGateway.OcTreeManager.CharacterTree.GetExact(_entityIds, boundingBox);
// foreach (var ent in ents) _entities.Add(GetEntityById(ent));
// ents.Clear();
// return _entities;
// }
//TODO: Replace with OcTree
public List<IMyEntity> GetEntitiesInSphere(ref BoundingSphereD boundingSphere)
{
return m_entities.GetEntitiesInSphere(ref boundingSphere);
}
public List<IMyEntity> GetTopMostEntitiesInSphere(ref BoundingSphereD boundingSphere)
{
return m_entities.GetTopMostEntitiesInSphere(ref boundingSphere);
}
public List<IMyEntity> GetTopMostEntitiesInBox(ref BoundingBoxD boundingBox)
{
return m_entities.GetTopMostEntitiesInBox(ref boundingBox);
}
public IMyEntity CreateFromObjectBuilderParallel(MyObjectBuilder_EntityBase objectBuilder,
bool addToScene = false,
Action<IMyEntity> completionCallback = null)
{
return m_entities.CreateFromObjectBuilderParallel(objectBuilder, addToScene, completionCallback);
}
event Action<IMyEntity> IMyEntities.OnEntityRemove
{
add => m_entities.OnEntityRemove += value;
remove => m_entities.OnEntityRemove -= value;
}
event Action<IMyEntity> IMyEntities.OnEntityAdd
{
add => m_entities.OnEntityAdd += value;
remove => m_entities.OnEntityAdd -= value;
}
event Action IMyEntities.OnCloseAll
{
add => m_entities.OnCloseAll += value;
remove => m_entities.OnCloseAll -= value;
}
event Action<IMyEntity, string, string> IMyEntities.OnEntityNameSet
{
add => customEventDef += value;
remove => customEventDef -= value;
}
private static event Action<IMyEntity, string, string> customEventDef;
public static void CallRename(IMyEntity entity, string oldName, string newName)
{
customEventDef?.Invoke(entity, oldName, newName);
}
}
}