Class EntityManager
Base class for client and server manager
Inheritance
EntityManager
Assembly: LiteEntitySystem.dll
Syntax
public abstract class EntityManager
Constructors
Declaration
protected EntityManager(EntityTypesMap typesMap, InputProcessor inputProcessor, NetworkMode mode, byte framesPerSecond, byte headerByte)
Parameters
Fields
AliveEntities
Declaration
protected readonly AVLTree<InternalEntity> AliveEntities
Field Value
AllEntities
Declaration
protected readonly AVLTree<InternalEntity> AllEntities
Field Value
DeltaTime
Declaration
public readonly double DeltaTime
Field Value
DeltaTimeF
Fixed delta time (float for less precision)
Declaration
public readonly float DeltaTimeF
Field Value
FramesPerSecond
Declaration
public readonly int FramesPerSecond
Field Value
Declaration
public readonly byte HeaderByte
Field Value
Declaration
protected readonly InputProcessor InputProcessor
Field Value
InvalidEntityId
Declaration
public const ushort InvalidEntityId = 0
Field Value
IsClient
Declaration
public readonly bool IsClient
Field Value
IsServer
Declaration
public readonly bool IsServer
Field Value
LagCompensatedEntities
Declaration
protected readonly AVLTree<EntityLogic> LagCompensatedEntities
Field Value
MaxEntityCount
Declaration
public const int MaxEntityCount = 16384
Field Value
MaxHistorySize
Size of history (in ticks) for lag compensation. Tune for your game fps
Declaration
public MaxHistorySize MaxHistorySize
Field Value
MaxPlayers
Declaration
public const int MaxPlayers = 254
Field Value
MaxSavedStateDiff
Declaration
protected const int MaxSavedStateDiff = 30
Field Value
MaxSyncedEntityCount
Maximum synchronized (without LocalOnly) entities
Declaration
public const int MaxSyncedEntityCount = 8192
Field Value
Mode
Current mode (Server or Client)
Declaration
public readonly NetworkMode Mode
Field Value
ServerPlayerId
Declaration
public const byte ServerPlayerId = 0
Field Value
SpeedMultiplier
Declaration
protected float SpeedMultiplier
Field Value
TimeSpeedChangeCoef
Declaration
protected const float TimeSpeedChangeCoef = 0.1
Field Value
_tick
Declaration
Field Value
Properties
EntitiesCount
Total entities count (including local)
Declaration
public ushort EntitiesCount { get; }
Property Value
InNormalState
Declaration
public bool InNormalState { get; }
Property Value
InRollBackState
Declaration
public bool InRollBackState { get; }
Property Value
IsRunning
Is entity manager running
IsRunning - true after first update
IsRunning - sets to false after Reset() call
Declaration
public bool IsRunning { get; }
Property Value
LerpFactor
Interpolation time between logic and render
Declaration
public float LerpFactor { get; }
Property Value
PlayerId
Local player id (0 on server)
Declaration
public byte PlayerId { get; }
Property Value
Tick
Declaration
public ushort Tick { get; }
Property Value
UpdateMode
Current update mode (can be used inside entities to separate logic for rollbacks)
Declaration
public UpdateMode UpdateMode { get; protected set; }
Property Value
VisualDeltaTime
Declaration
public double VisualDeltaTime { get; }
Property Value
Methods
AddEntity(EntityParams)
Declaration
protected InternalEntity AddEntity(EntityParams entityParams)
Parameters
Returns
AddLocalSingleton<T>(T)
Add local (not synchronized) singleton.
Declaration
public void AddLocalSingleton<T>(T singleton) where T : ILocalSingleton
Parameters
Type |
Name |
Description |
T |
singleton |
Signleton to add
|
Type Parameters
ConstructEntity(InternalEntity)
Declaration
protected void ConstructEntity(InternalEntity e)
Parameters
DisableLagCompensation()
Declaration
public void DisableLagCompensation()
EnableLagCompensation(NetPlayer)
Declaration
public void EnableLagCompensation(NetPlayer player)
Parameters
GetControllers<T>()
Get all controller entities with type
Declaration
public EntityFilter<T> GetControllers<T>() where T : ControllerLogic
Returns
Type |
Description |
EntityFilter<T> |
Entity filter that can be used in foreach
|
Type Parameters
Name |
Description |
T |
Entity type
|
GetEntities<T>()
Get all entities with type
Declaration
public EntityFilter<T> GetEntities<T>() where T : EntityLogic
Returns
Type |
Description |
EntityFilter<T> |
Entity filter that can be used in foreach
|
Type Parameters
Name |
Description |
T |
Entity type
|
GetEntityById<T>(EntitySharedReference)
Declaration
public T GetEntityById<T>(EntitySharedReference id) where T : InternalEntity
Parameters
Returns
Type |
Description |
T |
Entity if it exists, null if id == InvalidEntityId or entity is another type or version
|
Type Parameters
GetLocalSingleton<T>()
Get local (not synchronized) singleton.
Declaration
public T GetLocalSingleton<T>() where T : ILocalSingleton
Returns
Type Parameters
GetSingleton<T>()
Get existing singleton entity
Declaration
public T GetSingleton<T>() where T : SingletonEntityLogic
Returns
Type |
Description |
T |
Singleton entity, can throw exceptions on invalid type
|
Type Parameters
Name |
Description |
T |
Singleton entity type
|
HasSingleton<T>()
Is singleton exists and has correct type
Declaration
public bool HasSingleton<T>() where T : SingletonEntityLogic
Returns
Type Parameters
OnAliveEntityAdded(InternalEntity)
Declaration
protected virtual void OnAliveEntityAdded(InternalEntity e)
Parameters
OnLogicTick()
Declaration
protected abstract void OnLogicTick()
RegisterFieldType<T>()
Register custom field type
Declaration
public static void RegisterFieldType<T>() where T : unmanaged
Type Parameters
RegisterFieldType<T>(InterpolatorDelegateWithReturn<T>)
Register custom field type with interpolation
Declaration
public static void RegisterFieldType<T>(InterpolatorDelegateWithReturn<T> interpolationDelegate) where T : unmanaged
Parameters
Type Parameters
RemoveEntity(InternalEntity)
Declaration
protected void RemoveEntity(InternalEntity e)
Parameters
Reset()
Remove all entities and reset all counters and timers
Declaration
public virtual void Reset()
TryGetEntityById<T>(EntitySharedReference, out T)
Try get entity by id
throws exception if entity is null or invalid type
Declaration
public bool TryGetEntityById<T>(EntitySharedReference id, out T entity) where T : InternalEntity
Parameters
Returns
Type |
Description |
bool |
true if it exists, false if id == InvalidEntityId or entity is another type or version
|
Type Parameters
TryGetLocalSingleton<T>(out T)
TryGet local (not synchronized) singleton.
Declaration
public bool TryGetLocalSingleton<T>(out T result) where T : ILocalSingleton
Parameters
Type |
Name |
Description |
T |
result |
|
Returns
Type Parameters
TryGetSingleton<T>(out T)
Declaration
public bool TryGetSingleton<T>(out T singleton) where T : SingletonEntityLogic
Parameters
Type |
Name |
Description |
T |
singleton |
result singleton entity
|
Returns
Type |
Description |
bool |
true if entity exists
|
Type Parameters
Name |
Description |
T |
Singleton type
|
Update()
Main update method, updates internal fixed timer and do all other stuff
Declaration
public virtual void Update()