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 Engine::Core
12{
13 class AssetManager;
14 class ApplicationContext;
15
21 {
22 public:
25
30 std::vector<Entities::Actor *> getAllActors();
35 std::vector<Entities::Entity *> getAllEntities();
36
42 template <typename T>
43 std::vector<T *> getAllComponentsOfClassFromActors();
44
52 void unregisterGameObject( const Components::Mesh * gameObject );
53
57 [[nodiscard]] uint32_t getGameObjectCount() const
58 {
59 return gameObjects.size();
60 }
61
62 [[nodiscard]] const std::vector<Components::Mesh *> & getGameObjects() const;
63 [[nodiscard]] const Components::Mesh * getGameObject( const scene_object_id id ) const;
64 [[nodiscard]] const Vulkan::Buffer & getMeshletToObjectBuffer() const;
65
66 void cleanup();
67
76
85 template <typename T>
86 void loadScene();
87
92 [[nodiscard]] bool isSceneChangePending() const;
93
98
103
107 void clear();
108
109 [[nodiscard]] Entities::Scene * getActiveScene() const { return activeScene; }
111
117
118 private:
120 std::vector<Components::Mesh *> gameObjects = {};
121
122 std::vector<uint32_t> gameObjectToMeshletMap{};
123
124 std::optional<Vulkan::Buffer> meshletToObjectMapBuffer{};
125
127
129
131 std::function<void()> pendingSceneLoad;
132
133 void loadSceneContent() const;
134 };
135
136 template <typename T>
138 {
139 if (!activeScene) return {};
140 std::vector<T*> outComponents;
141 for ( const auto entity : activeScene->getEntities()) {
142 if ( const auto actor = dynamic_cast<Entities::Actor*>(entity)) {
143 if (actor->hasComponent<T>())
144 {
145 std::vector<T*> components = actor->getComponents<T>();
146 outComponents.insert(outComponents.end(), components.begin(), components.end());
147 }
148 }
149 }
150 return outComponents;
151
152 }
153
154 template <typename T>
156 pendingSceneLoad = [this]() {
157 activeScene = new T();
158 // Inject AssetManager into the scene if available
159 if (assetManager_ != nullptr) {
160 activeScene->setAssetManager(assetManager_);
161 }
163 };
164 }
165} // namespace EngineCore
uint32_t scene_object_id
Definition SceneManager.h:9
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:20
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
Definition Scene.h:56
RAII wrapper for Vulkan buffer and device memory.
Definition Buffer.h:26
Core audio subsystem owning the miniaudio engine and managing playback.
Definition AudioConfig.h:9