PhysicsSystem class in Thread

Singleton facade over Jolt Physics. The engine takes care of lifecycle and the per-frame step; user code mostly calls these static functions to apply forces or move kinematic bodies during gameplay.

Lifecycle

Init()boolRegister Jolt types, build the broadphase, allocate temp allocator + job system. Idempotent.
Shutdown()voidTear everything down. Called automatically on app exit.
IsInitialized()boolTrue after Init succeeded.
Step(dt, steps = 1)voidAdvance simulation. Called internally per runtime frame.

Globals

SetGravity(g)voidWorld gravity vector. Default {0, -9.81, 0}.
GetGravity()Thread::Vec3Current gravity.

Body manipulation

AddForce(bodyId, f)voidContinuous force (N). Apply each frame for sustained accel.
AddImpulse(bodyId, imp)voidInstant change of momentum — single-frame for jumps / explosions.
SetLinearVel(bodyId, v)voidOverwrite linear velocity.
SetAngularVel(bodyId, v)voidOverwrite angular velocity (rad/s).
SetBodyTransform(bodyId, p, r)voidTeleport (and re-activate) a body.
GetBodyTransform(bodyId, &p, &r)boolRead current world position/rotation.

Specialised constructors

CreateHeightFieldBody(...)uint32_tUsed internally by TerrainComponent. Resolution must be a multiple of 4.
CreateCharacter(desc)void*Spawns a Jolt CharacterVirtual. Used by CharacterControllerComponent.

Example — one-shot impulse

void OnUpdate(float ts) override {
    if (Input::WasKeyPressed(Key::Space)) {
        auto& rb = GetComponent<Thread::RigidBodyComponent>();
        Thread::PhysicsSystem::AddImpulse(rb.BodyId, Thread::Vec3(0.0f, 8.0f, 0.0f));
    }
}

PhysicsSystem klasa w Thread

Singleton nad Jolt Physics. Silnik dba o cykl życia i krok symulacji co klatkę; kod gry głównie wywołuje te statyczne funkcje, żeby przykładać siły albo przesuwać ciała kinematyczne.

Cykl życia

Init()boolRejestruje typy Jolt, buduje broadphase, przydziela alokator tymczasowy i system zadań. Idempotentne.
Shutdown()voidSprząta wszystko. Wywoływane automatycznie przy wyjściu z aplikacji.
IsInitialized()boolTrue po udanym Init.
Step(dt, steps = 1)voidPrzesuwa symulację. Wywoływane wewnętrznie co klatkę gry.

Ustawienia globalne

SetGravity(g)voidWektor grawitacji świata. Domyślnie {0, -9.81, 0}.
GetGravity()Thread::Vec3Bieżąca grawitacja.

Sterowanie ciałami

AddForce(bodyId, f)voidCiągła siła (N). Przykładaj co klatkę dla stałego przyspieszenia.
AddImpulse(bodyId, imp)voidNatychmiastowa zmiana pędu — jednorazowo przy skokach i wybuchach.
SetLinearVel(bodyId, v)voidNadpisuje prędkość liniową.
SetAngularVel(bodyId, v)voidNadpisuje prędkość kątową (rad/s).
SetBodyTransform(bodyId, p, r)voidTeleportuje (i budzi) ciało.
GetBodyTransform(bodyId, &p, &r)boolOdczytuje bieżącą pozycję/rotację w świecie.

Specjalne konstruktory

CreateHeightFieldBody(...)uint32_tUżywane wewnętrznie przez TerrainComponent. Rozdzielczość musi być wielokrotnością 4.
CreateCharacter(desc)void*Tworzy CharacterVirtual z Jolt. Używane przez CharacterControllerComponent.

Przykład — jednorazowy impuls

void OnUpdate(float ts) override {
    if (Input::WasKeyPressed(Key::Space)) {
        auto& rb = GetComponent<Thread::RigidBodyComponent>();
        Thread::PhysicsSystem::AddImpulse(rb.BodyId, Thread::Vec3(0.0f, 8.0f, 0.0f));
    }
}