Class EntitySystem
Namespace: ValveResourceFormat.Renderer.Entities
Assembly: Renderer.dll
Owns the living entities, runs them on a fixed tick, and carries the entity I/O queue.
public sealed class EntitySystemInheritance
object ← EntitySystem
Remarks
Entities tick at EntitySystem.TickInterval, not once per frame. A frame runs the ticks it owes, up to EntitySystem.MaxTicksPerFrame, so a hitch cannot make simulating take longer than drawing.
Constructors
EntitySystem(RendererContext)
Initializes an entity world. Prefer Renderer.EntitySystem over constructing one.
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
int
TickInterval
The fixed simulation tick, 64 per second.
public const float TickInterval = 0.015625Field Value
float
Properties
ActiveSkyboxReference
Gets the skybox_reference whose 3D sky is drawn, the last to activate, or null.
public SkyboxReference? ActiveSkyboxReference { get; }Property Value
ActiveSpawnGroup
Gets the active spawn group, which a point_template set to insert into it gives its entities to, set by SpawnGroupManager.PerformActivateSpawnGroup(SpawnGroup). The map becomes active once it has spawned, and none is active once the active one unloads.
public SpawnGroup? ActiveSpawnGroup { get; }Property Value
CurrentTime
Gets the current simulation time in seconds.
public float CurrentTime { get; }Property Value
float
Enabled
Gets or sets whether the world is simulated. When off the ticks stop, so nothing thinks, moves, touches or fires entity I/O. Spawned entities stay in the scene and stay drawn.
public bool Enabled { get; set; }Property Value
bool
Entities
Gets every living entity, in spawn order.
public IReadOnlyList<BaseEntity> Entities { get; }Property Value
FileLoader
Gets the loader for entity 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 it so movement is smooth at any framerate.
public float InterpolationFraction { get; }Property Value
[float
Logger
Gets the logger for entity problems.
public ILogger Logger { get; }Property Value
PhysicsWorld
Gets the physics world of the main world group, which every trace is made against. It holds the world physics of every spawn group loaded into that group.
public PhysicsWorld PhysicsWorld { get; }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
SpawnGroupManager
Gets what loads, spawns and unloads the spawn groups the entities come from.
public SpawnGroupManager SpawnGroupManager { get; }Property Value
TempEntities
Gets the one-shot effects that have no entity of their own, such as bullet impacts.
public TempEntities TempEntities { get; }Property Value
TickCount
Gets the number of ticks simulated so far.
public int TickCount { get; }Property Value
int
ToolVisuals
Gets or sets what a tool draws for entities beyond what the game shows, or null to draw only that. Set before a world is loaded, as entities build their nodes when they spawn.
public IEntityToolVisuals? ToolVisuals { get; set; }Property Value
World
Gets the world entity at the root of the hierarchy, once a map has loaded. A trace that hits the static world reports it as the entity hit.
public WorldEntity? World { get; }Property Value
Methods
AddEntity(BaseEntity)
Adds an entity built in code rather than from map keyvalues.
public void AddEntity(BaseEntity entity)Parameters
entity BaseEntity
CancelQueuedInputsFrom(BaseEntity)
Drops the unfired inputs an entity 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 the collision of the loaded worlds, and resets the clock. Scene nodes are cleaned up by Renderer.Clear(), which runs first.
public void Clear()FindAllByTargetName(string)
Finds every entity whose targetname matches, in any world group.
public IEnumerable<BaseEntity> FindAllByTargetName(string pattern)Parameters
pattern string
Returns
FindAllByTargetNameInWorldGroup(string, Scene)
Finds every entity in the world group of scene whose targetname matches. Used for parentname only; every other name is found in any world group.
public IEnumerable<BaseEntity> FindAllByTargetNameInWorldGroup(string pattern, Scene scene)Parameters
pattern string
scene Scene
Returns
FindByTargetName(string)
Finds the first entity whose targetname matches, in any world group.
public BaseEntity? FindByTargetName(string pattern)Parameters
pattern string
Returns
FindTargets(EntityIOTarget, BaseEntity?, BaseEntity?)
Resolves what an authored connection addresses: ! names 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.
GetPhysicsWorld(string?)
Gets the physics world of a world group, creating it on first use.
public PhysicsWorld GetPhysicsWorld(string? worldGroup)Parameters
worldGroup string?
The world group, or null for the main one.
Returns
NotePlayerImpact(BaseEntity)
Records that the player hit a solid entity, for the next tick to report as a touch.
public void NotePlayerImpact(BaseEntity entity)Parameters
entity BaseEntity
The entity a movement sweep hit.
NotePlayerImpact(in TraceResult)
Notes what a sweep of the player ran into, unless it missed or struck the world.
public void NotePlayerImpact(in Rubikon.TraceResult trace)Parameters
trace Rubikon.TraceResult
OverlapsSolidEntity(Vector3, Vector3)
Gets whether an axis-aligned box overlaps any solid entity where it stands.
public bool OverlapsSolidEntity(Vector3 center, Vector3 halfExtents)Parameters
center Vector3
halfExtents Vector3
Returns
bool
QueueConnection(Connection, BaseEntity?)
Fires one authored connection on its own, for triggering map logic by hand.
public void QueueConnection(EntityLump.Connection connection, BaseEntity? activator = null)Parameters
connection EntityLump.Connection
The connection to fire.
activator BaseEntity?
The entity that started the chain, usually the player.
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, or failing that classname, * 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 its nodes from the scene.
public void Remove(BaseEntity entity)Parameters
entity BaseEntity
RemoveAllEntities()
Removes every entity and resets the clock, keeping the collision of the loaded worlds, so their entities can spawn again as they did when the map loaded.
public void RemoveAllEntities()SnapToTick(float)
Rounds a time onto the nearest tick.
public static float SnapToTick(float time)Parameters
time float
Returns
float
The time of the nearest tick.
Remarks
Rounding up to the first tick at or after the time would make a repeating 0.1s think run every 7 ticks instead of 6, about a sixth slow.
SpawnPlayer(IPlayerController, Scene)
Puts the player into the world, replacing any 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
bool
true when an entity produced the nearest hit.
TraceRay(Vector3, Vector3, string, ref TraceResult)
Traces a ray against every solid entity, narrowing result to the nearest hit.
public bool TraceRay(Vector3 from, Vector3 to, string collisionName, ref Rubikon.TraceResult result)Parameters
from Vector3
to Vector3
collisionName string
result Rubikon.TraceResult
Returns
bool
true when an entity produced the nearest hit.
TraceWaterSurface(Vector3, Vector3, out Vector3)
Finds where a ray enters water that it is still under at its end.
public bool TraceWaterSurface(Vector3 from, Vector3 to, out Vector3 surface)Parameters
from Vector3
Where the ray starts, above the water.
to Vector3
Where the ray ends.
surface Vector3
The point on the water surface the ray goes in at.
Returns
bool
true when the ray ends under water.
TriggerOutput(BaseEntity, string, BaseEntity?, string?, BaseEntity?)
Fires an entity's authored output on every connection with that name. The value is what the output reports, and a connection's own parameter overrides it. The caller defaults to source; the few outputs that pass on the caller of the input that fired them name it.
public void TriggerOutput(BaseEntity source, string outputName, BaseEntity? activator = null, string? value = null, BaseEntity? caller = null)Parameters
source BaseEntity
outputName string
activator BaseEntity?
value string?
caller BaseEntity?
Update(float)
Advances the world by a frame's worth of time, running whole ticks.
public void Update(float frameTime)Parameters
frameTime float

