FlowManagerBase class

Non-template base for FlowManager<TNet,TRollback,TFrame>.

Owns all data and all externally-callable methods. This is the pointer type stored by TrinyxEngine, EditorContext, AuthorityNet, OwnerNet, FlowState, Soul, GameMode, and Construct.

One protected pure-virtual: CreateWorldImpl() — the only virtual called on state transitions (Sentinel thread, not a hot path). LoadLevel is a second override point, used by the concrete template to resolve rollback configuration at compile time.

Derived classes

template<typename TNet, typename TRollback, typename TFrame>
class FlowManager

Public types

using StateFactory = std::function<std::unique_ptr<FlowState>()>
using ModeFactory = std::function<std::unique_ptr<GameMode>()>

Constructors, destructors, conversion operators

FlowManagerBase()
~FlowManagerBase() virtual
FlowManagerBase(const FlowManagerBase&) deleted

Public functions

auto operator=(const FlowManagerBase&) -> FlowManagerBase& deleted
void Initialize(TrinyxEngine* engine, const EngineConfig* config, int windowWidth, int windowHeight)
One-time initialization called by TrinyxEngine after construction.
void RegisterState(const char* name, StateFactory factory)
Register a named state factory. Name is used by LoadState/TransitionTo.
void RegisterMode(const char* name, ModeFactory factory)
Register a named mode factory. Name is used by SetGameMode.
void TransitionTo(const char* stateName)
Replace the entire state stack with a single new state.
void PushState(const char* stateName)
Push an overlay state (pause menu, inventory screen).
void PopState()
Pop the top overlay state.
void LoadDefaultState(const char* stateName)
Load the default state. Called once during engine bootstrap.
auto CreateWorld() -> WorldBase*
Create a fresh World. Non-virtual; calls CreateWorldImpl().
void DestroyWorld()
Destroy the current World and everything scoped to it.
void StartWorld()
Start the World's LogicThread.
void StopWorld()
Signal the World's LogicThread to stop.
void JoinWorld()
Join the World's LogicThread.
void LoadLevel(const char* levelPath, bool bBackground = false) virtual
void LoadLevel(const AssetID& id, bool bBackground = false)
Load a level by AssetID — resolves path via AssetRegistry.
void LoadLevelByName(const char* name, bool bBackground = false)
Load a level by display name.
void UnloadLevel()
Unload the current level.
void OnClientLoaded(uint8_t ownerID)
void OnLocalOwnerConnected(uint8_t ownerID)
void OnClientDisconnected(uint8_t ownerID)
void SpawnLocalPlayer(uint8_t ownerID = 0)
Spawn the local player without a network round-trip.
void OnStreamReady(int64_t, uint16_t, uint8_t) virtual
auto GetSoul(uint8_t ownerID) const -> Soul*
auto EnsureEchoSoul(uint8_t ownerID) -> Soul*
void SetGameMode(const char* modeName)
auto GetGameMode() const -> GameMode*
auto IsGameModeReady() const -> bool
void PostNetEvent(uint8_t eventID)
void PostTravelNotify(const char* levelPath)
void PostPlayerBeginConfirm(const PlayerBeginConfirmPayload& payload)
auto GetPendingPlayerBeginConfirm() const -> PlayerBeginConfirmPayload
auto GetPendingTravelPath() const -> const std::string&
auto GetStreamingManager() const -> StreamingManager*
Returns the engine's StreamingManager, or nullptr if not initialised.
auto GetRawNetThread() const -> void*
void Tick(SimFloat dt)
auto GetActiveState() const -> FlowState*
auto GetWorld() const -> WorldBase*
auto HasWorld() const -> bool
auto GetConfig() const -> const EngineConfig*
void RewireConfig(const EngineConfig* newConfig)
auto GetConstructRegistry() -> ConstructRegistry*
auto GetActiveLevelPath() const -> const std::string&
auto GetActiveLevelLocalPath() const -> std::string

Protected types

struct NamedModeFactory
struct NamedStateFactory

Protected static functions

static void PreloadLevelAssets(const char* path)

Protected functions

void CheckPendingMode()
auto FindStateFactory(const char* name) const -> StateFactory
auto FindModeFactory(const char* name) const -> ModeFactory
void EnforceRequirements(FlowState* currentState, FlowState* nextState)
auto CreateWorldImpl() -> WorldBase* pure virtual
Implemented by FlowManager<TNet,TRollback,TFrame> — creates the typed World.

Protected static variables

static uint32_t MaxStateStack constexpr
static uint32_t MaxRegisteredStates constexpr
static uint32_t MaxRegisteredModes constexpr

Protected variables

std::unique_ptr<FlowState> StateStack
uint32_t StateStackCount
NamedStateFactory RegisteredStates
uint32_t RegisteredStateCount
NamedModeFactory RegisteredModes
uint32_t RegisteredModeCount
ConstructRegistry ConstructReg
std::unique_ptr<Soul> Souls
std::unique_ptr<WorldBase> ActiveWorld
std::unique_ptr<GameMode> ActiveMode
std::unique_ptr<GameMode> PendingMode
TrinyxJobs::JobCounter PendingPreloadCounter
std::string ActiveLevelPath
std::string PendingTravelPath
PlayerBeginConfirmPayload PendingPlayerBeginConfirm
TrinyxEngine* Engine
const EngineConfig* Config
int WindowWidth
int WindowHeight
std::atomic<uint32_t> PendingNetEvents
uint32_t PendingPlayerJoins

Function documentation

void FlowManagerBase::LoadLevel(const char* levelPath, bool bBackground = false) virtual

Load a level (.tnxscene) into the current World. Virtual — overridden by FlowManager<> to use if constexpr(TRollback::Enabled).

void FlowManagerBase::SpawnLocalPlayer(uint8_t ownerID = 0)

Spawn the local player without a network round-trip.

Collapses the Authority's LevelReady → PlayerBegin → Confirm sequence into one synchronous call for solo/standalone mode. Equivalent outcome: Soul created, GameMode::OnPlayerBeginRequest called (which spawns the Construct and calls soul.ClaimBody), then the input accumulator opened.

Requires the Logic thread to be running. Call from a FlowState::OnEnter after SetGameMode, i.e. from PostStart context or later.

void FlowManagerBase::OnStreamReady(int64_t, uint16_t, uint8_t) virtual

Called by AuthorityNet when a client sends StreamReady for a non-auto-activate chunk. Override or wire GameMode logic to call AuthorityNet::SendChunkActivate when ready.

bool FlowManagerBase::IsGameModeReady() const

True once the pending GameMode's OnPreload() has finished and AreUploadsReady() returns true. ReplicationSystem gates ServerReady on this. Returns true immediately when no mode is pending (solo/headless worlds aren't blocked).

void* FlowManagerBase::GetRawNetThread() const

Returns the active net thread as a void* to avoid including TrinyxEngine.h in the template header. FlowManager<TNet> static_casts this to the concrete NetThreadType.

static void FlowManagerBase::PreloadLevelAssets(const char* path) protected

Scan a level JSON file and demand-load all named asset references via TriggerLoad(). Called by FlowManager::LoadLevel before SpawnFromFile so assets are ready when entities spawn.