Loading...
Searching...
No Matches
SceneAssetResolver.h
Go to the documentation of this file.
1//
2// Created by denzel on 09/12/2025.
3//
4
5#pragma once
6
7#include "hellfire/assets/AssetManager.h"
8#include "hellfire/scene/Scene.h"
9#include "hellfire/ecs/components/MeshComponent.h"
10#include "hellfire/ecs/RenderableComponent.h"
11
12 namespace hellfire {
13
15 public:
16 explicit SceneAssetResolver(AssetManager& assets) : assets_(assets) {}
17
18 void resolve(Scene& scene) {
19 for (const auto id: scene.get_all_entities() | std::views::keys) {
20 Entity* entity = scene.get_entity(id);
21 if (!entity) continue;
22
23 resolve_entity(*entity);
24 }
25 }
26
27 private:
28 void resolve_entity(Entity& entity) {
29 if (auto* mesh = entity.get_component<MeshComponent>()) {
30 AssetID id = mesh->get_mesh_asset();
31 if (id != INVALID_ASSET_ID) {
32 mesh->set_mesh(assets_.get_mesh(id));
33 }
34 }
35
36 if (auto* renderable = entity.get_component<RenderableComponent>()) {
37 AssetID id = renderable->get_material_asset();
38 if (id != INVALID_ASSET_ID) {
39 renderable->set_material(assets_.get_material(id));
40 }
41 }
42 }
43
45 };
46
47 }
std::shared_ptr< Mesh > get_mesh(AssetID id)
std::shared_ptr< Material > get_material(AssetID id)
uint32_t get_id() const
Definition Entity.h:45
void resolve_entity(Entity &entity)
SceneAssetResolver(AssetManager &assets)
void destroy_scene(Scene *scene)
CameraComponent * get_active_camera() const
bool save_scene(Scene *scene)
Scene * create_scene(const std::string &name="GameScene")
Scene * load_scene(const std::filesystem::path &filename)
std::optional< AssetID > get_scene_asset_id(Scene *scene) const
void set_active_camera(EntityID camera) const
std::optional< AssetID > get_active_scene_asset_id() const
SceneActivatedCallback scene_activated_callback_
Scene * get_active_scene() const
bool save_scene_as(const std::string &filename, Scene *scene)
std::vector< Scene * > scenes_
std::vector< Scene * > get_scenes()
std::unordered_map< Scene *, AssetID > scene_asset_ids_
EntityID find_entity_by_name(const std::string &name)
std::vector< EntityID > get_camera_entities() const
Scene * load_scene(AssetID asset_id, const std::filesystem::path &filename)
void update(float delta_time)
Manages a collection of entities and their hierarchical relationships.
Definition Scene.h:24
Entity * find_entity_by_name(const std::string &name)
Finds an entity by its name.
Definition Scene.cpp:174
Scene(std::string name="Unnamed")
Constructs a new Scene with an optional name.
Definition Scene.cpp:9
void set_playing(bool active)
Definition Scene.h:173
virtual void update(float delta_time)
Updates all entities in the scene.
Definition Scene.cpp:161
void set_default_camera(EntityID camera_id)
Sets the default camera for the scene.
Definition Scene.cpp:182
CameraComponent * get_default_camera() const
Definition Scene.cpp:189
void set_source_filename(const std::filesystem::path &filename)
Definition Scene.h:174
const std::filesystem::path & get_source_filename() const
Definition Scene.h:175
void register_all_components()
constexpr AssetID INVALID_ASSET_ID
static bool serialize(std::ostream &output, const Scene *scene)
static bool deserialize(std::istream &input, Scene *scene)