Class EntityManager (original) (raw)
Namespace
Assembly
LiteEntitySystem.dll
Base class for client and server manager
public abstract class EntityManagerInheritance
object
EntityManager
Derived
Constructors
EntityManager(EntityTypesMap, NetworkMode, byte, MaxHistorySize)
protected EntityManager(EntityTypesMap typesMap, NetworkMode mode, byte headerByte, MaxHistorySize maxHistorySize)Parameters
typesMap EntityTypesMap
mode NetworkMode
headerByte byte
maxHistorySize MaxHistorySize
Fields
AliveEntities
protected readonly AVLTree<InternalEntity> AliveEntitiesField Value
EntityManager packets header byte (can be used to distinguish LES packets from custom made)
public readonly byte HeaderByteField Value
InvalidEntityId
Invalid entity id
public const ushort InvalidEntityId = 0Field Value
IsClient
Is client
public readonly bool IsClientField Value
IsServer
Is server
public readonly bool IsServerField Value
LagCompensatedEntities
protected readonly AVLTree<EntityLogic> LagCompensatedEntitiesField Value
MaxEntityCount
public const int MaxEntityCount = 65534Field Value
MaxHistorySize
Size of history (in ticks) for lag compensation. Tune for your game fps
public readonly MaxHistorySize MaxHistorySizeField Value
MaxLocalEntityCount
Maximum count of predicted local entities
public const int MaxLocalEntityCount = 1534Field Value
MaxPlayers
public const int MaxPlayers = 254Field Value
MaxSavedStateDiff
protected const int MaxSavedStateDiff = 30Field Value
MaxSyncedEntityCount
Maximum synchronized (without LocalOnly) entities
public const int MaxSyncedEntityCount = 64000Field Value
Mode
Current mode (Server or Client)
public readonly NetworkMode ModeField Value
ServerPlayerId
Server player Id - always 0 and reserved
public const byte ServerPlayerId = 0Field Value
SpeedMultiplier
protected float SpeedMultiplierField Value
TimeSpeedChangeCoef
protected const float TimeSpeedChangeCoef = 0.1Field Value
_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(EntityParams)
protected T AddEntity<T>(EntityParams entityParams) where T : InternalEntityParameters
entityParams EntityParams
Returns
T
Type Parameters
T
AddLocalSingleton(T)
Add local (not synchronized) singleton.
public void AddLocalSingleton<T>(T singleton) where T : ILocalSingletonParameters
singleton T
Signleton to add
Type Parameters
T
ConstructEntity(InternalEntity)
protected void ConstructEntity(InternalEntity e)Parameters
DisableLagCompensation()
public void DisableLagCompensation()EnableLagCompensation(NetPlayer)
public void EnableLagCompensation(NetPlayer player)Parameters
player NetPlayer
ExecuteLateConstruct()
protected void ExecuteLateConstruct()GetControllers()
Get all controller entities with type
public EntityFilter<T> GetControllers<T>() where T : ControllerLogicReturns
Entity filter that can be used in foreach
Type Parameters
T
Entity type
GetCurrentFrameDebugInfo(DebugFrameModes)
Get information about current update frame
public abstract string GetCurrentFrameDebugInfo(DebugFrameModes modes)Parameters
modes DebugFrameModes
Returns
debug formatted string
GetEntities()
Get all entities with type
public EntityFilter<T> GetEntities<T>() where T : InternalEntityReturns
Entity filter that can be used in foreach
Type Parameters
T
Entity type
GetEntityById(EntitySharedReference)
Get entity by id
public T GetEntityById<T>(EntitySharedReference id) where T : InternalEntityParameters
Id 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 InternalEntity
entity to show
resultPrinter IEntitySyncVarInfoPrinter
IEntitySyncVarInfoPrinter 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()
Get local (not synchronized) singleton.
public T GetLocalSingleton<T>() where T : ILocalSingletonReturns
T
Type Parameters
T
GetSingleton()
Get existing singleton entity
public T GetSingleton<T>() where T : SingletonEntityLogicReturns
T
Singleton entity, can throw exceptions on invalid type
Type Parameters
T
Singleton entity type
HasSingleton()
Is singleton exists and has correct type
public bool HasSingleton<T>() where T : SingletonEntityLogicReturns
Type Parameters
T
IsEntityLagCompensated(InternalEntity)
protected static bool IsEntityLagCompensated(InternalEntity e)Parameters
Returns
OnLogicTick()
protected abstract void OnLogicTick()RegisterFieldType()
Register custom field type
public static void RegisterFieldType<T>() where T : unmanagedType Parameters
T
RegisterFieldType(InterpolatorDelegateWithReturn)
Register custom field type with interpolation
public static void RegisterFieldType<T>(InterpolatorDelegateWithReturn<T> interpolationDelegate) where T : unmanagedParameters
interpolationDelegate InterpolatorDelegateWithReturn
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(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 : InternalEntityParameters
Id of entity
entity T
out entity if exists otherwise null
Returns
true if it exists, false if id == InvalidEntityId or entity is another type or version
Type Parameters
T
TryGetLocalSingleton(out T)
TryGet local (not synchronized) singleton.
public bool TryGetLocalSingleton<T>(out T result) where T : ILocalSingletonParameters
result T
Returns
Type Parameters
T
TryGetSingleton(out T)
Try get singleton entity
public bool TryGetSingleton<T>(out T singleton) where T : SingletonEntityLogicParameters
singleton T
result singleton entity
Returns
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()