Scene class in Thread
Container that owns the EnTT registry, the skybox, scene systems, and the
audio/physics integration. A running game has exactly one active Scene at any
time, reachable via Scene::GetCurrent() or
ScriptableEntity::GetScene().
Static
| GetCurrent() | Scene* | The scene that's currently ticking. |
Entity lifecycle
| CreateEntity(name) | Entity | Spawn entity with TagComponent + TransformComponent + IDComponent. |
| CreateEntityWithUUID(id, name) | Entity | Same, with a specific id. Used by loading — the id is set at construction, because it is the entity's identity rather than a field patched in afterwards. |
| DestroyEntity(entity) | void | Remove the entity and all its components. |
| Clear() | void | Wipe every entity and reset the skybox. |
Finding entities
| FindByUUID(id) | Entity | The entity with that id, or an invalid Entity. An indexed lookup, not a scan — safe to call per frame. |
| FindByName(name) | Entity | Some entity with that name, or an invalid Entity. Linear scan, case-sensitive. |
| FindAllByName(name) | std::vector<Entity> | Every entity with that name. Empty when none match. |
| GetRegistry() | entt::registry& | The raw registry, for views over components (finding by tag, batching). |
An id (IDComponent::ID) is how you store a reference to an entity that must
survive a scene reload or Play/Stop — those rebuild the registry, so a raw handle is meaningless
afterwards. It is what cutscenes, behaviour-tree blackboards and
script reference fields all keep.
if (Thread::Entity target = scene->FindByUUID(id)) {
target.GetComponent<Thread::TransformComponent>().Translation.y += 1.0f;
}
Why there are two name lookups. Names are not unique and nothing enforces that
they should be, so FindByName can only answer “some entity called that” — and it
has no way to tell you that it just made a choice. FindAllByName is how you find out
there was a choice to make.
Which one it picks is entt's iteration order, not the order you authored the scene in, so it can
change when unrelated entities are added or destroyed. A name also does not survive a rename, while
the id does. Use FindByUUID for any reference that has to keep pointing at the same
entity; use these when a name genuinely is the identity you have.
// One boss, by design — and a loud failure if that ever stops being true.
auto bosses = scene->FindAllByName("Boss");
if (bosses.size() != 1)
Thread::Logger::Warn("expected exactly one Boss, found " + std::to_string(bosses.size()));
Frame hooks
| OnUpdateEditor(ts, camera) | void | Render from the editor camera. Audio & physics paused. |
| OnUpdateRuntime(ts, w, h, playing) | void | Full tick — scripts, physics, audio, render. |
| StopAllAudio() | void | Free every OpenAL source held by AudioComponents. |
| StopPhysics() | void | Destroy every Jolt body / character. |
Skybox
| SetSkybox(faces) | void | Load 6 cubemap face PNGs (+X, −X, +Y, −Y, +Z, −Z). |
| GetSkybox() | Skybox* | Current skybox or nullptr. |
Example
Thread::Scene* s = GetScene();
Entity e = s->CreateEntity("Bullet");
e.AddComponent<Thread::PrimitiveComponent>(Thread::PrimitiveType::Sphere);
e.AddComponent<Thread::RigidBodyComponent>().Mass = 0.1f;
e.AddComponent<Thread::SphereColliderComponent>().Radius = 0.1f;
Scene klasa w Thread
Kontener, który posiada rejestr EnTT, skybox, systemy sceny oraz integrację z dźwiękiem i
fizyką. Działająca gra ma w każdej chwili dokładnie jedną aktywną Scene, dostępną przez
Scene::GetCurrent() albo ScriptableEntity::GetScene().
Statyczne
| GetCurrent() | Scene* | Scena, która właśnie tyka. |
Cykl życia encji
| CreateEntity(name) | Entity | Tworzy encję z TagComponent + TransformComponent + IDComponent. |
| CreateEntityWithUUID(id, name) | Entity | To samo, z konkretnym id. Używane przy wczytywaniu — id ustawia się przy tworzeniu, bo jest tożsamością encji, a nie polem poprawianym później. |
| DestroyEntity(entity) | void | Usuwa encję ze wszystkimi komponentami. |
| Clear() | void | Czyści wszystkie encje i resetuje skybox. |
Wyszukiwanie encji
| FindByUUID(id) | Entity | Encja o tym id albo nieważna Entity. Wyszukiwanie po indeksie, nie przeglądanie — bezpieczne co klatkę. |
| FindByName(name) | Entity | Jakaś encja o tej nazwie albo nieważna Entity. Przegląd liniowy, z rozróżnianiem wielkości liter. |
| FindAllByName(name) | std::vector<Entity> | Wszystkie encje o tej nazwie. Pusty, gdy żadna nie pasuje. |
| GetRegistry() | entt::registry& | Surowy rejestr — do widoków po komponentach (szukanie po tagu, przetwarzanie wsadowe). |
Id (IDComponent::ID) to sposób na zapamiętanie odwołania do encji, które ma przetrwać
przeładowanie sceny albo Play/Stop — te odbudowują rejestr, więc surowy uchwyt traci potem sens.
Właśnie id trzymają przerywniki, tablice drzew zachowań i
pola skryptów wskazujące encje.
if (Thread::Entity target = scene->FindByUUID(id)) {
target.GetComponent<Thread::TransformComponent>().Translation.y += 1.0f;
}
Dlaczego są dwa wyszukiwania po nazwie. Nazwy nie są unikalne i nic tego nie
wymusza, więc FindByName może odpowiedzieć tylko „jakaś encja o tej nazwie” — i
nie ma jak powiedzieć, że właśnie dokonało wyboru. FindAllByName pozwala się dowiedzieć,
że był wybór do zrobienia.
Którą wybierze, zależy od kolejności iteracji entt, a nie od kolejności w scenie, więc może się
zmienić, gdy dodasz lub usuniesz niezwiązane encje. Nazwa nie przetrwa też zmiany nazwy, a id tak.
Do odwołań, które mają wskazywać ciągle tę samą encję, używaj FindByUUID; tych używaj,
gdy nazwa naprawdę jest tożsamością, którą masz.
// Jeden boss z założenia — i głośny błąd, jeśli kiedyś przestanie to być prawdą.
auto bosses = scene->FindAllByName("Boss");
if (bosses.size() != 1)
Thread::Logger::Warn("expected exactly one Boss, found " + std::to_string(bosses.size()));
Zaczepy klatki
| OnUpdateEditor(ts, camera) | void | Renderuje z kamery edytora. Dźwięk i fizyka wstrzymane. |
| OnUpdateRuntime(ts, w, h, playing) | void | Pełny tick — skrypty, fizyka, dźwięk, renderowanie. |
| StopAllAudio() | void | Zwalnia wszystkie źródła OpenAL trzymane przez AudioComponent. |
| StopPhysics() | void | Niszczy wszystkie ciała i postacie Jolt. |
Skybox
| SetSkybox(faces) | void | Wczytuje 6 ścian cubemapy PNG (+X, −X, +Y, −Y, +Z, −Z). |
| GetSkybox() | Skybox* | Bieżący skybox albo nullptr. |
Przykład
Thread::Scene* s = GetScene();
Entity e = s->CreateEntity("Bullet");
e.AddComponent<Thread::PrimitiveComponent>(Thread::PrimitiveType::Sphere);
e.AddComponent<Thread::RigidBodyComponent>().Mass = 0.1f;
e.AddComponent<Thread::SphereColliderComponent>().Radius = 0.1f;