Class EntitySystem
Namespace: ValveResourceFormat.Renderer.Entities
Assembly: Renderer.dll
The world every simulated entity lives in. It owns the list of living entities, runs them on a fixed tick, and carries the entity I/O queue between them.
public sealed class EntitySystemInheritance
Remarks
Entities tick at rather than once per rendered frame. A frame runs as many ticks as it owes, up to , so a hitch cannot leave the world simulating for longer than it takes to draw.
Constructors
EntitySystem(RendererContext)
Initializes an entity world. Prefer over constructing one directly.
public EntitySystem(RendererContext context)Parameters
context RendererContext
The shared renderer context entities load and log through.
Fields
MaxTicksPerFrame
The most ticks one frame may run before the leftover time is dropped.
public const int MaxTicksPerFrame = 8Field Value
TickInterval
The fixed simulation tick, matching the engine's default 64 tick.
public const float TickInterval = 0.015625Field Value
Properties
CurrentTime
Gets the current simulation time in seconds, the engine's curtime.
public float CurrentTime { get; }Property Value
Enabled
Gets or sets whether the world is simulated. Switching it off holds every entity where it stands: the ticks stop, so nothing thinks, moves, touches, or fires entity I/O. What is already spawned stays in the scene and stays drawn.
public bool Enabled { get; set; }Property Value
Entities
Gets every living entity, in spawn order.
public IReadOnlyList<BaseEntity> Entities { get; }Property Value
FileLoader
Gets the loader entities use to pull their models and physics.
public IFileLoader FileLoader { get; }Property Value
InterpolationFraction
Gets how far the current frame sits between the last two simulated ticks, in [0, 1). Entities interpolate their render transform across that span so movement is smooth at any framerate rather than stepping at the tick rate.
public float InterpolationFraction { get; }Property Value
Logger
Gets the logger for entity problems.
public ILogger Logger { get; }Property Value
PhysicsWorld
Gets or sets the static collision every entity is simulated against. There is one, from the map the player is in; a spawn group placed inside it, such as a 3D sky, brings no collision of its own.
public Rubikon? PhysicsWorld { get; set; }Property Value
Player
Gets the player, once one has been spawned into this world.
public PlayerEntity? Player { get; }Property Value
RendererContext
Gets the shared renderer context this world loads and logs through.
public RendererContext RendererContext { get; }Property Value
TickCount
Gets the number of ticks simulated so far.
public int TickCount { get; }Property Value
World
Gets the worldspawn at the root of the entity hierarchy, once a map has supplied one. A trace that hits the static world reports it as the entity it hit.
public WorldEntity? World { get; }Property Value
Methods
Activate()
Runs on every entity spawned since the last call. Called once per spawn group - the map, and again for its 3D skybox - the way the engine activates each group as it finishes spawning.
public void Activate()AddEntity(BaseEntity)
Puts an entity built in code, rather than from map keyvalues, into the world.
public void AddEntity(BaseEntity entity)Parameters
entity BaseEntity
CancelQueuedInputsFrom(BaseEntity)
Drops the inputs an entity queued that have not fired yet, Source's CancelPending. Only the ones it queued itself: an input another entity aimed at it is that entity's to cancel.
public void CancelQueuedInputsFrom(BaseEntity caller)Parameters
caller BaseEntity
Clear()
Drops every entity and resets the clock. The scene nodes themselves are the scene's to clean up, which does before calling this.
public void Clear()CreateEntity(Entity, Matrix4x4, string?, Scene)
Creates the entity for a map entity's keyvalues and puts it in the world. A classname the entity system does not implement becomes a or a , which draw themselves but do nothing else.
public BaseEntity? CreateEntity(EntityLump.Entity data, Matrix4x4 parentTransform, string? layerName, Scene intoScene)Parameters
data EntityLump.Entity
The entity's keyvalues.
parentTransform Matrix4x4
Transform of whatever spawned it.
layerName string?
Visibility layer for its nodes.
intoScene Scene
Scene the entity's nodes render into.
Returns
The spawned entity, or null if the keyvalues name no classname.
FindAllByTargetName(string)
Finds every entity whose targetname matches.
public IEnumerable<BaseEntity> FindAllByTargetName(string pattern)Parameters
pattern string
Returns
FindAllByTargetName(string, Scene)
Finds every entity of one spawn group whose targetname matches. A 3D sky shares its names with the map it is placed in, so anything an entity names in its own keyvalues is looked up this way.
public IEnumerable<BaseEntity> FindAllByTargetName(string pattern, Scene scene)Parameters
pattern string
scene Scene
Returns
FindTargets(EntityIOTarget, BaseEntity?, BaseEntity?)
Resolves what an authored connection addresses: the ! names that stand for an entity in the firing chain, then names and classnames.
public IEnumerable<BaseEntity> FindTargets(EntityIOTarget target, BaseEntity? activator = null, BaseEntity? caller = null)Parameters
target EntityIOTarget
activator BaseEntity?
caller BaseEntity?
Returns
The entities the target stands for, which may be none.
FindUseTarget(Vector3, Vector3)
Finds the nearest usable entity along a ray, for the player's +use.
public BaseEntity? FindUseTarget(Vector3 from, Vector3 to)Parameters
from Vector3
to Vector3
Returns
The nearest usable entity in reach, or null when there is none.
QueueInput(BaseEntity, string, string?, BaseEntity?, BaseEntity?, float)
Fires an entity I/O input at one entity, after a delay in seconds.
public void QueueInput(BaseEntity target, string inputName, string? parameter = null, BaseEntity? activator = null, BaseEntity? caller = null, float delay = 0)Parameters
target BaseEntity
inputName string
parameter string?
activator BaseEntity?
caller BaseEntity?
delay float
QueueInputByTargetName(string, string, string?, BaseEntity?, BaseEntity?, float)
Fires an entity I/O input at every entity whose targetname matches, * and ? wildcards included, after a delay in seconds.
public void QueueInputByTargetName(string targetName, string inputName, string? parameter = null, BaseEntity? activator = null, BaseEntity? caller = null, float delay = 0)Parameters
targetName string
inputName string
parameter string?
activator BaseEntity?
caller BaseEntity?
delay float
Remove(BaseEntity)
Removes an entity from the world and takes its nodes out of the scene.
public void Remove(BaseEntity entity)Parameters
entity BaseEntity
SnapToTick(float)
Rounds a time onto the tick it lands nearest, the way the engine's TIME_TO_TICKS does.
public static float SnapToTick(float time)Parameters
time float
Returns
The time of the nearest tick.
Remarks
Scheduling to the first tick at or after the time would round every interval up: a repeating 0.1s think would run every 7 ticks instead of 6, about a sixth slow.
SpawnPlayer(IPlayerController, Scene)
Puts the player into the world, so triggers have something to touch. Replaces any player already spawned.
public PlayerEntity SpawnPlayer(IPlayerController controller, Scene scene)Parameters
controller IPlayerController
scene Scene
Returns
The player entity.
StartRound()
Notify every entity a round started.
public void StartRound()TraceAABB(Vector3, Vector3, Vector3, bool, ref TraceResult)
Sweeps an axis-aligned box against every solid entity, narrowing result to the nearest hit.
public bool TraceAABB(Vector3 from, Vector3 to, Vector3 halfExtents, bool detectStartSolid, ref Rubikon.TraceResult result)Parameters
from Vector3
to Vector3
halfExtents Vector3
detectStartSolid bool
result Rubikon.TraceResult
Returns
true when an entity produced the nearest hit.
TriggerOutput(BaseEntity, string, BaseEntity?, string?)
Fires one of an entity's authored outputs, delivering it to every connection with that name. Source's FireOutput. The value is what the output reports, for the ones that carry a reading; a connection authored with its own parameter overrides it, as in the engine.
public void TriggerOutput(BaseEntity source, string outputName, BaseEntity? activator = null, string? value = null)Parameters
source BaseEntity
outputName string
activator BaseEntity?
value string?
Update(float)
Advances the world by a rendered frame's worth of time, running whole ticks.
public void Update(float frameTime)Parameters
frameTime float

