Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
SceneManager.cpp
Go to the documentation of this file.
2
5#include "Engine/Core/Tick.h"
9#include "Engine/Mesh/Mesh.h"
10#include "plog/Log.h"
11
12namespace EngineCore {
16
19
20 std::vector<Actor *> SceneManager::getAllActors()
21 {
22 TRACY_ZONE_SCOPED_NAMED("Get all actors");
23 if (!activeScene) return {};
24 std::vector<Actor*> actors;
25 for (auto entity : activeScene->getEntities()) {
26 if (auto actor = dynamic_cast<Actor*>(entity)) {
27 actors.push_back(actor);
28 }
29 }
30 return actors;
31 }
32
33 std::vector<Entity *> SceneManager::getAllEntities()
34 {
35 if (!activeScene) return {};
36 return activeScene->getEntities();
37 }
38
40 {
41 gameObjects.push_back(gameObject);
42 return gameObject;
43 }
44
46 {
47 if (gameObject == nullptr) {
48 PLOGW << "Attempted to unregister a null GameObject pointer.";
49 return;
50 }
51
52 if (const auto it = std::ranges::find(gameObjects, gameObject); it != gameObjects.end()) {
53 gameObjects.erase(it);
54 } else {
55 PLOGW << "GameObject pointer not found in gameObjects vector during unregistration.";
56 }
57 }
58
59 const std::vector<MeshComponent *> & SceneManager::getGameObjects() const {
60 return gameObjects;
61 }
62
64 if (id < gameObjects.size()) {
65 return gameObjects[id];
66 }
67 return nullptr;
68 }
69
73
79
81 return pendingSceneLoad != nullptr;
82 }
83
85 TRACY_ZONE_SCOPED_NAMED("Scene loading");
86 if (activeScene != nullptr) {
88 }
90 pendingSceneLoad = nullptr;
91 }
92
94 TRACY_ZONE_SCOPED_NAMED("Unload scene");
95 if (activeScene) {
96 activeScene->unloadContent();
97 activeScene->cleanup();
98 delete activeScene;
99 activeScene = nullptr;
100 }
101 clear();
102 }
103
105 gameObjects.clear();
107 }
108
110 if (activeScene) {
111 unloadScene();
112 }
113 activeScene = scene;
114 if (activeScene) {
115 // Inject AssetManager into the scene if available
116 if (assetManager_ != nullptr) {
117 activeScene->setAssetManager(assetManager_);
118 }
120 }
121 }
122
124 assetManager_ = manager;
125 }
126
128 if (activeScene) {
129 activeScene->loadContent();
130 }
131 else {
132 PLOGE << "Failed to load scene content as the scene was nullptr";
133 }
134 }
135
139
141 // Legacy - meshlet mapping now handled by RenderingDataManager
142 }
143
144 void SceneManager::addMeshesToMap(const std::vector<MeshComponent *> &gameObjects) {
145 // Legacy - meshlet mapping now handled by RenderingDataManager
146 }
147
149 // Legacy - meshlet mapping now handled by RenderingDataManager
150 }
151
153 {
154 constexpr VkDeviceSize bufferSize = sizeof( uint32_t ) * MAX_MESHLETS_PER_BIN;
157 bufferSize,
158 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
159 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
160 );
161 meshletToObjectMapBuffer->setDebugName( "Meshlet To Object Map Buffer" );
162 }
163
165 {
166 if ( meshletToObjectMapBuffer.has_value() && meshletToObjectMapBuffer->isValid() )
167 {
168 meshletToObjectMapBuffer->destroy();
169 }
170 meshletToObjectMapBuffer->invalidate();
171 }
172}
uint32_t scene_object_id
Definition SceneManager.h:9
constexpr uint32_t MAX_MESHLETS_PER_BIN
Definition Settings.h:37
#define TRACY_ZONE_SCOPED_NAMED(name)
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
const std::vector< MeshComponent * > & getGameObjects() const
std::vector< MeshComponent * > gameObjects
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.