WorldBase class

Non-template base class for all World specializations.

Owns: Registry, JoltPhysics, LogicThread (via LogicThreadBase), input buffers, and the world-scoped job queue handle. Does not own Vulkan resources, SDL_Window, MeshManager, or TrinyxJobs — those are shared across worlds by TrinyxEngine.

Derived classes

template<typename TNet, typename TRollback, typename TFrame>
class World
Typed simulation container that binds a concrete LogicThread policy triple.

Constructors, destructors, conversion operators

WorldBase()
~WorldBase() virtual
WorldBase(const WorldBase&) deleted

Public functions

auto operator=(const WorldBase&) -> WorldBase& deleted
void Start()
Spawn and start the LogicThread (Brain). Jobs must be initialized before calling.
void Stop()
Signal the LogicThread to stop at the end of the current frame.
void Join()
Block the caller until the LogicThread exits.
void Shutdown()
Shut down and destroy all owned subsystems.
void SpawnAndWait(LAMBDA lambda)
Submit a job to the world queue, blocking the caller until it completes.
void PostAndWait(LAMBDA lambda)
Alias for SpawnAndWait.
void Spawn(LAMBDA lambda, TrinyxJobs::JobCounter* counter)
Submit a job with a counter for dependency tracking.
void Post(LAMBDA lambda)
Fire-and-forget job submission — no dependency tracking.
auto GetWorldQueue() const -> TrinyxJobs::WorldQueueHandle
Returns the world-scoped job queue handle.
auto GetRegistry() const -> Registry*
auto GetPhysics() const -> JoltPhysics*
auto GetLogicThread() const -> LogicThreadBase*
auto GetSimInput() -> InputBuffer*
auto GetVizInput() -> InputBuffer*
auto GetInputForPlayer(uint8_t ownerID) -> InputBuffer*
Engine-internal: returns the correct sim input buffer for ownerID.
auto GetVizInputForPlayer(uint8_t ownerID) -> InputBuffer*
Engine-internal: returns the correct viz input buffer for ownerID.
auto GetPlayerSimInput(uint8_t ownerID) -> InputBuffer*
Engine-internal: returns the injected net sim buffer for a remote player slot.
auto GetPlayerVizInput(uint8_t ownerID) -> InputBuffer*
Returns the viz input buffer for a remote player slot, or nullptr if unallocated.
void EnsurePlayerInputSlot(uint8_t ownerID)
Grow player input slot vectors to accommodate ownerID (1-based).
auto GetInputAccumRing() -> TrinyxMPSCRing<NetInputFrame>&
MPSC ring for outbound input accumulation (client-side only).
auto GetInputAccumConsumer() -> TrinyxMPSCRing<NetInputFrame>::Consumer*
Returns the net-thread consumer for the input accumulator ring, or nullptr if not issued.
void EnableInputAccum()
Open the input accumulator gate. Call once at PlayerBeginConfirm (Playing state).
auto IsInputAccumEnabled() const -> bool
auto GetInputTargets() const -> std::span<InputBuffer*const>
Returns both input targets (SimInput, VizInput) for batch routing.
auto GetConfig() const -> const EngineConfig&
auto GetConfigMut() -> EngineConfig&
auto GetConstructRegistry() -> ConstructRegistry*
auto GetReplicationSystem() const -> ReplicationSystem*
void SetReplicationSystem(ReplicationSystem* repl)
void EnqueueCorrections(std::vector<EntityTransformCorrection>, uint32_t) virtual
Base no-op for rollback correction queuing.
void EnqueuePredictedCorrections(std::vector<EntityTransformCorrection>) virtual
Base no-op for predicted correction queuing; overridden when rollback is enabled.
void EnqueueSpawnRollback(uint32_t) virtual
Base no-op for spawn-triggered rollback; overridden when rollback is enabled.
void BindAuthorityNet(AuthorityNet*, NetConnectionManager*) virtual
Base no-op for Authority net binding.
auto GetFlowManager() const -> FlowManagerBase*
Returns the FlowManagerBase that owns this World.
void SetFlowManager(FlowManagerBase* flow)
Set by FlowManagerBase::CreateWorld — do not call externally.
void SetJobsInitialized(bool v)
Set by the engine after the job system is initialized. Logic thread polls this gate.
auto GetJobsInitialized() const -> bool
void TriggerAudio(TnxName name, float volume = 1.f, float pitch = 1.f, bool loop = false)
Post an audio playback command from any thread.
auto GetAudioCmdConsumer() -> TrinyxMPSCRing<AudioCommand>::Consumer*
Returns the Sentinel-side consumer for the audio command ring, or nullptr if not issued.
auto GetLocalOwnerID() const -> uint8_t
Local Owner ID: 0 = Authority/Solo, 1–255 = client slot.
void SetLocalOwnerID(uint8_t id)
Assign the local Owner ID. Called once at handshake.
auto GetServerFrameOffset() const -> uint32_t
Frame delta to convert a local logic frame to the equivalent Authority frame.
void SetServerFrameOffset(uint32_t offset)
void ResetRegistry() const
Test-only: wipe all entities, handles, and caches.
void ConfirmLocalRecycles() const
Advance the local handle free-pool after the safety window.

Public variables

ContactEventFn OnContactEvent
Physics contact event multicast; listeners invoked on the Logic thread after PullActiveTransforms.

Protected functions

auto InitBase(const EngineConfig& config, ConstructRegistry* constructRegistry, int windowWidth, int windowHeight) -> bool
Initialize all owned subsystems except LogicThread (created by the derived World<>).

Protected variables

EngineConfig Config
std::unique_ptr<Registry> RegistryPtr
std::unique_ptr<JoltPhysics> Physics
std::unique_ptr<LogicThreadBase> Logic
Ownership; World<> std::moves the typed instance here.
InputBuffer SimInput
InputBuffer VizInput
std::vector<std::unique_ptr<InputBuffer>> PlayerSimInputs
Per-slot sim buffers for remote players (ownerID - 1 indexed).
std::vector<std::unique_ptr<InputBuffer>> PlayerVizInputs
Per-slot viz buffers for remote players (ownerID - 1 indexed).
InputBuffer* InputTargets
TrinyxJobs::WorldQueueHandle WQHandle
TrinyxMPSCRing<NetInputFrame> InputAccumRing
Client outbound input ring.
std::optional<TrinyxMPSCRing<NetInputFrame>::Consumer> InputAccumConsumer
Net-thread consumer handle.
TrinyxMPSCRing<AudioCommand> AudioCmdRing
Audio command ring (any thread → Sentinel).
std::optional<TrinyxMPSCRing<AudioCommand>::Consumer> AudioCmdConsumer
Sentinel consumer handle.
ConstructRegistry* Constructs
Non-owning — FlowManager owns the registry.
ReplicationSystem* Replicator
Non-owning — TrinyxEngine or EditorContext owns it.
FlowManagerBase* FlowMgr
Non-owning — set by FlowManagerBase::CreateWorld.
uint32_t ServerFrameOffset
Local→Authority frame delta; set by OwnerNet at handshake.
std::atomic<bool> bJobsInitialized
std::atomic<bool> bInputAccumEnabled
Gated to true at PlayerBeginConfirm (client-side only).

Function documentation

template<TrinyxJobs::ValidJobLambda LAMBDA>
void WorldBase::SpawnAndWait(LAMBDA lambda)

Submit a job to the world queue, blocking the caller until it completes.

Executes inline on the calling thread if the Logic thread is not yet running or the job system has not been initialized — avoids deadlock during engine startup.

InputBuffer* WorldBase::GetInputForPlayer(uint8_t ownerID)

Engine-internal: returns the correct sim input buffer for ownerID.

InputBuffer* WorldBase::GetVizInputForPlayer(uint8_t ownerID)

Engine-internal: returns the correct viz input buffer for ownerID.

InputBuffer* WorldBase::GetPlayerSimInput(uint8_t ownerID)

Engine-internal: returns the injected net sim buffer for a remote player slot.

Returns nullptr if the slot is unallocated — call EnsurePlayerInputSlot() first.

TrinyxMPSCRing<NetInputFrame>& WorldBase::GetInputAccumRing()

MPSC ring for outbound input accumulation (client-side only).

Logic thread pushes one NetInputFrame per sim frame at ProcessSimInput time. Net thread drains via the issued Consumer. The ring rejects pushes until EnableInputAccum() is called at Playing state.

void WorldBase::EnqueueCorrections(std::vector<EntityTransformCorrection>, uint32_t) virtual

Base no-op for rollback correction queuing.

void WorldBase::BindAuthorityNet(AuthorityNet*, NetConnectionManager*) virtual

Base no-op for Authority net binding.

void WorldBase::TriggerAudio(TnxName name, float volume = 1.f, float pitch = 1.f, bool loop = false)

Post an audio playback command from any thread.

void WorldBase::SetLocalOwnerID(uint8_t id)

Assign the local Owner ID. Called once at handshake.

uint32_t WorldBase::GetServerFrameOffset() const

Frame delta to convert a local logic frame to the equivalent Authority frame.