Core module
SoA storage substrate: FieldProxy, component schema, temporal ring buffers, archetype chunks, logic-thread coordination, engine bootstrap.
Namespaces
- namespace TVecDetail
- namespace Internal
- Engine-internal global counters. Do not access directly from gameplay code.
Classes
- struct EngineConfig
- Runtime configuration for a TrinyxEngine instance.
-
template<typename Ret, typename... Args>struct Callback
- Type-erased single-binding delegate — stores one member function or free function.
-
template<typename CB, bool Fixed, size_t MaxBinds>struct MultiCallbackStorage
- Fixed-capacity storage backend for MultiCallback —
MaxBindsslots in astd::array. -
template<typename CB, size_t MaxBinds>struct MultiCallbackStorage<CB, true, MaxBinds>
-
template<typename CB, size_t MaxBinds>struct MultiCallbackStorage<CB, false, MaxBinds>
- Dynamic-capacity storage backend for MultiCallback — bindings live in a
std::vector. -
template<typename Ret, bool Fixed, size_t MaxBinds = 16, typename... Args>struct MultiCallback
- Multi-binding delegate — dispatches to
MaxBindssimultaneous listeners. -
template<typename Derived>class GameManager
- CRTP base for user game projects; provides default lifecycle hooks and window config.
-
template<typename TNet, typename TRollback, typename TFrame>class World
- Typed simulation container that binds a concrete LogicThread policy triple.
-
template<typename TNet, typename TRollback, typename TFrame>class FlowManager
-
template<typename TNet, typename TRollback, typename TFrame>class LogicThread
- The Brain — fixed-timestep simulation coordinator for one World.
- class LogicThreadBase
- Non-template base class for all LogicThread<> specializations.
- struct GameFrame
- TFrameMode policy tag for
LogicThread— pure tag types, no methods. - struct EditorFrame
- Editor/PIE frame; unlocks scene snapshot, tick-pause, and PIE hooks.
- struct SoloSim
- TNetMode policy tag for
LogicThread— controls input injection and replication dispatch. - struct NoRollback
- TRollbackMode policy for
LogicThread— no rollback history, zero overhead. - struct RollbackSim
- TRollbackMode policy for
LogicThread— owns all rollback state and logic. - class TrinyxEngine
- The Sentinel — main-thread owner of all engine subsystems.
-
template<typename VecType = SimFloat>struct TVector3
- 3-component vector parameterized on a scalar type.
-
template<typename VecType = SimFloat>struct TQuat
- Unit quaternion parameterized on a scalar type.
-
template<typename MatType = SimFloat>struct TMatrix4
- 4×4 column-major matrix parameterized on a scalar type.
- struct AudioCommand
- Audio playback command posted from any thread; Sentinel drains before AudioManager::Update.
- class WorldBase
- Non-template base class for all World specializations.
-
template<FieldWidth WIDTH>struct FieldProxyMask
-
template<>struct FieldProxyMask<FieldWidth::Scalar>
-
template<typename FieldType, FieldWidth WIDTH>struct FieldProxy
Enums
- enum class FieldWidth: uint8_t { Scalar, Wide, WideMask }
- Selects the storage and update path for a FieldProxy.
- enum class CacheTier: uint8_t { None = 0, Volatile = 1, Temporal = 2, Universal = 3, MAX }
- Identifies which SoA ring-buffer tier an entity's fields live in.
- enum class EngineMode: uint8_t { Standalone, Client, Server, Host }
- Determines what subsystems are initialized for this process.
- enum class ConstructLifetime: uint8_t { Level, World, Session, Persistent }
- Lifetime tier of a Construct — determines survival across level transitions and World resets.
Typedefs
- using DefaultNet = SoloSim
- Offline sim — default when no net model is set.
- using DefaultRollback = RollbackSim
- Rollback enabled via TNX_ENABLE_ROLLBACK.
- using DefaultFrame = GameFrame
- Frame policy for this build.
- using WorldType = World<DefaultNet, DefaultRollback, DefaultFrame>
- Canonical world type for this build configuration.
- using FlowManagerType = FlowManager<DefaultNet, DefaultRollback, DefaultFrame>
- Canonical FlowManager type for this build configuration.
- using PIEServerNet = AuthoritySim
- PIE Authority net policy.
- using PIEServerRollback = RollbackSim
- PIE server always runs rollback for reconciliation.
- using PIEClientNet = OwnerSim
- PIE Owner net policy.
- using PIEClientRollback = DefaultRollback
- PIE client follows the build's rollback setting.
- using PIEServerWorld = World<PIEServerNet, PIEServerRollback, DefaultFrame>
- PIE Authority world type.
- using PIEClientWorld = World<PIEClientNet, PIEClientRollback, DefaultFrame>
- PIE Owner world type.
- using PIELocalWorld = World<SoloSim, RollbackSim, DefaultFrame>
- PIE local/solo world type.
- using PIEServerFlow = FlowManager<PIEServerNet, PIEServerRollback, DefaultFrame>
- PIE Authority FlowManager type.
- using PIEClientFlow = FlowManager<PIEClientNet, PIEClientRollback, DefaultFrame>
- PIE Owner FlowManager type.
- using PIELocalFlow = FlowManager<SoloSim, RollbackSim, DefaultFrame>
- PIE local/solo FlowManager type.
- using MaskTemplate = Derived<WIDTH>
- using Vector3 = TVector3<>
- Simulation-space 3-vector (SimFloat components).
- using Vector3f = TVector3<float>
- Float-component 3-vector for render/upload code.
- using Quat = TQuat<>
- Simulation-space quaternion (SimFloat components).
- using Quatf = TQuat<float>
- Float-component quaternion for render/upload code.
- using Matrix4 = TMatrix4<>
- Simulation-space 4×4 matrix (SimFloat elements).
- using Matrix4f = TMatrix4<float>
- Float-element 4×4 matrix for render/upload code.
- using ComponentTypeID = uint32_t
- Numeric identifier for a component type.
- using CacheSlotID = uint8_t
- Slot index within a ComponentCacheBase — which SoA column a component occupies.
-
using ComponentSignature = FixedBitset<MAX_
COMPONENTS> - Bitmask tracking which component types are present on an archetype.
- using ClassID = uint16_t
- Per-Construct-type numeric class identifier.
- using ContactEventFn = MultiCallback<void, true, 8, const PhysicsContactEvent&>
- Fixed-capacity multicast delegate for physics contact events.
Functions
-
template<typename T>auto Sqrt(SimFloatImpl<T> x) -> SimFloatImpl<T>
-
template<typename VecType>auto Dot(const TVector3<VecType>& a, const TVector3<VecType>& b) -> VecType
- Dot product of two same-type vectors.
-
template<typename VecType>auto Cross(const TVector3<VecType>& a, const TVector3<VecType>& b) -> TVector3<VecType>
- Cross product of two same-type vectors.
-
template<typename TLogic>void ProcessRollback(TLogic& logic)
- Drains incoming rings and triggers resimulation if corrections are pending.
-
template<typename TLogic>void ExecuteRollback(TLogic& logic, uint32_t targetFrame)
- Restores Jolt + SoA state to
targetFrameand resimulates forward. -
template<typename TLogic>void ExecuteRollbackTest(TLogic& logic)
- Determinism self-test: resimulates the last N frames and diffs against saved ground truth.
-
template<typename GameClass>void Run(GameClass& game)
- Start all threads and run the main loop until the window is closed.
Variables
- int32_t FixedUnitsPerMeter constexpr
- Simulation units per meter. 1 unit = 0.1 mm; int32 range covers ±214 km.
- int32_t FixedUnitsPerRadian constexpr
- Simulation units per unit-range value (2^28). Used by FixedUnit for quaternion components and trig output. Range ±8 gives headroom above [-1,1] for unnormalized intermediates.
- static const char* EngineModeNames
- static size_t MAX_COMPONENTS constexpr
- Maximum distinct component types.
- static size_t MAX_TEMPORAL_FIELDS_PER_COMPONENT constexpr
- Max decomposed temporal SoA fields per component.
- static size_t MAX_FIELD_ARRAYS constexpr
- static size_t MAX_FIELDS_PER_ARCHETYPE constexpr
- Upper bound on field arrays for any single archetype (temporal + non-temporal).
- static size_t MAX_CLASS_COUNT constexpr
- Hard limit based on the ClassID field width in Entity headers.
- uint32_t CHUNK_SIZE constexpr
- Nominal chunk size in bytes — ~32 entities if each has 64 fields of 4 bytes in chunk storage.
Defines
- #define DEFINE_FIXED_MULTICALLBACK(FuncName, Size, ...)
- Declares a fixed-capacity MultiCallback type with void return.
- #define DEFINE_MULTICAST_CALLBACK(FuncName, ...)
- Declares a dynamically-growing MultiCallback type with void return and default capacity 16.
- #define DEFINE_CALLBACK_RET(RetVal, FuncName, ...)
- Declares a single-binding Callback type with a custom return type.
- #define DEFINE_CALLBACK(FuncName, ...)
- Declares a single-binding Callback type with void return.
- #define DEFINE_CALLBACK_VOID(FuncName)
- #define TNX_PROJECT_DIR
- Provides
main()and wiresParseCommandLine → Initialize → PostInitialize → Run. - #define TNX_IMPLEMENT_GAME(GameClass)
- #define FORCE_INLINE
- Force-inline attribute —
__forceinlineon MSVC,always_inlineon GCC/Clang. - #define TNX_CTZ32(x)
- #define TNX_CTZ64(x)
- #define TNX_POPCOUNT32(x)
Enum documentation
enum class FieldWidth: uint8_t
#include <Runtime/Core/Public/Types.h>
Selects the storage and update path for a FieldProxy.
| Enumerators | |
|---|---|
| Scalar |
Single-entity scalar update path. |
| Wide |
AVX2 8-wide SIMD unconditional store. |
| WideMask |
AVX2 8-wide SIMD masked store (gated on the Active flag). |
enum class CacheTier: uint8_t
#include <Runtime/Core/Public/Types.h>
Identifies which SoA ring-buffer tier an entity's fields live in.
| Enumerators | |
|---|---|
| None |
No SoA tier — cold/chunk-only data, not iterable by wide sweeps. |
| Volatile |
3-frame ring buffer — cosmetic entities, ambient AI, particles (no rollback). |
| Temporal |
N-frame ring buffer — simulation-authoritative, rollback-capable. |
| Universal |
N-frame ring buffer — grows as needed; fields shared by all entities. |
| MAX |
|
enum class EngineMode: uint8_t
#include <Runtime/Core/Public/Types.h>
Determines what subsystems are initialized for this process.
| Enumerators | |
|---|---|
| Standalone |
No networking — singleplayer / editor default. |
| Client |
Connects to a remote Authority; renders locally. |
| Server |
Headless Authority — no window, no Vulkan, no renderer. |
| Host |
Authority + Owner in one process — listen-server / PIE default. |
enum class ConstructLifetime: uint8_t
#include <Runtime/Core/Public/Types.h>
Lifetime tier of a Construct — determines survival across level transitions and World resets.
| Enumerators | |
|---|---|
| Level |
Destroyed when the Level unloads. |
| World |
Destroyed when the World resets. |
| Session |
Survives World reset; destroyed when the session ends. |
| Persistent |
Survives everything; destroyed only explicitly. |
Typedef documentation
using DefaultNet = SoloSim
#include <Runtime/Core/Public/Globals.h>
Offline sim — default when no net model is set.
using DefaultRollback = RollbackSim
#include <Runtime/Core/Public/Globals.h>
Rollback enabled via TNX_ENABLE_ROLLBACK.
using DefaultFrame = GameFrame
#include <Runtime/Core/Public/Globals.h>
Frame policy for this build.
using WorldType = World<DefaultNet, DefaultRollback, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
Canonical world type for this build configuration.
using FlowManagerType = FlowManager<DefaultNet, DefaultRollback, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
Canonical FlowManager type for this build configuration.
using PIEServerNet = AuthoritySim
#include <Runtime/Core/Public/Globals.h>
PIE Authority net policy.
using PIEServerRollback = RollbackSim
#include <Runtime/Core/Public/Globals.h>
PIE server always runs rollback for reconciliation.
using PIEClientNet = OwnerSim
#include <Runtime/Core/Public/Globals.h>
PIE Owner net policy.
using PIEClientRollback = DefaultRollback
#include <Runtime/Core/Public/Globals.h>
PIE client follows the build's rollback setting.
using PIEServerWorld = World<PIEServerNet, PIEServerRollback, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
PIE Authority world type.
using PIEClientWorld = World<PIEClientNet, PIEClientRollback, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
PIE Owner world type.
using PIELocalWorld = World<SoloSim, RollbackSim, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
PIE local/solo world type.
using PIEServerFlow = FlowManager<PIEServerNet, PIEServerRollback, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
PIE Authority FlowManager type.
using PIEClientFlow = FlowManager<PIEClientNet, PIEClientRollback, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
PIE Owner FlowManager type.
using PIELocalFlow = FlowManager<SoloSim, RollbackSim, DefaultFrame>
#include <Runtime/Core/Public/Globals.h>
PIE local/solo FlowManager type.
#include <Runtime/Core/Public/Types.h>
using MaskTemplate = Derived<WIDTH>
using Vector3 = TVector3<>
#include <Runtime/Core/Public/Types.h>
Simulation-space 3-vector (SimFloat components).
using Vector3f = TVector3<float>
#include <Runtime/Core/Public/Types.h>
Float-component 3-vector for render/upload code.
using Quat = TQuat<>
#include <Runtime/Core/Public/Types.h>
Simulation-space quaternion (SimFloat components).
using Quatf = TQuat<float>
#include <Runtime/Core/Public/Types.h>
Float-component quaternion for render/upload code.
using Matrix4 = TMatrix4<>
#include <Runtime/Core/Public/Types.h>
Simulation-space 4×4 matrix (SimFloat elements).
using Matrix4f = TMatrix4<float>
#include <Runtime/Core/Public/Types.h>
Float-element 4×4 matrix for render/upload code.
using ComponentTypeID = uint32_t
#include <Runtime/Core/Public/Types.h>
Numeric identifier for a component type.
using CacheSlotID = uint8_t
#include <Runtime/Core/Public/Types.h>
Slot index within a ComponentCacheBase — which SoA column a component occupies.
using ComponentSignature = FixedBitset<MAX_ COMPONENTS>
#include <Runtime/Core/Public/Types.h>
Bitmask tracking which component types are present on an archetype.
using ClassID = uint16_t
#include <Runtime/Core/Public/Types.h>
Per-Construct-type numeric class identifier.
using ContactEventFn = MultiCallback<void, true, 8, const PhysicsContactEvent&>
#include <Runtime/Core/Public/WorldBase.h>
Fixed-capacity multicast delegate for physics contact events.
Function documentation
#include <Runtime/Core/Public/Types.h>
template<typename T>
SimFloatImpl<T> Sqrt(SimFloatImpl<T> x)
#include <Runtime/Core/Public/Types.h>
template<typename VecType>
VecType Dot(const TVector3<VecType>& a,
const TVector3<VecType>& b)
Dot product of two same-type vectors.
#include <Runtime/Core/Public/Types.h>
template<typename VecType>
TVector3<VecType> Cross(const TVector3<VecType>& a,
const TVector3<VecType>& b)
Cross product of two same-type vectors.
template<typename TLogic>
void ProcessRollback(TLogic& logic)
Drains incoming rings and triggers resimulation if corrections are pending.
| Template parameters | |
|---|---|
| TLogic | Concrete LogicThread specialization. |
| Parameters | |
| logic | The concrete LogicThread instance that owns this policy. |
Called once per logic tick to drain corrections and trigger rollback if needed.
Prunes stale server events, drains IncomingCorrections, merges any pending spawn-rollback frame, then calls ExecuteRollback if the earliest correction or spawn event predates the current frame.
template<typename TLogic>
void ExecuteRollback(TLogic& logic,
uint32_t targetFrame)
Restores Jolt + SoA state to targetFrame and resimulates forward.
| Template parameters | |
|---|---|
| TLogic | Concrete LogicThread specialization. |
| Parameters | |
| logic | |
| targetFrame | The simulation frame to rewind to. |
Rewind to targetFrame and resimulate forward to the current frame.
Restores the nearest Jolt snapshot at or before targetFrame, rewinds the ECS slab write pointer, replays server events, then iterates the resim loop — injecting stored input and applying EntityTransformCorrection entries at the correct frame. Uses dirty-filtered scalar sweeps to skip unchanged entities.
template<typename TLogic>
void ExecuteRollbackTest(TLogic& logic)
Determinism self-test: resimulates the last N frames and diffs against saved ground truth.
| Template parameters | |
|---|---|
| TLogic | Concrete LogicThread specialization. |
| Parameters | |
| logic | The concrete LogicThread instance that owns this policy. |
Determinism test: roll back RollbackFrameCount frames and compare against ground truth.
Under TNX_TESTING, backs up the current slab and Jolt state, calls ExecuteRollback, then does a byte-perfect memcmp of the resimulated field data against the saved ground truth. Reports per-field divergences and Jolt state mismatches. Restores the original simulation state before returning.
#include <Runtime/Core/Public/TrinyxEngine.h>
template<typename GameClass>
void Run(GameClass& game)
Start all threads and run the main loop until the window is closed.
| Template parameters | |
|---|---|
| GameClass | A GameManager subclass; its PostStart is called after threads are ready. |
Calls game.PostStart after Logic/Render threads and the job pool are fully initialized, then loads Config.DefaultState if set (non-editor builds only). Calls Shutdown before returning.
Variable documentation
int32_t FixedUnitsPerMeter constexpr
#include <Runtime/Core/Public/Globals.h>
Simulation units per meter. 1 unit = 0.1 mm; int32 range covers ±214 km.
int32_t FixedUnitsPerRadian constexpr
#include <Runtime/Core/Public/Globals.h>
Simulation units per unit-range value (2^28). Used by FixedUnit for quaternion components and trig output. Range ±8 gives headroom above [-1,1] for unnormalized intermediates.
static const char* EngineModeNames
#include <Runtime/Core/Public/Types.h>
static size_t MAX_COMPONENTS constexpr
#include <Runtime/Core/Public/Types.h>
Maximum distinct component types.
static size_t MAX_TEMPORAL_FIELDS_PER_COMPONENT constexpr
#include <Runtime/Core/Public/Types.h>
Max decomposed temporal SoA fields per component.
static size_t MAX_FIELD_ARRAYS constexpr
#include <Runtime/Core/Public/Types.h>
Max total field arrays across all components.
static size_t MAX_FIELDS_PER_ARCHETYPE constexpr
#include <Runtime/Core/Public/Types.h>
Upper bound on field arrays for any single archetype (temporal + non-temporal).
static size_t MAX_CLASS_COUNT constexpr
#include <Runtime/Core/Public/Types.h>
Hard limit based on the ClassID field width in Entity headers.
uint32_t CHUNK_SIZE constexpr
#include <Runtime/Core/Public/Types.h>
Nominal chunk size in bytes — ~32 entities if each has 64 fields of 4 bytes in chunk storage.
Define documentation
#define DEFINE_FIXED_MULTICALLBACK(FuncName,
Size,
...)
#include <Runtime/Core/Public/Events.h>
Declares a fixed-capacity MultiCallback type with void return.
| Parameters | |
|---|---|
| FuncName | Name of the resulting type alias. |
| Size | Maximum number of simultaneous bindings (compile-time, stored in-place). |
| ... | |
#define DEFINE_MULTICAST_CALLBACK(FuncName,
...)
#include <Runtime/Core/Public/Events.h>
Declares a dynamically-growing MultiCallback type with void return and default capacity 16.
| Parameters | |
|---|---|
| FuncName | Name of the resulting type alias. |
| ... | |
#define DEFINE_CALLBACK_RET(RetVal,
FuncName,
...)
#include <Runtime/Core/Public/Events.h>
Declares a single-binding Callback type with a custom return type.
| Parameters | |
|---|---|
| RetVal | Return type of the callback. |
| FuncName | Name of the resulting type alias. |
| ... | |
#define DEFINE_CALLBACK(FuncName,
...)
#include <Runtime/Core/Public/Events.h>
Declares a single-binding Callback type with void return.
| Parameters | |
|---|---|
| FuncName | Name of the resulting type alias. |
| ... | |
#define DEFINE_CALLBACK_VOID(FuncName)
#include <Runtime/Core/Public/Events.h>
#define TNX_PROJECT_DIR
#include <Runtime/Core/Public/GameManager.h>
Provides main() and wires ParseCommandLine → Initialize → PostInitialize → Run.
Place in exactly one .cpp in your game project.
#define TNX_IMPLEMENT_GAME(GameClass)
#include <Runtime/Core/Public/GameManager.h>
#define FORCE_INLINE
#include <Runtime/Core/Public/Types.h>
Force-inline attribute — __forceinline on MSVC, always_inline on GCC/Clang.
#define TNX_CTZ32(x)
#include <Runtime/Core/Public/Types.h>
#define TNX_CTZ64(x)
#include <Runtime/Core/Public/Types.h>
#define TNX_POPCOUNT32(x)
#include <Runtime/Core/Public/Types.h>