class Lapis::Core::StaticSignalTable

Overview

Zero-allocation static signal dispatch table.

Stores all signal slots and listener records in pre-allocated flat Slice pools with an intrusive free-list for recycled listener records.

Defined in:

lapis/core/static_signal_table.cr

Constant Summary

DEFAULT_MAX_LISTENERS = 4096
DEFAULT_MAX_SLOTS = 1024
FNV_OFFSET_BASIS = 14695981039346656037_u64
FNV_PRIME = 1099511628211_u64
MAX_STACK_SNAPSHOT = 64

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Object

try?(&)
try?
try?

Constructor Detail

def self.current : StaticSignalTable #

def self.global : StaticSignalTable #

Global singleton dispatch table used by Lapis TypedSignal and signal macros.


def self.new(max_slots : Int32 = DEFAULT_MAX_SLOTS, max_listeners : Int32 = DEFAULT_MAX_LISTENERS) #

Class Method Detail

def self.combine_key(emitter_id : UInt64, signal_hash : UInt64) : UInt64 #

Mixes (emitter_id, signal_hash) into a well-distributed 64-bit probe key.


def self.fnv1a_64(name : String) : UInt64 #

Computes the 64-bit FNV-1a hash of a signal name with zero heap allocations.


def self.hash_signal_name(name : String) : UInt64 #

Alias for .fnv1a_64 used by synthesized signal and on_signal macros.


def self.next_anonymous_emitter_id : UInt64 #

Generates a unique monotonic emitter ID for standalone StaticSignalSlot instances.


def self.reset_global! : Void #

Resets the global dispatch table state in-place without reallocating backing slices.


Instance Method Detail

def active_listener_count(emitter_id : UInt64, signal_name : String) : Int32 #

Returns the number of active listeners for (emitter_id, signal_name).


def active_listener_count_by_hash(emitter_id : UInt64, signal_hash : UInt64) : Int32 #

def active_listeners : Int32 #

def active_slots : Int32 #

def bind(emitter_id : UInt64, signal_name : String, callback : Proc(*T, R), once : Bool = false, subscription : Godot::SignalSubscription | Nil = nil, match_proc_pointer : Pointer(Void) = Pointer(Void).null, match_closure_data : Pointer(Void) = Pointer(Void).null) : UInt64 forall T, R #

Binds a compile-time typed Proc(*T, R) to (emitter_id, signal_name). Returns a unique 64-bit listener token that can be passed to #unbind.


def bind_by_hash(emitter_id : UInt64, signal_hash : UInt64, callback : Proc(*T, R), once : Bool = false, subscription : Godot::SignalSubscription | Nil = nil, match_proc_pointer : Pointer(Void) = Pointer(Void).null, match_closure_data : Pointer(Void) = Pointer(Void).null) : UInt64 forall T, R #

Binds a compile-time typed Proc(*T, R) using a precomputed signal_hash.


def bind_raw(emitter_id : UInt64, signal_name : String, callback : Proc(UInt64, Pointer(Void), Int32, R), once : Bool = false) : UInt64 forall R #

Binds a raw C-ABI / arena-staged callback Proc(UInt64, Pointer(Void), Int32, R).


def clear! : Void #

Resets the entire table in-place with zero heap allocations.


def clear_emitter(emitter_id : UInt64) : Int32 #

Clears all signal slots and listeners associated with emitter_id (as emitter or receiver).


def clear_signal(emitter_id : UInt64, signal_name : String) : Int32 #

Clears all listeners registered for (emitter_id, signal_name).


def connect(emitter_id : UInt64, signal_name : String, type0 : T0.class, type1 : T1.class, type2 : T2.class, type3 : T3.class, once : Bool = false, &block : T0, T1, T2, T3 -> Void) : UInt64 forall T0, T1, T2, T3 #

def connect(emitter_id : UInt64, signal_name : String, type0 : T0.class, type1 : T1.class, once : Bool = false, &block : T0, T1 -> Void) : UInt64 forall T0, T1 #

def connect(emitter_id : UInt64, signal_name : String, type0 : T0.class, type1 : T1.class, type2 : T2.class, once : Bool = false, &block : T0, T1, T2 -> Void) : UInt64 forall T0, T1, T2 #

def connect(emitter_id : UInt64, signal_name : String, once : Bool = false, &block : -> Void) : UInt64 #

Block-based typed connection helpers (0..4 arguments).


def connect(emitter_id : UInt64, signal_name : String, type0 : T0.class, once : Bool = false, &block : T0 -> Void) : UInt64 forall T0 #

def emission_count(emitter_id : UInt64, signal_name : String) : UInt64 #

Returns the total number of emissions recorded for (emitter_id, signal_name).


def emission_count_by_hash(emitter_id : UInt64, signal_hash : UInt64) : UInt64 #

def emit(emitter_id : UInt64, signal_name : String, *args : *T) : Int32 forall T #

Emits a strongly-typed signal by name with strictly ZERO GC heap allocations. Returns the number of active listeners invoked.


def emit_by_hash(emitter_id : UInt64, signal_hash : UInt64, *args : *T) : Int32 forall T #

Emits a strongly-typed signal using a precomputed 64-bit signal_hash with strictly ZERO GC heap allocations.


def emit_payload(emitter_id : UInt64, signal_name : String, value : T, arena : FrameArena = FrameArena.current) : Int32 forall T #

Stages value : T into FrameArena (linear frame scratchpad) and dispatches both typed Proc(T, Void) listeners and raw RawSignalCallback listeners receiving the arena-allocated pointer and sizeof(T) with zero GC heap allocations.


def emit_raw(emitter_id : UInt64, signal_name : String, payload_ptr : Pointer(Void) = Pointer(Void).null, payload_bytes : Int32 = 0) : Int32 #

Emits a raw pointer / byte-sized payload to all RawSignalCallback listeners registered on (emitter_id, signal_name) with zero GC heap allocations.


def emit_standalone_zero_arg(emitter_id : UInt64, signal_name : String) : Int32 #

Dispatches 0-arg listeners bound directly to StaticSignalTable (without a mirroring SignalSubscription) when a signal is emitted via dynamic Object#emit_signal(name).


def has_listeners?(emitter_id : UInt64, signal_name : String) : Bool #

Returns true if (emitter_id, signal_name) has at least one active listener.


def listener_capacity : Int32 #

def once(emitter_id : UInt64, signal_name : String, type0 : T0.class, type1 : T1.class, type2 : T2.class, type3 : T3.class, &block : T0, T1, T2, T3 -> Void) : UInt64 forall T0, T1, T2, T3 #

def once(emitter_id : UInt64, signal_name : String, type0 : T0.class, type1 : T1.class, type2 : T2.class, &block : T0, T1, T2 -> Void) : UInt64 forall T0, T1, T2 #

def once(emitter_id : UInt64, signal_name : String, type0 : T0.class, type1 : T1.class, &block : T0, T1 -> Void) : UInt64 forall T0, T1 #

def once(emitter_id : UInt64, signal_name : String, type0 : T0.class, &block : T0 -> Void) : UInt64 forall T0 #

def once(emitter_id : UInt64, signal_name : String, &block : -> Void) : UInt64 #

One-shot block connection helpers (0..4 arguments).


def slot(emitter_id : UInt64, signal_name : String, t0 : T0.class, t1 : T1.class, t2 : T2.class, t3 : T3.class) : StaticSignalSlot(T0, T1, T2, T3) forall T0, T1, T2, T3 #

def slot(emitter_id : UInt64, signal_name : String, t0 : T0.class, t1 : T1.class, t2 : T2.class) : StaticSignalSlot(T0, T1, T2) forall T0, T1, T2 #

def slot(emitter_id : UInt64, signal_name : String, t0 : T0.class, t1 : T1.class) : StaticSignalSlot(T0, T1) forall T0, T1 #

def slot(emitter_id : UInt64, signal_name : String, t0 : T0.class) : StaticSignalSlot(T0) forall T0 #

def slot(emitter_id : UInt64, signal_name : String) : StaticSignalSlot() #

Returns a typed StaticSignalSlot(*T) handle bound to (emitter_id, signal_name).


def slot_capacity : Int32 #

def standalone_listener_count(emitter_id : UInt64, signal_name : String) : Int32 #

Returns the count of active listeners bound directly to StaticSignalTable without a mirroring Godot::SignalSubscription.


Captures a value-type telemetry snapshot of the table.


def total_emissions : UInt64 #

def unbind(token : UInt64) : Bool #

Unbinds a listener by its 64-bit registration token.


def unbind_proc(emitter_id : UInt64, signal_name : String, proc_ptr : Pointer(Void), closure_ptr : Pointer(Void)) : Bool #

Unbinds the most recently registered active listener matching (proc_ptr, closure_ptr).


def unbind_proc(emitter_id : UInt64, signal_name : String, callback : Proc(*T, R)) : Bool forall T, R #

Unbinds the most recently registered active listener matching callback.


def unbind_proc_by_hash(emitter_id : UInt64, signal_hash : UInt64, proc_ptr : Pointer(Void), closure_ptr : Pointer(Void)) : Bool #

def unbind_proc_by_hash(emitter_id : UInt64, signal_hash : UInt64, callback : Proc(*T, R)) : Bool forall T, R #

Unbinds the most recently registered active listener matching callback by precomputed hash.


def unbind_subscription(sub : Godot::SignalSubscription) : Bool #

Unbinds any listener associated with the given Godot::SignalSubscription.