Show / Hide Table of Contents

Class EntityManager

Base class for client and server manager

Inheritance
object
EntityManager
ClientEntityManager
ServerEntityManager
Namespace: LiteEntitySystem
Assembly: LiteEntitySystem.dll
Syntax
public abstract class EntityManager

Constructors

EntityManager(EntityTypesMap, NetworkMode, byte, MaxHistorySize)

Declaration
protected EntityManager(EntityTypesMap typesMap, NetworkMode mode, byte headerByte, MaxHistorySize maxHistorySize)
Parameters
Type Name Description
EntityTypesMap typesMap
NetworkMode mode
byte headerByte
MaxHistorySize maxHistorySize

Fields

AliveEntities

Declaration
protected readonly AVLTree<InternalEntity> AliveEntities
Field Value
Type Description
AVLTree<InternalEntity>

HeaderByte

Declaration
public readonly byte HeaderByte
Field Value
Type Description
byte

InvalidEntityId

Invalid entity id

Declaration
public const ushort InvalidEntityId = 0
Field Value
Type Description
ushort

IsClient

Is client

Declaration
public readonly bool IsClient
Field Value
Type Description
bool

IsServer

Is server

Declaration
public readonly bool IsServer
Field Value
Type Description
bool

LagCompensatedEntities

Declaration
protected readonly AVLTree<EntityLogic> LagCompensatedEntities
Field Value
Type Description
AVLTree<EntityLogic>

MaxEntityCount

Declaration
public const int MaxEntityCount = 32768
Field Value
Type Description
int

MaxHistorySize

Size of history (in ticks) for lag compensation. Tune for your game fps

Declaration
public readonly MaxHistorySize MaxHistorySize
Field Value
Type Description
MaxHistorySize

MaxPlayers

Declaration
public const int MaxPlayers = 254
Field Value
Type Description
int

MaxSavedStateDiff

Declaration
protected const int MaxSavedStateDiff = 30
Field Value
Type Description
int

MaxSyncedEntityCount

Maximum synchronized (without LocalOnly) entities

Declaration
public const int MaxSyncedEntityCount = 16384
Field Value
Type Description
int

Mode

Current mode (Server or Client)

Declaration
public readonly NetworkMode Mode
Field Value
Type Description
NetworkMode

ServerPlayerId

Declaration
public const byte ServerPlayerId = 0
Field Value
Type Description
byte

SpeedMultiplier

Declaration
protected float SpeedMultiplier
Field Value
Type Description
float

TimeSpeedChangeCoef

Declaration
protected const float TimeSpeedChangeCoef = 0.1
Field Value
Type Description
float

_tick

Declaration
protected ushort _tick
Field Value
Type Description
ushort

Properties

DeltaTime

Fixed delta time

Declaration
public double DeltaTime { get; }
Property Value
Type Description
double

DeltaTimeF

Fixed delta time (float for less precision)

Declaration
public float DeltaTimeF { get; }
Property Value
Type Description
float

EntitiesCount

Total entities count (including local)

Declaration
public ushort EntitiesCount { get; }
Property Value
Type Description
ushort

InNormalState

Declaration
public bool InNormalState { get; }
Property Value
Type Description
bool

InRollBackState

Declaration
public bool InRollBackState { get; }
Property Value
Type Description
bool

IsRunning

Is entity manager running IsRunning - true after first update IsRunning - sets to false after Reset() call

Declaration
public bool IsRunning { get; }
Property Value
Type Description
bool

LerpFactor

Interpolation time between logic and render

Declaration
public float LerpFactor { get; }
Property Value
Type Description
float

PlayerId

Local player id (0 on server)

Declaration
public byte PlayerId { get; }
Property Value
Type Description
byte

Tick

Current tick

Declaration
public ushort Tick { get; }
Property Value
Type Description
ushort

Tickrate

tick rate of game logic (logic FPS, not visual)

Declaration
public byte Tickrate { get; }
Property Value
Type Description
byte

UpdateMode

Current update mode (can be used inside entities to separate logic for rollbacks)

Declaration
public UpdateMode UpdateMode { get; protected set; }
Property Value
Type Description
UpdateMode

VisualDeltaTime

Declaration
public double VisualDeltaTime { get; }
Property Value
Type Description
double

Methods

AddEntity<T>(EntityParams)

Declaration
protected T AddEntity<T>(EntityParams entityParams) where T : InternalEntity
Parameters
Type Name Description
EntityParams entityParams
Returns
Type Description
T
Type Parameters
Name Description
T

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
Name Description
T

ConstructEntity(InternalEntity)

Declaration
protected void ConstructEntity(InternalEntity e)
Parameters
Type Name Description
InternalEntity e

DisableLagCompensation()

Declaration
public void DisableLagCompensation()

EnableLagCompensation(NetPlayer)

Declaration
public void EnableLagCompensation(NetPlayer player)
Parameters
Type Name Description
NetPlayer player

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 : InternalEntity
Returns
Type Description
EntityFilter<T>

Entity filter that can be used in foreach

Type Parameters
Name Description
T

Entity type

GetEntityById<T>(EntitySharedReference)

Get entity by id

Declaration
public T GetEntityById<T>(EntitySharedReference id) where T : InternalEntity
Parameters
Type Name Description
EntitySharedReference id

Id of entity

Returns
Type Description
T

Entity if it exists, null if id == InvalidEntityId or entity is another type or version

Type Parameters
Name Description
T

GetEntitySyncVarInfo(InternalEntity, IEntitySyncVarInfoPrinter)

Prints names and values of entity syncVars using IEntitySyncVarInfoPrinter

Declaration
public void GetEntitySyncVarInfo(InternalEntity entity, IEntitySyncVarInfoPrinter resultPrinter)
Parameters
Type Name Description
InternalEntity entity

entity to show

IEntitySyncVarInfoPrinter resultPrinter

IEntitySyncVarInfoPrinter implementation

GetEntityTypeFromClassId(ushort)

Get type of entity from classId. Returns null if classId is unknown

Declaration
public Type GetEntityTypeFromClassId(ushort classId)
Parameters
Type Name Description
ushort classId
Returns
Type Description
Type

GetLocalSingleton<T>()

Get local (not synchronized) singleton.

Declaration
public T GetLocalSingleton<T>() where T : ILocalSingleton
Returns
Type Description
T
Type Parameters
Name Description
T

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 Description
bool
Type Parameters
Name Description
T

OnAliveEntityAdded(InternalEntity)

Declaration
protected virtual void OnAliveEntityAdded(InternalEntity e)
Parameters
Type Name Description
InternalEntity e

OnLogicTick()

Declaration
protected abstract void OnLogicTick()

RegisterFieldType<T>()

Register custom field type

Declaration
public static void RegisterFieldType<T>() where T : unmanaged
Type Parameters
Name Description
T

RegisterFieldType<T>(InterpolatorDelegateWithReturn<T>)

Register custom field type with interpolation

Declaration
public static void RegisterFieldType<T>(InterpolatorDelegateWithReturn<T> interpolationDelegate) where T : unmanaged
Parameters
Type Name Description
InterpolatorDelegateWithReturn<T> interpolationDelegate

interpolation function

Type Parameters
Name Description
T

RemoveEntity(InternalEntity)

Declaration
protected void RemoveEntity(InternalEntity e)
Parameters
Type Name Description
InternalEntity e

Reset()

Remove all entities and reset all counters and timers

Declaration
public virtual void Reset()

SetTickrate(byte)

Declaration
protected void SetTickrate(byte tickrate)
Parameters
Type Name Description
byte tickrate

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
Type Name Description
EntitySharedReference id

Id of entity

T entity

out entity if exists otherwise null

Returns
Type Description
bool

true if it exists, false if id == InvalidEntityId or entity is another type or version

Type Parameters
Name Description
T

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 Description
bool
Type Parameters
Name Description
T

TryGetSingleton<T>(out T)

Try get singleton entity

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()
In this article
Back to top Generated by DocFX