Class EntityManager
- Namespace
- LiteEntitySystem
- Assembly
- LiteEntitySystem.dll
Base class for client and server manager
public abstract class EntityManager
- Inheritance
-
objectEntityManager
- Derived
Constructors
EntityManager(EntityTypesMap, NetworkMode, byte, MaxHistorySize)
protected EntityManager(EntityTypesMap typesMap, NetworkMode mode, byte headerByte, MaxHistorySize maxHistorySize)
Parameters
typesMap
EntityTypesMapmode
NetworkModeheaderByte
bytemaxHistorySize
MaxHistorySize
Fields
AliveEntities
protected readonly AVLTree<InternalEntity> AliveEntities
Field Value
HeaderByte
EntityManager packets header byte (can be used to distinguish LES packets from custom made)
public readonly byte HeaderByte
Field Value
InvalidEntityId
Invalid entity id
public const ushort InvalidEntityId = 0
Field Value
IsClient
Is client
public readonly bool IsClient
Field Value
IsServer
Is server
public readonly bool IsServer
Field Value
LagCompensatedEntities
protected readonly AVLTree<EntityLogic> LagCompensatedEntities
Field Value
MaxEntityCount
public const int MaxEntityCount = 65534
Field Value
MaxHistorySize
Size of history (in ticks) for lag compensation. Tune for your game fps
public readonly MaxHistorySize MaxHistorySize
Field Value
MaxLocalEntityCount
Maximum count of predicted local entities
public const int MaxLocalEntityCount = 1534
Field Value
MaxPlayers
public const int MaxPlayers = 254
Field Value
MaxSavedStateDiff
protected const int MaxSavedStateDiff = 30
Field Value
MaxSyncedEntityCount
Maximum synchronized (without LocalOnly) entities
public const int MaxSyncedEntityCount = 64000
Field Value
Mode
Current mode (Server or Client)
public readonly NetworkMode Mode
Field Value
ServerPlayerId
Server player Id - always 0 and reserved
public const byte ServerPlayerId = 0
Field Value
SpeedMultiplier
protected float SpeedMultiplier
Field Value
TimeSpeedChangeCoef
protected const float TimeSpeedChangeCoef = 0.1
Field Value
_tick
protected ushort _tick
Field Value
Properties
DeltaTime
Fixed delta time
public double DeltaTime { get; }
Property Value
DeltaTimeF
Fixed delta time (float for less precision)
public float DeltaTimeF { get; }
Property Value
EntitiesCount
Total entities count (including local)
public ushort EntitiesCount { get; }
Property Value
InNormalState
public bool InNormalState { get; }
Property Value
InRollBackState
public bool InRollBackState { get; }
Property Value
IsLagCompensationEnabled
Is lag compensation currently enabled
public bool IsLagCompensationEnabled { get; }
Property Value
IsRunning
Is entity manager running IsRunning - true after first update IsRunning - sets to false after Reset() call
public bool IsRunning { get; }
Property Value
LerpFactor
Interpolation time between logic and render
public float LerpFactor { get; }
Property Value
PlayerId
Local player id (0 on server)
public byte PlayerId { get; }
Property Value
Tick
Current tick
public ushort Tick { get; }
Property Value
Tickrate
tick rate of game logic (logic FPS, not visual)
public byte Tickrate { get; }
Property Value
UpdateMode
Current update mode (can be used inside entities to separate logic for rollbacks)
public UpdateMode UpdateMode { get; protected set; }
Property Value
VisualDeltaTime
Delta time between visual Updates
public double VisualDeltaTime { get; }
Property Value
VisualDeltaTimeF
Delta time between visual Updates (float)
public float VisualDeltaTimeF { get; }
Property Value
Methods
AddEntity<T>(EntityParams)
protected T AddEntity<T>(EntityParams entityParams) where T : InternalEntity
Parameters
entityParams
EntityParams
Returns
- T
Type Parameters
T
AddLocalSingleton<T>(T)
Add local (not synchronized) singleton.
public void AddLocalSingleton<T>(T singleton) where T : ILocalSingleton
Parameters
singleton
TSignleton to add
Type Parameters
T
ConstructEntity(InternalEntity)
protected bool ConstructEntity(InternalEntity e)
Parameters
Returns
DisableLagCompensation()
public void DisableLagCompensation()
EnableLagCompensation(NetPlayer)
public void EnableLagCompensation(NetPlayer player)
Parameters
player
NetPlayer
ExecuteLateConstruct()
protected void ExecuteLateConstruct()
GetControllers<T>()
Get all controller entities with type
public EntityFilter<T> GetControllers<T>() where T : ControllerLogic
Returns
- EntityFilter<T>
Entity filter that can be used in foreach
Type Parameters
T
Entity type
GetEntities<T>()
Get all entities with type
public EntityFilter<T> GetEntities<T>() where T : InternalEntity
Returns
- EntityFilter<T>
Entity filter that can be used in foreach
Type Parameters
T
Entity type
GetEntityById<T>(EntitySharedReference)
Get entity by id
public T GetEntityById<T>(EntitySharedReference id) where T : InternalEntity
Parameters
id
EntitySharedReferenceId of entity
Returns
- T
Entity if it exists, null if id == InvalidEntityId or entity is another type or version
Type Parameters
T
GetEntitySyncVarInfo(InternalEntity, IEntitySyncVarInfoPrinter)
Prints names and values of entity syncVars using IEntitySyncVarInfoPrinter
public void GetEntitySyncVarInfo(InternalEntity entity, IEntitySyncVarInfoPrinter resultPrinter)
Parameters
entity
InternalEntityentity to show
resultPrinter
IEntitySyncVarInfoPrinterIEntitySyncVarInfoPrinter implementation
GetEntityTypeFromClassId(ushort)
Get type of entity from classId. Returns null if classId is unknown
public Type GetEntityTypeFromClassId(ushort classId)
Parameters
classId
ushort
Returns
GetLocalSingleton<T>()
Get local (not synchronized) singleton.
public T GetLocalSingleton<T>() where T : ILocalSingleton
Returns
- T
Type Parameters
T
GetSingleton<T>()
Get existing singleton entity
public T GetSingleton<T>() where T : SingletonEntityLogic
Returns
- T
Singleton entity, can throw exceptions on invalid type
Type Parameters
T
Singleton entity type
HasSingleton<T>()
Is singleton exists and has correct type
public bool HasSingleton<T>() where T : SingletonEntityLogic
Returns
Type Parameters
T
IsEntityLagCompensated(InternalEntity)
protected static bool IsEntityLagCompensated(InternalEntity e)
Parameters
Returns
OnLogicTick()
protected abstract void OnLogicTick()
RegisterFieldType<T>()
Register custom field type
public static void RegisterFieldType<T>() where T : unmanaged
Type Parameters
T
RegisterFieldType<T>(InterpolatorDelegateWithReturn<T>)
Register custom field type with interpolation
public static void RegisterFieldType<T>(InterpolatorDelegateWithReturn<T> interpolationDelegate) where T : unmanaged
Parameters
interpolationDelegate
InterpolatorDelegateWithReturn<T>interpolation function
Type Parameters
T
RemoveEntity(InternalEntity)
protected void RemoveEntity(InternalEntity e)
Parameters
Reset()
Remove all entities and reset all counters and timers
public virtual void Reset()
SetTickrate(byte)
protected void SetTickrate(byte tickrate)
Parameters
tickrate
byte
TryGetEntityById<T>(EntitySharedReference, out T)
Try get entity by id throws exception if entity is null or invalid type
public bool TryGetEntityById<T>(EntitySharedReference id, out T entity) where T : InternalEntity
Parameters
id
EntitySharedReferenceId of entity
entity
Tout entity if exists otherwise null
Returns
- bool
true if it exists, false if id == InvalidEntityId or entity is another type or version
Type Parameters
T
TryGetLocalSingleton<T>(out T)
TryGet local (not synchronized) singleton.
public bool TryGetLocalSingleton<T>(out T result) where T : ILocalSingleton
Parameters
result
T
Returns
Type Parameters
T
TryGetSingleton<T>(out T)
Try get singleton entity
public bool TryGetSingleton<T>(out T singleton) where T : SingletonEntityLogic
Parameters
singleton
Tresult singleton entity
Returns
- bool
true if entity exists
Type Parameters
T
Singleton type
Update()
Main update method, updates internal fixed timer and do all other stuff
public virtual void Update()