This implementation separates the searching entity (Self), the original
activation cause (Activator), and the entity that emitted the current event
(Caller). The semantics follow the procedural-name resolver and event queue in
Source SDK 2013 where applicable to XSharp’s single-player 2-D engine.
| Name | Resolution |
|---|---|
!self |
Searching entity. For an output’s target field this is the emitter; for an entity-valued input parameter it is the receiving entity. |
!caller |
Emitter of the current event. Changes at each forwarding step. |
!activator |
Original activation cause, propagated through synchronous input handlers and queued events. |
!player |
Current local player. |
!pvsplayer |
Live local player if inside a camera-sized rectangle centered on the searching entity (or activator). Without either origin, the live local player is returned. |
!picker |
Closest visible live sprite intersecting the player’s horizontal aiming ray, limited to the current viewport. |
Selectors are case-insensitive. Existing targetnames, */? wildcards,
@GUID, bare GUIDs and #index remain supported. I/O dispatch uses classname
fallback only if no targetname matches; classname is taken from the entity’s
attribute, with CLR names also supported. Multiple matching recipients are
supported. Unknown ! names are configuration errors. A known selector with no
current entity is not a permanent error.
The !pvsplayer and !picker rules are deliberate 2-D approximations, not an
implementation of Source’s BSP/PVS or 3-D trace. The picker does not test terrain
occlusion. XSharp is single-player. Entity lifetime is checked against the current
entity factory; delayed identity references cannot accidentally match a reused
entity index. A delayed selector such as !player or !picker is evaluated at
delivery time, whereas the caller, activator and explicit entity-valued payload
retain their original identities.
The old attributed inputs and CLR event signatures remain usable. Inputs that
need explicit context can accept EntityIOContext alone or alongside a single
supported data argument, in either order:
[Input]
public void Receive(Entity value, EntityIOContext context)
{
// context.Self: this recipient
// context.Caller: current emitter
// context.Activator: activation cause
// context.OutputId: authored connection ID, or Guid.Empty for a direct call
}
Legacy input handlers can inspect Engine.EntityOutputs.CurrentContext while
executing. Context scopes are nested and restored after exceptions. A caller
starting an independent event should supply its own context. The default context
has no caller or activator. An autonomous output with no explicit activator and
no active input scope has no activation cause. Asynchronous operations must
capture context explicitly (as LogicScript’s scheduled functions do).
var io = Engine.EntityOutputs;
var context = new EntityIOContext(this, activator, this);
io.FireTextInput(context, "gate", "Enable");
io.EnqueueInput("!activator", "Kill", EntityIOValue.Void, 2, context);
var entity = io.Selector.FindFirst("!caller", context);
To disambiguate entity-valued output data from an activator, use the parameter attributes on a delegate:
public delegate void TransferEvent(Entity sender,
[OutputActivator] Entity activator,
[OutputValue] Entity value);
[Output]
public event TransferEvent OnTransfer;
[OutputCaller] marks the sender argument when it is not the first argument.
The bound output owner, not an arbitrary delegate argument, is the actual caller.
Existing delegate signatures retain their conventional role inference. New
ambiguous delegates should use explicit attributes. EmitOutput is also
available as an alternative to firing a CLR event, with explicit activator and
value; do not use both emission paths for the same occurrence.
The LevelEditor exposes the six procedural target names and suggests compatible
inputs. !activator and !picker can resolve different classes at runtime, so
their input suggestions are a union of known inputs, not a guarantee of success.
Entity-valued input parameters offer the same procedural name suggestions.
Max fires is blank to retain Once, -1 for unlimited, or a positive integer.
An explicit limit overrides the legacy once flag. A finite count is consumed
when an output is queued, per connection and emitting entity, even if a future
recipient cannot be found. Override makes an empty parameter an intentional
empty string instead of inheriting the output payload. Nonempty parameters
continue to override the payload without this checkbox.
Level packages can use the optional fields maxFireCount and
overrideParameter in the existing output object. A JSON null parameter with
overrideParameter: true sends explicit null. The grid provides an empty-string
override; author explicit null in JSON. Existing level packages without these
fields retain their former fire-count and parameter rules.
logic_relay is a minimal forwarding entity with Trigger, OnTrigger, and
inherited enable/disable operations. Source-specific relay flags and cancellation
are not implemented here.
ent_fire !player Enable uses the local player as caller and activator when
present. A delay argument routes the request through the shared I/O queue;
existing no-delay console commands remain immediate. Selector completion and
entity inspection use the shared resolver.
engine.call('fire_input', '!activator', 'Increment', 5)
engine.call('fire_input', '!caller', 'Disable', nil, 2)
Lua fire_input(target, input [, value [, delay]]) enqueues a declared input.
Omitting value sends no payload; nil sends explicit null. The current script
becomes the caller, while the incoming activation cause is preserved. Existing
entity lookup bindings also accept procedural selectors. Script callbacks queued
with schedule retain the inbound caller and activator identities.
Run from a checkout with the .NET 9 SDK:
dotnet test XSharp.Tests/XSharp.Tests.csproj --filter 'FullyQualifiedName~LadderGapPhysicsTests'
dotnet build XSharpLevelEditor/XSharpLevelEditor.csproj
The I/O snapshot reader accepts legacy Value/Consumed fields as well as
new typed values and per-source counts. Compatibility of complete old binary save
states and demos (especially serialized LogicScript scheduler state) requires
runtime regression testing. Existing autonomous outputs and content-specific
asynchronous emitters may require explicit context capture or role annotations
for exact Source parity. The new tests cover core propagation, delayed identity,
selector fallback, fire counts, overrides, exception scopes, level loading and
Lua scheduling; the 2-D PVS and picker behavior also need in-game validation.