model_comp.hpp 2.8 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include "model.hpp"

#include <mirrage/ecs/component.hpp>

7
8
#include <future>

9

10
namespace mirrage::renderer {
11

12
13
14
15
16
	// model components are intially loaded as Model_unloaded_comp, replaced by Model_loading_comp
	//   once the loading of the model data has begun and finally replaced by Model_comp afterwards.
	// Client code should only care about the Model_comp class as it represents an actually usable model.


17
	class Model_comp : public ecs::Component<Model_comp> {
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
	  public:
		static constexpr const char* name() { return "Model_loaded"; }
		static constexpr const char* name_save_as() { return "Model"; }
		friend void load_component(ecs::Deserializer& state, Model_comp&);
		friend void save_component(ecs::Serializer& state, const Model_comp&);

		Model_comp() = default;
		Model_comp(ecs::Entity_manager& manager,
		           ecs::Entity_handle   owner,
		           asset::AID           model_aid = {},
		           Model_ptr            model     = {})
		  : Component(manager, owner), _model_aid(std::move(model_aid)), _model(std::move(model)) {}

		auto model_aid() const -> auto& { return _model_aid; }
		auto model() const -> auto& { return _model; }
		void model(Model_ptr model) { _model = std::move(model); }

	  private:
		asset::AID _model_aid;
		Model_ptr  _model;
38
39
	};

40
	class Model_unloaded_comp : public ecs::Component<Model_unloaded_comp> {
41
42
43
44
	  public:
		static constexpr const char* name() { return "Model"; }
		friend void load_component(ecs::Deserializer& state, Model_unloaded_comp&);
		friend void save_component(ecs::Serializer& state, const Model_unloaded_comp&);
45

46
47
48
		Model_unloaded_comp() = default;
		Model_unloaded_comp(ecs::Entity_manager& manager, ecs::Entity_handle owner, asset::AID model_aid = {})
		  : Component(manager, owner), _model_aid(std::move(model_aid)) {}
49

50
		auto model_aid() const -> auto& { return _model_aid; }
51

52
53
	  private:
		asset::AID _model_aid;
54
55
56
	};

	class Model_loading_comp : public ecs::Component<Model_loading_comp> {
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	  public:
		static constexpr const char* name() { return "Model_loading"; }
		static constexpr const char* name_save_as() { return "Model"; }
		friend void load_component(ecs::Deserializer& state, Model_loading_comp&);
		friend void save_component(ecs::Serializer& state, const Model_loading_comp&);

		Model_loading_comp() = default;
		Model_loading_comp(ecs::Entity_manager& manager,
		                   ecs::Entity_handle   owner,
		                   asset::AID           model_aid = {},
		                   future<Model_ptr>    model     = {})
		  : Component(manager, owner), _model_aid(std::move(model_aid)), _model(std::move(model)) {}

		auto model_aid() const -> auto& { return _model_aid; }
		auto model() const -> auto& { return _model; }
		auto model() -> auto& { return _model; }

	  private:
		asset::AID        _model_aid;
		future<Model_ptr> _model;
77
	};
78
}