34 struct GltfSpawnPlanData;
45 std::shared_ptr<const GltfSpawnPlanData>
data;
77 template<
typename T,
typename... Args>
79 static_assert(std::is_base_of_v<Entities::Actor, T>,
"T must derive from Actor");
81 std::is_constructible_v<T,
const SpawnContext&, Args...>,
82 "Actor types spawned with Scene::spawnActor must be constructible as "
83 "T(const SpawnContext&, ...actorSpecificArgs)."
89 throw std::runtime_error(
"Failed to spawn Actor with world node");
91 std::shared_ptr<Entities::SceneNode> node =
sceneGraph->createNode(spawnTransform,
sceneGraph->getRoot(),
false);
94 T* rawPtr =
new T(context, std::forward<Args>(args)...);
97 rawPtr->sceneNode = node;
101 }
catch (
const std::exception &e) {
102 throw std::runtime_error(
"Failed to spawn actor: " + std::string(e.what()));
117 template<
typename ActorT = StaticMeshActor>
120 const std::filesystem::path& gltfPath)
123 if (registry !=
nullptr)
130 std::vector<ActorT*> spawnedActors;
131 spawnedActors.reserve( spawnPlan.
meshNodes.size() );
135 spawnedActors.push_back(actor);
139 return spawnedActors;
142 template<
typename ActorT = StaticMeshActor>
149 std::vector<ActorT*> spawnedActors;
150 spawnedActors.reserve(spawnPlan.
meshNodes.size());
153 ActorT* actor =
nullptr;
155 if constexpr (std::is_constructible_v<ActorT, const SpawnContext&, Assets::GltfRenderableHandle>)
163 if (actor ==
nullptr)
165 if constexpr (std::is_constructible_v<ActorT, const SpawnContext&, Assets::GeometryMeshHandle>)
174 if (actor ==
nullptr)
179 spawnedActors.push_back(actor);
183 return spawnedActors;
#define TRACY_ZONE_SCOPED_NAMED(name)
Assets::GltfHandle load(const std::filesystem::path &source)
This is the interface which is used to call a tick function on an object. Everything which should be ...
Manages game objects within a scene, handling registration, ID allocation, and GPU buffer synchroniza...
An Actor is similar to an Engine::Entities::Entity. An actor is an Entity with a transform.
Represents the entire scene as a graph (specifically, a tree) of SceneNode objects....
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
static std::vector< ActorT * > spawnAll(Scene *scene, const std::filesystem::path &gltfPath)
Spawns all meshes from a GLTF file into the scene.
void destroyActor(Entities::Actor *actor)
Core::SceneManager * getSceneManager() const
SceneGraph * getSceneGraph() const
std::vector< Entities::Entity * > getEntities() const
Core::AssetManager * getAssetManager() const
Gets the asset manager for this scene.
virtual void unloadContent()
void destroyActorImmediate(Entities::Actor *actor)
void reserveActorCapacity(size_t additionalActors)
Reserves storage for a known number of upcoming actor spawns.
Core::AssetRegistry * assetRegistry
std::vector< Actor * > pendingDestroyActors_
Core::AssetRegistry * getAssetRegistry() const
void flushPendingActorDestruction()
std::unique_ptr< SceneGraph > sceneGraph
void setAssetRegistry(Core::AssetRegistry *registry)
void setAssetManager(Core::AssetManager *manager)
Sets the asset manager for this scene (used for dependency injection in tests)
virtual void loadContent()
static std::vector< ActorT * > spawnAll(Scene *scene, Assets::GltfHandle gltf)
T * spawnActor(const Ecs::Transform &spawnTransform, Args &&... args)
Spawns an actor from a specific class in somewhere into the scene.
std::vector< Entity * > entities
Core::AssetManager * assetManager
EngineKern * getEngine() const
Gets the engine instance for this scene.
Wrapper for entt component creation which ensures types safety and attaches the correct component wit...
AssetHandle< GltfRenderableHandleTag > GltfRenderableHandle
AssetHandle< GltfHandleTag > GltfHandle
AssetHandle< GeometryMeshHandleTag > GeometryMeshHandle
Manages IBL (Image-Based Lighting) resources for specular reflections.
GltfSpawnPlan prepareGltfSpawnPlan(Scene *scene, const std::filesystem::path &gltfPath)
void applyGltfNodeExtensions(Actor *actor, const GltfSpawnPlan &plan, const GltfSpawnNode &spawnNode)
Identifies a named mesh-like asset inside an asset file.
Scene ownership data passed to actor and component constructors during spawning.
Assets::GeometryMeshHandle geometryMesh
Assets::GltfRenderableHandle renderable
std::shared_ptr< const GltfSpawnPlanData > data
std::vector< GltfSpawnNode > meshNodes