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 <vector>
9using scene_object_id = uint32_t;
10
11namespace EngineCore
12{
13 class Actor;
14 class Entity;
15 class ApplicationContext;
16 class AssetManager;
17
23 {
24 public:
27
32 std::vector<Actor*> getAllActors();
37 std::vector<Entity*> getAllEntities();
38
44 template <typename T>
45 std::vector<T *> getAllComponentsOfClassFromActors();
46
54 void unregisterGameObject( const MeshComponent * gameObject );
55
59 [[nodiscard]] uint32_t getGameObjectCount() const
60 {
61 return gameObjects.size();
62 }
63
64 [[nodiscard]] const std::vector<MeshComponent *> & getGameObjects() const;
65 [[nodiscard]] const MeshComponent * getGameObject( const scene_object_id id ) const;
66 [[nodiscard]] const VulkanBuffer & getMeshletToObjectBuffer() const;
67
68 void cleanup();
69
78
87 template <typename T>
88 void loadScene();
89
94 [[nodiscard]] bool isSceneChangePending() const;
95
100
104 void unloadScene();
105
109 void clear();
110
111 [[nodiscard]] Scene* getActiveScene() const { return activeScene; }
112 void setActiveScene(Scene* scene);
113
118 void setAssetManager(AssetManager* manager);
119
120 private:
122 std::vector<MeshComponent *> gameObjects = {};
123
124 std::vector<uint32_t> gameObjectToMeshletMap{};
125
126 void addMeshToMap( const MeshComponent * gameObject );
127 void addMeshesToMap( const std::vector<MeshComponent *> & gameObjects );
128 void rebuildMeshMap();
129
130 std::optional<VulkanBuffer> meshletToObjectMapBuffer{};
131
133
135
136 Scene* activeScene = nullptr;
137 std::function<void()> pendingSceneLoad;
138
139 void loadSceneContent() const;
140 };
141
142 template <typename T>
144 {
145 if (!activeScene) return {};
146 std::vector<T*> outComponents;
147 for ( const auto entity : activeScene->getEntities()) {
148 if ( const auto actor = dynamic_cast<Actor*>(entity)) {
149 if (actor->hasComponent<T>())
150 {
151 std::vector<T*> components = actor->getComponents<T>();
152 outComponents.insert(outComponents.end(), components.begin(), components.end());
153 }
154 }
155 }
156 return outComponents;
157
158 }
159
160 template <typename T>
162 pendingSceneLoad = [this]() {
163 activeScene = new T();
164 // Inject AssetManager into the scene if available
165 if (assetManager_ != nullptr) {
166 activeScene->setAssetManager(assetManager_);
167 }
169 };
170 }
171} // namespace EngineCore
uint32_t scene_object_id
Definition SceneManager.h:9
An Actor is similar to an EngineCore::Entity. An actor is an Entity with a transform.
Definition Actor.h:24
The application context is the core class which stores the basic openxr and vulkan objects.
A component which can be attached as many times to an actor as one wants. It makes it possible to ren...
void addMeshToMap(const MeshComponent *gameObject)
void unloadScene()
Unloads the current scene.
ApplicationContext * context
std::vector< Entity * > getAllEntities()
Gets a list of pointers to all entities in the current scene.
void addMeshesToMap(const std::vector< MeshComponent * > &gameObjects)
std::optional< VulkanBuffer > meshletToObjectMapBuffer
void setAssetManager(AssetManager *manager)
Sets the asset manager that will be injected into scenes.
AssetManager * assetManager_
void executePendingSceneLoading()
Executes the pending scene load. Should be called between frames.
const MeshComponent * getGameObject(const scene_object_id id) const
void unregisterGameObject(const MeshComponent *gameObject)
unregisters a game object from the active scene
uint32_t getGameObjectCount() const
returns the amount of objects present in the current scene
Scene * getActiveScene() const
void loadScene()
Triggers the load of a new scene. Will be executed once the current frame has finished processing.
const std::vector< MeshComponent * > & getGameObjects() const
std::vector< MeshComponent * > gameObjects
std::vector< T * > getAllComponentsOfClassFromActors()
Gets a list of all components over all actors (EXPENSIVE!)
void clear()
Clears all game objects and resets the manager state for a new scene.
std::vector< uint32_t > gameObjectToMeshletMap
std::function< void()> pendingSceneLoad
std::vector< Actor * > getAllActors()
Gets a list of pointers to all actors in the scene.
MeshComponent * registerGameObject(MeshComponent *gameObject)
registers a game object to the active scene
const VulkanBuffer & getMeshletToObjectBuffer() const
SceneManager(ApplicationContext *context)
void uploadGameObjectToMeshletMap()
Uploads the changed data to the buffer on the gpu. Is only one buffer.
void createMeshletToObjectMapBuffer(ApplicationContext *context)
bool isSceneChangePending() const
Checks if a scene change has been requested.
void setActiveScene(Scene *scene)
A scene is the overarching structure which can spawn actors.
Definition Scene.h:17
RAII wrapper for Vulkan buffer and device memory.
Log category system implementation.