Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Scene.h
Go to the documentation of this file.
1#pragma once
2
3#include "Actor.h"
5#include "Entity.h"
6
7namespace EngineCore {
8 class Transform;
9 class SceneManager;
10 class SceneGraph;
11 class Engine;
12 class AssetManager;
13
17 class Scene : public ITickable {
18 public:
19 Scene();
20 virtual ~Scene();
21
32 template<typename T, typename... Args>
33 T* spawnActor(const Ecs::LocalTransform& spawnTransform, Args&&... args) {
34 static_assert(std::is_base_of_v<Actor, T>, "T must derive from Actor");
35 TRACY_ZONE_SCOPED_NAMED("Spawned actor of class");
36
37 try {
38 if (!sceneGraph) {
39 throw std::runtime_error("Failed to spawn Actor with world node");
40 }
41 std::shared_ptr<SceneNode> node = sceneGraph->createNode(spawnTransform, sceneGraph->getRoot(), false);
42
43 T* rawPtr = new T(node, this, std::forward<Args>(args)...);
44 entities.push_back(rawPtr);
45
46 rawPtr->sceneNode = node;
47 rawPtr->beginPlay();
48
49 return rawPtr;
50 } catch (const std::exception &e) {
51 throw std::runtime_error("Failed to spawn actor: " + std::string(e.what()));
52 }
53 }
54
55 void destroyActor(Actor* actor);
56
57 virtual void loadContent();
58 virtual void unloadContent();
59
60 [[nodiscard]] std::vector<Entity*> getEntities() const;
61
62 void cleanup();
63 [[nodiscard]] SceneManager* getSceneManager() const;
64
69 [[nodiscard]] AssetManager* getAssetManager() const;
70
75 void setAssetManager(AssetManager* manager);
76
81 [[nodiscard]] Engine* getEngine() const { return engine; }
82
83 protected:
84 Engine* engine = nullptr;
86 private:
87
88 std::unique_ptr<SceneGraph> sceneGraph;
89
90 std::vector<Entity*> entities;
91 };
92}
#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
This is the interface which is used to call a tick function on an object. Everything which should be ...
Definition Tick.h:10
Represents the entire scene as a graph (specifically, a tree) of SceneNode objects....
Definition SceneGraph.h:266
Manages game objects within a scene, handling registration, ID allocation, and GPU buffer synchroniza...
Engine * getEngine() const
Gets the engine instance for this scene.
Definition Scene.h:81
Engine * engine
Definition Scene.h:84
T * spawnActor(const Ecs::LocalTransform &spawnTransform, Args &&... args)
Spawns an actor from a specific class in somewhere into the scene.
Definition Scene.h:33
void setAssetManager(AssetManager *manager)
Sets the asset manager for this scene (used for dependency injection in tests)
Definition Scene.cpp:57
SceneManager * getSceneManager() const
Definition Scene.cpp:49
void destroyActor(Actor *actor)
Definition Scene.cpp:16
virtual void unloadContent()
Definition Scene.cpp:27
AssetManager * getAssetManager() const
Gets the asset manager for this scene.
Definition Scene.cpp:53
AssetManager * assetManager
Definition Scene.h:85
virtual void loadContent()
Definition Scene.cpp:24
std::vector< Entity * > getEntities() const
Definition Scene.cpp:31
std::unique_ptr< SceneGraph > sceneGraph
Definition Scene.h:88
std::vector< Entity * > entities
Definition Scene.h:90
Log category system implementation.