#pragma once #include "MinimalEngine.h" #include "Graphics/Graphics.h" #include "Physics/PhysicsSystem.h" #include namespace Seele { DECLARE_REF(Material) DECLARE_REF(Entity) DECLARE_REF(FluidScene) DECLARE_REF(LightEnvironment) class Scene { public: Scene(Gfx::PGraphics graphics); ~Scene(); void bakeLighting(); void update(float deltaTime); entt::entity createEntity() { return registry.create(); } // Out-of-line (Scene.cpp): the bodies need the complete Entity type (they call // getIdentifier() on roster entries). Scene.h only forward-declares Entity // (DECLARE_REF) to keep the header light and to avoid a circular include - // Entity.h includes Scene.h, so Scene.h must not pull Actor/Entity.h back in. void destroyEntity(entt::entity identifier); // The scene is the single source of truth for which entities exist. The editor's // inspector enumerates this roster (non-owning views) to build its entity list - the // whole point of "the scene owns the entity". Populated as entities are created and // pruned as they are destroyed; never points at a live handle that outlives its record. const Array& getEntities() const { return entities; } // Internal: called by Entity's ctor/dtor to keep the roster in lock-step with the // registry. Not part of the public "create/destroy" surface (use createEntity / // destroyEntity for that). void registerEntity(entt::entity identifier, PEntity self) { entities.add(self); } // Out-of-line (Scene.cpp): calls getIdentifier() on roster entries -> needs complete Entity. void unregisterEntity(entt::entity identifier); template Component& attachComponent(entt::entity entity, Args&&... args) { return registry.emplace(entity, std::forward(args)...); } template Component& accessComponent(entt::entity entity) { return registry.get(entity); } template const Component& accessComponent(entt::entity entity) const { return registry.get(entity); } template void view(Func func) requires std::is_invocable_v || std::is_invocable_v { registry.view().each(func); } template auto constructCallback() { return registry.on_construct(); } template auto destroyCallback() { return registry.on_destroy(); } PLightEnvironment getLightEnvironment() { return lightEnv; } PFluidScene getFluidScene() { return fluidScene; } Gfx::PGraphics getGraphics() const { return graphics; } entt::registry registry; private: Gfx::PGraphics graphics; // The roster: the scene's single source of truth for which entities currently exist. // Non-owning views (P* = RefPtr, a plain pointer) - the *owning* O* (OwningPtr) held // by the code that created each actor still owns the C++ object; the roster only tracks // existence so tooling (the editor's inspector) can enumerate entities in handle space. // Kept in lock-step by Entity's ctor (registerEntity) and dtor (routed through // destroyEntity -> unregisterEntity), so it never points at a dead record. Array entities; OLightEnvironment lightEnv; OFluidScene fluidScene; PhysicsSystem physics; Array lightMaps; }; DEFINE_REF(Scene) } // namespace Seele