Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
SceneManager.h
Go to the documentation of this file.
1#pragma once
6
7#include <functional>
8#include <utility>
9#include <vector>
10using scene_object_id = uint32_t;
11
12namespace Engine::Core
13{
14 class AssetManager;
15 class ApplicationContext;
16
22 {
23 public:
26
31 std::vector<Entities::Actor *> getAllActors();
36 std::vector<Entities::Entity *> getAllEntities();
37
43 template <typename T>
44 std::vector<T *> getAllComponentsOfClassFromActors();
45
53 void unregisterGameObject( const Components::Mesh * gameObject );
54
58 [[nodiscard]] uint32_t getGameObjectCount() const
59 {
60 return gameObjects.size();
61 }
62
63 [[nodiscard]] const std::vector<Components::Mesh *> & getGameObjects() const;
64 [[nodiscard]] const Components::Mesh * getGameObject( const scene_object_id id ) const;
65 [[nodiscard]] const Vulkan::Buffer & getMeshletToObjectBuffer() const;
66
67 void cleanup();
68
77
86 template <typename T>
87 void loadScene();
88 void loadScene( std::function<Entities::Scene *()> createScene );
89
94 [[nodiscard]] bool isSceneChangePending() const;
95
100
105
109 void clear();
110
111 [[nodiscard]] Entities::Scene * getActiveScene() const { return activeScene; }
113
119
120 private:
122 std::vector<Components::Mesh *> gameObjects = {};
123
124 std::vector<uint32_t> gameObjectToMeshletMap{};
125
126 std::optional<Vulkan::Buffer> meshletToObjectMapBuffer{};
127
129
131
133 std::function<void()> pendingSceneLoad;
134
135 void loadSceneContent() const;
136 };
137
138 template <typename T>
140 {
141 if (!activeScene) return {};
142 std::vector<T*> outComponents;
143 for ( const auto entity : activeScene->getEntities()) {
144 if ( const auto actor = dynamic_cast<Entities::Actor*>(entity)) {
145 if (actor->hasComponent<T>())
146 {
147 std::vector<T*> components = actor->getComponents<T>();
148 outComponents.insert(outComponents.end(), components.begin(), components.end());
149 }
150 }
151 }
152 return outComponents;
153
154 }
155
156 template <typename T>
158 pendingSceneLoad = [this]() {
159 activeScene = new T();
160 // Inject AssetManager into the scene if available
161 if (assetManager_ != nullptr) {
162 activeScene->setAssetManager(assetManager_);
163 }
165 };
166 }
167
168 inline void SceneManager::loadScene( std::function<Entities::Scene *()> createScene )
169 {
170 pendingSceneLoad = [this, createScene = std::move( createScene )]() {
171 activeScene = createScene ? createScene() : nullptr;
172 if ( activeScene != nullptr && assetManager_ != nullptr )
173 {
174 activeScene->setAssetManager( assetManager_ );
175 }
177 };
178 }
179} // namespace EngineCore
uint32_t scene_object_id
A component which can be attached as many times to an actor as one wants. It makes it possible to ren...
The application context is the core class which stores the basic openxr and vulkan objects.
ApplicationContext * context
Entities::Scene * activeScene
void clear()
Clears all game objects and resets the manager state for a new scene.
uint32_t getGameObjectCount() const
returns the amount of objects present in the current scene
void unloadScene()
Unloads the current scene.
bool isSceneChangePending() const
Checks if a scene change has been requested.
Components::Mesh * registerGameObject(Components::Mesh *gameObject)
registers a game object to the active scene
Entities::Scene * getActiveScene() const
const Vulkan::Buffer & getMeshletToObjectBuffer() const
std::vector< Entities::Entity * > getAllEntities()
Gets a list of pointers to all entities in the current scene.
void unregisterGameObject(const Components::Mesh *gameObject)
unregisters a game object from the active scene
std::vector< Components::Mesh * > gameObjects
const std::vector< Components::Mesh * > & getGameObjects() const
const Components::Mesh * getGameObject(const scene_object_id id) const
std::function< void()> pendingSceneLoad
void executePendingSceneLoading()
Executes the pending scene load. Should be called between frames.
std::vector< Entities::Actor * > getAllActors()
Gets a list of pointers to all actors in the scene.
void loadScene()
Triggers the load of a new scene. Will be executed once the current frame has finished processing.
SceneManager(ApplicationContext *context)
std::vector< uint32_t > gameObjectToMeshletMap
std::vector< T * > getAllComponentsOfClassFromActors()
Gets a list of all components over all actors (EXPENSIVE!)
void setActiveScene(Entities::Scene *scene)
void createMeshletToObjectMapBuffer(ApplicationContext *context)
std::optional< Vulkan::Buffer > meshletToObjectMapBuffer
void uploadGameObjectToMeshletMap()
Uploads the changed data to the buffer on the gpu. Is only one buffer.
void setAssetManager(AssetManager *manager)
Sets the asset manager that will be injected into scenes.
An Actor is similar to an Engine::Entities::Entity. An actor is an Entity with a transform.
Definition Actor.h:65
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
Definition Scene.h:62
RAII wrapper for Vulkan buffer and device memory.
Definition Buffer.h:26
Manages IBL (Image-Based Lighting) resources for specular reflections.