encompass-cs/encompass-cs/Engine.cs

611 lines
27 KiB
C#
Raw Normal View History

2019-12-16 10:17:39 +00:00
using System;
2019-06-15 07:39:08 +00:00
using System.Reflection;
2019-06-15 00:51:06 +00:00
using System.Collections.Generic;
2019-06-17 01:11:35 +00:00
using System.Linq;
using Encompass.Exceptions;
2019-06-15 00:51:06 +00:00
2019-06-16 01:05:56 +00:00
namespace Encompass
{
/// <summary>
/// Engines are the Encompass notion of an ECS System.
/// They are responsible for reading the World state, reading messages, emitting messages, and creating or mutating Entities and Components.
/// Engines run once per World Update.
/// </summary>
public abstract class Engine : IEquatable<Engine>
2019-06-16 01:05:56 +00:00
{
2019-11-21 03:01:29 +00:00
internal Guid ID;
2019-12-06 03:55:17 +00:00
internal readonly HashSet<Type> readTypes = new HashSet<Type>();
internal readonly HashSet<Type> readPendingTypes = new HashSet<Type>();
2019-07-19 01:20:38 +00:00
internal readonly HashSet<Type> sendTypes = new HashSet<Type>();
2019-07-19 19:47:17 +00:00
internal readonly HashSet<Type> receiveTypes = new HashSet<Type>();
2019-12-06 03:55:17 +00:00
internal readonly HashSet<Type> writeTypes = new HashSet<Type>();
internal readonly HashSet<Type> writePendingTypes = new HashSet<Type>();
internal readonly Dictionary<Type, int> writePriorities = new Dictionary<Type, int>();
internal readonly int defaultWritePriority = 0;
2019-06-15 07:39:08 +00:00
/// <summary>
2019-12-05 20:10:33 +00:00
/// If false, the Engine will ignore time dilation.
/// </summary>
internal bool usesTimeDilation = true;
public bool TimeDilationActive { get => usesTimeDilation && timeManager.TimeDilationActive; }
2019-06-15 00:51:06 +00:00
private EntityManager entityManager;
2019-06-16 01:55:35 +00:00
private MessageManager messageManager;
private ComponentManager componentManager;
private ComponentUpdateManager componentUpdateManager;
private TimeManager timeManager;
2019-06-15 00:51:06 +00:00
2019-06-20 17:46:15 +00:00
protected Engine()
2019-06-16 01:05:56 +00:00
{
ID = Guid.NewGuid();
2019-07-19 19:47:17 +00:00
var sendsAttribute = GetType().GetCustomAttribute<Sends>(false);
if (sendsAttribute != null)
2019-06-16 01:55:35 +00:00
{
2019-07-19 19:47:17 +00:00
sendTypes = sendsAttribute.sendTypes;
}
var activatesAttribute = GetType().GetCustomAttribute<WritesPending>(false);
2019-07-19 19:47:17 +00:00
if (activatesAttribute != null)
{
2019-12-06 03:55:17 +00:00
writePendingTypes = activatesAttribute.writePendingTypes;
2019-07-19 19:47:17 +00:00
}
var defaultWritePriorityAttribute = GetType().GetCustomAttribute<DefaultWritePriority>(false);
if (defaultWritePriorityAttribute != null)
{
defaultWritePriority = defaultWritePriorityAttribute.writePriority;
}
2019-12-06 03:55:17 +00:00
foreach (var writesAttribute in GetType().GetCustomAttributes<Writes>(false))
2019-07-20 00:50:13 +00:00
{
2019-12-06 03:55:17 +00:00
writeTypes.UnionWith(writesAttribute.writeTypes);
writePriorities = new Dictionary<Type, int>[2] { writePriorities, writesAttribute.priorities }.SelectMany(dict => dict).ToDictionary(pair => pair.Key, pair => pair.Value);
2019-07-20 00:50:13 +00:00
}
2019-07-19 19:47:17 +00:00
var receivesAttribute = GetType().GetCustomAttribute<Receives>(false);
if (receivesAttribute != null)
{
receiveTypes = receivesAttribute.receiveTypes;
2019-06-16 01:55:35 +00:00
}
2019-06-20 03:37:46 +00:00
var readsAttribute = GetType().GetCustomAttribute<Reads>(false);
2019-06-16 01:55:35 +00:00
if (readsAttribute != null)
{
2019-12-06 03:55:17 +00:00
readTypes = readsAttribute.readTypes;
2019-06-16 01:55:35 +00:00
}
2019-07-23 17:17:53 +00:00
var readsPendingAttribute = GetType().GetCustomAttribute<ReadsPending>(false);
if (readsPendingAttribute != null)
{
2019-12-06 03:55:17 +00:00
readPendingTypes = readsPendingAttribute.readPendingTypes;
2019-07-23 17:17:53 +00:00
}
2019-06-15 07:39:08 +00:00
}
public override bool Equals(object obj)
{
if (obj is Engine engine)
{
return Equals(engine);
}
return false;
}
public bool Equals(Engine other)
{
return other.ID == ID;
}
public override int GetHashCode()
{
return ID.GetHashCode();
}
2019-06-16 01:05:56 +00:00
internal void AssignEntityManager(EntityManager entityManager)
{
2019-06-15 00:51:06 +00:00
this.entityManager = entityManager;
}
2019-06-16 01:05:56 +00:00
internal void AssignComponentManager(ComponentManager componentManager)
{
2019-06-15 00:51:06 +00:00
this.componentManager = componentManager;
}
2019-06-16 01:55:35 +00:00
internal void AssignMessageManager(MessageManager messageManager)
{
this.messageManager = messageManager;
}
internal void AssignComponentUpdateManager(ComponentUpdateManager componentUpdateManager)
2019-08-01 23:24:57 +00:00
{
this.componentUpdateManager = componentUpdateManager;
2019-08-01 23:24:57 +00:00
}
internal void AssignTimeManager(TimeManager timeManager)
{
this.timeManager = timeManager;
}
/// <summary>
/// Runs once per World update with the calculated delta-time.
/// </summary>
/// <param name="dt">The time in seconds that has elapsed since the previous frame.</param>
public abstract void Update(double dt);
2019-06-15 00:51:06 +00:00
/// <summary>
/// Creates and returns a new empty Entity.
/// </summary>
2019-06-16 01:05:56 +00:00
protected Entity CreateEntity()
{
2019-06-20 03:37:46 +00:00
return entityManager.CreateEntity();
}
/// <summary>
/// Returns true if an Entity with the specified ID exists.
/// </summary>
protected bool EntityExists(Entity entity)
{
return entityManager.EntityExists(entity.ID);
}
/// <summary>
/// Returns an Entity containing the specified Component type.
/// </summary>
protected Entity ReadEntity<TComponent>() where TComponent : struct, IComponent
{
2019-12-05 20:10:33 +00:00
return ReadComponentHelper<TComponent>().Item1;
}
/// <summary>
/// Returns all Entities containing the specified Component type.
/// </summary>
protected IEnumerable<Entity> ReadEntities<TComponent>() where TComponent : struct, IComponent
{
2019-12-05 20:10:33 +00:00
return ReadComponentsHelper<TComponent>().Select(pair => pair.Item1);
}
// these next two are for the ComponentMessageEmitter only
2019-08-20 02:05:18 +00:00
2019-12-05 20:10:33 +00:00
internal IEnumerable<TComponent> ReadComponentsFromWorld<TComponent>() where TComponent : struct, IComponent
2019-06-16 01:05:56 +00:00
{
2019-08-01 23:44:29 +00:00
return componentManager.GetComponentsByType<TComponent>();
2019-06-15 00:51:06 +00:00
}
2019-06-15 07:39:08 +00:00
2019-12-05 20:10:33 +00:00
private IEnumerable<(Entity, TComponent)> ReadComponentsHelper<TComponent>() where TComponent : struct, IComponent
{
2019-12-06 03:55:17 +00:00
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && pendingRead)
{
return componentUpdateManager.ReadExistingAndPendingComponentsByType<TComponent>();
}
2019-07-23 17:17:53 +00:00
else if (existingRead)
{
return componentUpdateManager.ReadExistingComponentsByType<TComponent>();
2019-07-23 17:17:53 +00:00
}
else if (pendingRead)
{
return componentUpdateManager.ReadPendingComponentsByType<TComponent>();
2019-07-23 17:17:53 +00:00
}
else
2019-07-18 21:02:57 +00:00
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
}
}
2019-07-18 21:02:57 +00:00
/// <summary>
2019-11-21 03:01:29 +00:00
/// Returns all of the Components with the specified Component Type.
/// </summary>
2019-11-21 03:01:29 +00:00
protected IEnumerable<TComponent> ReadComponents<TComponent>() where TComponent : struct, IComponent
{
2019-11-21 03:01:29 +00:00
return ReadComponentsHelper<TComponent>().Select(tuple => tuple.Item2);
}
/// <summary>
2019-11-21 03:01:29 +00:00
/// Returns all of the components of the specified type including an Entity reference for each Component.
/// </summary>
2019-11-21 03:01:29 +00:00
protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent
{
2019-12-05 20:10:33 +00:00
return ReadComponentsHelper<TComponent>().Select((tuple) => (tuple.Item2, tuple.Item1));
2019-11-21 03:01:29 +00:00
}
2019-12-05 22:59:55 +00:00
internal IEnumerable<(TComponent, Entity)> InternalRead<TComponent>() where TComponent : struct, IComponent
{
return componentManager.GetComponentsIncludingEntity<TComponent>();
}
2019-12-05 20:10:33 +00:00
private (Entity, TComponent) ReadComponentHelper<TComponent>() where TComponent : struct, IComponent
{
2019-12-06 03:55:17 +00:00
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
2019-08-01 23:24:57 +00:00
if (existingRead && pendingRead)
{
return componentUpdateManager.ReadFirstExistingOrPendingComponentByType<TComponent>();
2019-08-01 23:24:57 +00:00
}
else if (existingRead)
{
return componentUpdateManager.ReadFirstExistingComponentByType<TComponent>();
2019-08-01 23:24:57 +00:00
}
else if (pendingRead)
{
return componentUpdateManager.ReadFirstPendingComponentByType<TComponent>();
2019-08-01 23:24:57 +00:00
}
else
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
}
2019-07-19 19:47:17 +00:00
}
2019-11-21 03:01:29 +00:00
/// <summary>
/// Returns a Component with the specified Component Type. If multiples exist, an arbitrary Component is returned.
/// </summary>
protected TComponent ReadComponent<TComponent>() where TComponent : struct, IComponent
{
return ReadComponentHelper<TComponent>().Item2;
}
/// <summary>
/// Returns a component of the specified type including its Entity reference. If multiples exist, an arbitrary Component is returned.
/// </summary>
2019-11-21 03:01:29 +00:00
protected (TComponent, Entity) ReadComponentIncludingEntity<TComponent>() where TComponent : struct, IComponent
{
2019-12-05 20:10:33 +00:00
var (entity, component) = ReadComponentHelper<TComponent>();
return (component, entity);
}
/// <summary>
/// Returns true if any Component with the specified Component Type exists.
/// </summary>
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
2019-07-19 19:47:17 +00:00
{
2019-12-06 03:55:17 +00:00
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
2019-08-01 23:24:57 +00:00
if (existingRead && pendingRead)
{
return componentUpdateManager.SomeExistingOrPendingComponent<TComponent>();
2019-08-01 23:24:57 +00:00
}
else if (existingRead)
{
return componentUpdateManager.SomeExistingComponent<TComponent>();
2019-08-01 23:24:57 +00:00
}
else if (pendingRead)
{
return componentUpdateManager.SomePendingComponent<TComponent>();
2019-08-01 23:24:57 +00:00
}
else
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
}
2019-07-19 19:47:17 +00:00
}
2019-12-05 20:10:33 +00:00
private TComponent GetComponentHelper<TComponent>(Entity entity) where TComponent : struct, IComponent
2019-07-17 18:24:21 +00:00
{
2019-12-06 03:55:17 +00:00
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
2019-08-01 23:24:57 +00:00
if (existingRead && pendingRead)
{
if (componentUpdateManager.HasPendingComponent<TComponent>(entity))
{
return componentUpdateManager.ReadPendingComponentByEntityAndType<TComponent>(entity);
}
else if (componentUpdateManager.HasExistingComponent<TComponent>(entity))
{
return componentUpdateManager.ReadExistingComponentByEntityAndType<TComponent>(entity);
}
else
{
throw new NoComponentOfTypeOnEntityException("No Component of type {0} exists on Entity {1}", typeof(TComponent).Name, entity.ID);
}
2019-08-01 23:24:57 +00:00
}
else if (existingRead)
{
return componentUpdateManager.ReadExistingComponentByEntityAndType<TComponent>(entity);
2019-08-01 23:24:57 +00:00
}
else if (pendingRead)
{
return componentUpdateManager.ReadPendingComponentByEntityAndType<TComponent>(entity);
2019-08-01 23:24:57 +00:00
}
else
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
}
2019-07-17 18:24:21 +00:00
}
2019-11-13 21:24:20 +00:00
/// <summary>
/// Returns a Component with the specified Type that exists on the Entity.
/// </summary>
/// <exception cref="Encompass.Exceptions.NoComponentOfTypeOnEntityException">
/// Thrown when the Entity does not have a Component of the specified Type
/// </exception>
/// <exception cref="Encompass.Exceptions.IllegalReadException">
/// Thrown when the Engine does not declare that it reads the given Component Type.
/// </exception>
2019-11-21 03:01:29 +00:00
protected TComponent GetComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
2019-12-05 20:10:33 +00:00
return GetComponentHelper<TComponent>(entity);
2019-11-21 03:01:29 +00:00
}
/// <summary>
/// Returns true if the Entity has a Component of the given Type.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalReadException">
/// Thrown when the Engine does not declare that is Reads the given Component Type.
/// </exception>
2019-07-17 18:24:21 +00:00
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
2019-12-06 03:55:17 +00:00
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
2019-08-01 23:24:57 +00:00
if (pendingRead && existingRead)
{
return componentUpdateManager.HasExistingOrPendingComponent<TComponent>(entity);
2019-08-01 23:24:57 +00:00
}
else if (existingRead)
{
return componentUpdateManager.HasExistingComponent<TComponent>(entity);
2019-08-01 23:24:57 +00:00
}
else if (pendingRead)
{
return componentUpdateManager.HasPendingComponent<TComponent>(entity);
2019-08-01 23:24:57 +00:00
}
else
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
}
2019-07-17 18:24:21 +00:00
}
2019-11-13 21:15:43 +00:00
/// <summary>
/// Returns true if the Entity has a Component of the given Type.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalReadException">
/// Thrown when the Engine does not declare that is Reads the given Component Type.
/// </exception>
protected bool HasComponent(Entity entity, Type type)
{
2019-12-06 03:55:17 +00:00
var pendingRead = readPendingTypes.Contains(type);
var existingRead = readTypes.Contains(type);
2019-11-13 21:15:43 +00:00
if (pendingRead && existingRead)
{
return componentUpdateManager.HasExistingOrPendingComponent(entity, type);
2019-11-13 21:15:43 +00:00
}
else if (existingRead)
{
return componentUpdateManager.HasExistingComponent(entity, type);
2019-11-13 21:15:43 +00:00
}
else if (pendingRead)
{
return componentUpdateManager.HasPendingComponent(entity, type);
2019-11-13 21:15:43 +00:00
}
else
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, type.Name);
}
}
/// <summary>
/// Sets Component data for the specified Component Type on the specified Entity. If Component data for this Type already existed on the Entity, the component data is overwritten.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalWriteException">
/// Thrown when the Engine does not declare that it Writes the given Component Type.
/// </exception>
2019-11-21 03:01:29 +00:00
protected void SetComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
2019-06-16 01:05:56 +00:00
{
var priority = writePriorities.ContainsKey(typeof(TComponent)) ? writePriorities[typeof(TComponent)] : defaultWritePriority;
2019-12-06 03:55:17 +00:00
if (!writeTypes.Contains(typeof(TComponent)))
2019-07-20 00:50:13 +00:00
{
throw new IllegalWriteException("Engine {0} tried to update undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
2019-07-20 00:50:13 +00:00
}
bool written;
2019-12-06 03:55:17 +00:00
if (writePendingTypes.Contains(typeof(TComponent)))
{
written = AddPendingComponent(entity, component, priority);
}
2019-12-05 23:14:28 +00:00
else
{
written = componentUpdateManager.UpdateComponent(entity, component, priority);
2019-12-05 23:14:28 +00:00
}
if (written && component is IDrawableComponent drawableComponent)
{
2019-12-06 03:55:17 +00:00
componentManager.RegisterDrawableComponent(entity, component, drawableComponent.Layer);
}
2019-06-15 07:39:08 +00:00
}
2019-06-16 01:55:35 +00:00
/// <summary>
/// Sends a Message.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalSendException">
/// Thrown when the Engine does not declare that it Sends the Message Type.
/// </exception>
protected void SendMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
2019-06-16 01:55:35 +00:00
{
2019-07-19 01:20:38 +00:00
if (!sendTypes.Contains(typeof(TMessage)))
2019-06-16 01:55:35 +00:00
{
2019-07-20 00:50:13 +00:00
throw new IllegalSendException("Engine {0} tried to send undeclared Message {1}", GetType().Name, typeof(TMessage).Name);
2019-06-16 01:55:35 +00:00
}
messageManager.AddMessage(message);
2019-06-16 01:55:35 +00:00
}
/// <summary>
2019-11-21 22:22:10 +00:00
/// Sends a message after the specified number of seconds, respecting time dilation.
/// </summary>
/// <param name="time">The time in seconds that will elapse before the message is sent.</param>
2019-11-21 22:22:10 +00:00
protected void SendMessage<TMessage>(TMessage message, double time) where TMessage : struct, IMessage
2019-08-20 02:05:18 +00:00
{
2019-12-06 20:01:56 +00:00
messageManager.AddMessage(message, time);
2019-08-20 02:05:18 +00:00
}
2019-11-21 22:22:10 +00:00
/// <summary>
/// Sends a message after the specified number of seconds, ignoring time dilation.
/// </summary>
/// <param name="time">The time in seconds that will elapse before the message is sent.</param>
protected void SendMessageIgnoringTimeDilation<TMessage>(TMessage message, double time) where TMessage : struct, IMessage
{
2019-12-06 20:01:56 +00:00
messageManager.AddMessageIgnoringTimeDilation(message, time);
2019-07-29 05:25:34 +00:00
}
2019-12-06 03:55:17 +00:00
internal void AddExistingComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
2019-08-01 23:24:57 +00:00
{
componentUpdateManager.AddExistingComponent(entity, component);
2019-08-01 23:24:57 +00:00
}
internal bool AddPendingComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
2019-08-01 23:24:57 +00:00
{
2019-12-06 20:01:56 +00:00
return componentUpdateManager.AddPendingComponent(entity, component, priority);
2019-08-01 23:24:57 +00:00
}
/// <summary>
/// Reads all messages of the specified Type.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalReadException">
/// Thrown when the Engine does not declare that it Receives the specified Message Type.
/// </exception>
2019-06-16 01:55:35 +00:00
protected IEnumerable<TMessage> ReadMessages<TMessage>() where TMessage : struct, IMessage
{
2019-07-19 19:47:17 +00:00
if (!receiveTypes.Contains(typeof(TMessage)))
2019-06-16 01:55:35 +00:00
{
throw new IllegalReadException("Engine {0} tried to read undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name);
2019-06-16 01:55:35 +00:00
}
return messageManager.GetMessagesByType<TMessage>();
2019-06-16 01:55:35 +00:00
}
2019-06-17 01:11:35 +00:00
/// <summary>
/// Reads an arbitrary message of the specified Type.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalReadException">
/// Thrown when the Engine does not declare that it Receives the specified Message Type.
/// </exception>
2019-07-18 21:02:57 +00:00
protected TMessage ReadMessage<TMessage>() where TMessage : struct, IMessage
{
2019-12-06 20:01:56 +00:00
return messageManager.First<TMessage>();
2019-07-18 21:02:57 +00:00
}
/// <summary>
/// Returns true if a Message of the specified Type has been sent this frame.
/// </summary>
/// <exception cref="Encompass.Exceptions.IllegalReadException">
/// Thrown when the Engine does not declare that it Receives the specified Message Type.
/// </exception>
protected bool SomeMessage<TMessage>() where TMessage : struct, IMessage
2019-06-17 01:11:35 +00:00
{
2019-07-19 19:47:17 +00:00
if (!receiveTypes.Contains(typeof(TMessage)))
2019-06-17 01:11:35 +00:00
{
2019-07-18 21:02:57 +00:00
throw new IllegalReadException("Engine {0} tried to read undeclared Message {1}", GetType().Name, typeof(TMessage).Name);
2019-06-17 01:11:35 +00:00
}
2019-12-06 20:01:56 +00:00
return messageManager.Any<TMessage>();
2019-06-17 01:11:35 +00:00
}
2019-06-20 03:37:46 +00:00
/// <summary>
/// Destroys the specified Entity. This also removes all of the Components associated with the Entity.
/// Entity destruction takes place after all the Engines have been processed by World Update.
/// </summary>
protected void Destroy(Entity entity)
{
2019-12-05 22:59:55 +00:00
entityManager.MarkForDestroy(entity);
}
/// <summary>
/// Destroys an arbitrary Entity containing a Component of the specified Type.
/// Entity destruction takes place after all the Engines have been processed by World Update.
/// </summary>
protected void DestroyWith<TComponent>() where TComponent : struct, IComponent
{
Destroy(ReadEntity<TComponent>());
}
/// <summary>
/// Destroys all Entities containing a Component of the specified Type.
/// Entity destruction takes place after all the Engines have been processed by World Update.
/// </summary>
protected void DestroyAllWith<TComponent>() where TComponent : struct, IComponent
{
foreach (var entity in ReadEntities<TComponent>())
{
Destroy(entity);
}
}
/// <summary>
/// Removes a Component with the specified type from the given Entity.
/// Note that the Engine must Read the Component type that is being removed.
2019-11-21 03:01:29 +00:00
/// If a Component with the specified type does not exist on the Entity, returns false and does not mutate the Entity.
/// </summary>
2019-11-21 03:01:29 +00:00
protected bool RemoveComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
2019-11-21 03:01:29 +00:00
if (!HasComponent<TComponent>(entity)) { return false; }
2019-12-05 20:10:33 +00:00
componentManager.Remove<TComponent>(entity);
2019-11-21 03:01:29 +00:00
return true;
}
2019-11-21 22:22:10 +00:00
/// <summary>
/// Activates the Encompass time dilation system.
/// Engines that have the IgnoresTimeDilation property will ignore all time dilation.
/// If multiple time dilations are active they will be averaged.
2019-11-21 22:22:10 +00:00
/// </summary>
/// <param name="factor">The time dilation factor, which is multiplied by real delta time.</param>
/// <param name="easeInTime">The time that will elapse before time is fully dilated, in real time.</param>
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime)
{
timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime);
}
2019-11-21 22:22:10 +00:00
/// <summary>
/// Activates the Encompass time dilation system.
/// Engines that have the IgnoresTimeDilation property will ignore all time dilation.
/// If multiple time dilations are active they will be averaged.
2019-11-21 22:22:10 +00:00
/// </summary>
/// <param name="factor">The time dilation factor, which is multiplied by real delta time.</param>
/// <param name="easeInTime">The time that will elapse before time is fully dilated, in real time.</param>
/// <param name="easeInFunction">An easing function for the easing in of time dilation.</param>
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
public void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime)
{
timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime);
}
2019-11-21 22:22:10 +00:00
/// <summary>
/// Activates the Encompass time dilation system.
/// Engines that have the IgnoresTimeDilation property will ignore all time dilation.
/// If multiple time dilations are active they will be averaged.
2019-11-21 22:22:10 +00:00
/// </summary>
/// <param name="factor">The time dilation factor, which is multiplied by real delta time.</param>
/// <param name="easeInTime">The time that will elapse before time is fully dilated, in real time.</param>
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
/// <param name="easeOutFunction">An easing function for the easing out of time dilation.</param>
public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
{
timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime, easeOutFunction);
}
2019-11-21 22:22:10 +00:00
/// <summary>
/// Activates the Encompass time dilation system.
/// Engines that have the IgnoresTimeDilation property will ignore all time dilation.
/// If multiple time dilations are active they will be averaged.
2019-11-21 22:22:10 +00:00
/// </summary>
/// <param name="factor">The time dilation factor, which is multiplied by real delta time.</param>
/// <param name="easeInTime">The time that will elapse before time is fully dilated, in real time.</param>
/// <param name="easeInFunction">An easing function for the easing in of time dilation.</param>
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
/// <param name="easeOutFunction">An easing function for the easing out of time dilation.</param>
public void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
{
timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime, easeOutFunction);
}
2019-06-15 00:51:06 +00:00
}
}