Table of Contents

Class EntityManager

Namespace
LiteEntitySystem
Assembly
LiteEntitySystem.dll

Base class for client and server manager

public abstract class EntityManager
Inheritance
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> AliveEntities

Field Value

AVLTree<InternalEntity>

HeaderByte

EntityManager packets header byte (can be used to distinguish LES packets from custom made)

public readonly byte HeaderByte

Field Value

byte

InvalidEntityId

Invalid entity id

public const ushort InvalidEntityId = 0

Field Value

ushort

IsClient

Is client

public readonly bool IsClient

Field Value

bool

IsServer

Is server

public readonly bool IsServer

Field Value

bool

LagCompensatedEntities

protected readonly AVLTree<EntityLogic> LagCompensatedEntities

Field Value

AVLTree<EntityLogic>

MaxEntityCount

public const int MaxEntityCount = 65534

Field Value

int

MaxHistorySize

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

public readonly MaxHistorySize MaxHistorySize

Field Value

MaxHistorySize

MaxLocalEntityCount

Maximum count of predicted local entities

public const int MaxLocalEntityCount = 1534

Field Value

int

MaxPlayers

public const int MaxPlayers = 254

Field Value

int

MaxSavedStateDiff

protected const int MaxSavedStateDiff = 30

Field Value

int

MaxSyncedEntityCount

Maximum synchronized (without LocalOnly) entities

public const int MaxSyncedEntityCount = 64000

Field Value

int

Mode

Current mode (Server or Client)

public readonly NetworkMode Mode

Field Value

NetworkMode

ServerPlayerId

Server player Id - always 0 and reserved

public const byte ServerPlayerId = 0

Field Value

byte

SpeedMultiplier

protected float SpeedMultiplier

Field Value

float

TimeSpeedChangeCoef

protected const float TimeSpeedChangeCoef = 0.1

Field Value

float

_tick

protected ushort _tick

Field Value

ushort

Properties

DeltaTime

Fixed delta time

public double DeltaTime { get; }

Property Value

double

DeltaTimeF

Fixed delta time (float for less precision)

public float DeltaTimeF { get; }

Property Value

float

EntitiesCount

Total entities count (including local)

public ushort EntitiesCount { get; }

Property Value

ushort

InNormalState

public bool InNormalState { get; }

Property Value

bool

InRollBackState

public bool InRollBackState { get; }

Property Value

bool

IsLagCompensationEnabled

Is lag compensation currently enabled

public bool IsLagCompensationEnabled { get; }

Property Value

bool

IsRunning

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

public bool IsRunning { get; }

Property Value

bool

LerpFactor

Interpolation time between logic and render

public float LerpFactor { get; }

Property Value

float

PlayerId

Local player id (0 on server)

public byte PlayerId { get; }

Property Value

byte

Tick

Current tick

public ushort Tick { get; }

Property Value

ushort

Tickrate

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

public byte Tickrate { get; }

Property Value

byte

UpdateMode

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

public UpdateMode UpdateMode { get; protected set; }

Property Value

UpdateMode

VisualDeltaTime

Delta time between visual Updates

public double VisualDeltaTime { get; }

Property Value

double

VisualDeltaTimeF

Delta time between visual Updates (float)

public float VisualDeltaTimeF { get; }

Property Value

float

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 T

Signleton to add

Type Parameters

T

ConstructEntity(InternalEntity)

protected bool ConstructEntity(InternalEntity e)

Parameters

e InternalEntity

Returns

bool

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 EntitySharedReference

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

Type

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

bool

Type Parameters

T

IsEntityLagCompensated(InternalEntity)

protected static bool IsEntityLagCompensated(InternalEntity e)

Parameters

e InternalEntity

Returns

bool

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

e InternalEntity

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 EntitySharedReference

Id of entity

entity T

out 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

bool

Type Parameters

T

TryGetSingleton<T>(out T)

Try get singleton entity

public bool TryGetSingleton<T>(out T singleton) where T : SingletonEntityLogic

Parameters

singleton T

result 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()