Cogs.Core
AssetDefinition.h
1#pragma once
2
3#include "EntityPtr.h"
4#include "EntityDefinition.h"
5
6#include "Rendering/TextureData.h"
7
8#include "Generators/ImageType.h"
9
10#include "ResourceBase.h"
11#include "ResourceFlags.h"
12
13#include "Services/PropertiesManager.h"
14
15namespace Cogs::Core
16{
18 {
19 enum EFlags
20 {
21 None = 0,
22 ParentIsName = 1 << 0,
23 Sequence = 1 << 1,
24 LodGroup = 1 << 2,
25 Asset = 1 << 3,
26 Model = 1 << 4,
27
28 Children = 1 << 5,
29 Empty = 1 << 6,
30
31 Error = 1 << 16,
32 Last = Error,
33 };
34 };
35
37 {
38 static constexpr uint32_t NoIndex = static_cast<uint32_t>(-1);
39
40 uint32_t index;
41 uint32_t nameIndex;
42 uint32_t parentIndex;
43
44 union
45 {
48
50 struct
51 {
52 uint32_t index;
53 uint32_t flags;
54 uint32_t material;
56
58 struct
59 {
60 uint32_t index;
61 uint16_t flags;
62 uint16_t depth;
63 uint32_t part;
64 uint32_t size; // in KB
66
68 struct
69 {
70 uint32_t numLods;
71 } lod;
72 };
73
74 uint32_t firstField;
75 uint32_t numFields;
76
77 uint32_t firstProperty;
78 uint32_t numProperties;
79
80 uint32_t firstChild; // First child
81 uint32_t numChildren;
82
83 // +------------------------------------firstChild--+
84 // | |
85 // V |
86 // Lod_0_entity_0 ---parent-------------+--+--+--+---> Parent
87 // | \ | | | |
88 // nextSibling nextLodSibling --| | | | |
89 // | | | | |
90 // V | | | |
91 // Lod_1_entity_0 ---parent-------------+ | | |
92 // | \ | | |
93 // nextSibling nextLodSibling --| | | |
94 // | | | |
95 // V | | |
96 // Lod_2_entity_0 --parent-----------------+ | |
97 // | \ | |
98 // nextSibling nextLodSibling | |
99 // | / | |
100 // V V | |
101 // Lod_2_entity_1 ---parent-------------------+ |
102 // | \ |
103 // nextSibling nextLodSibling --| |
104 // | |
105 // V |
106 // Lod_3_entity_0 ---parent----------------------+
107 // | \
108 // nextSibling nextLodSibling --|
109 // |
110 // +--|
111
112 uint32_t nextSibling;
113 uint32_t nextLodSibling;
114
115 uint32_t objectId;
116 uint32_t flags = 0;
117
118 bool isTrivial() const { return !numFields && !numProperties && !numChildren; }
119
120 void setSequence() { flags |= SceneEntityFlags::Sequence; }
121 bool isSequence() const { return flags & SceneEntityFlags::Sequence; }
122 bool isParentedByName() const { return flags & SceneEntityFlags::ParentIsName; }
123
124 void setEmpty() { flags |= SceneEntityFlags::Empty; }
125 bool isEmpty() const { return flags & SceneEntityFlags::Empty; }
126
127 void setLodGroup() { flags |= SceneEntityFlags::LodGroup; }
128 bool isLodGroup() const { return flags & SceneEntityFlags::LodGroup; }
129
130 void setAsset() { flags |= SceneEntityFlags::Asset; }
131 bool isAsset() const { return flags & SceneEntityFlags::Asset; }
132
133 void setModel() { flags |= SceneEntityFlags::Model; }
134 bool isModel() const { return flags & SceneEntityFlags::Model; }
135
136 bool isAssetModelOrLodGroup() const { return flags & (SceneEntityFlags::Asset | SceneEntityFlags::Model | SceneEntityFlags::LodGroup); }
137
138 void setChildren() { flags |= SceneEntityFlags::Children; }
139 bool hasChildren() const { return flags & SceneEntityFlags::Children; }
140
141 void setError() { flags |= SceneEntityFlags::Error; }
142 bool hasError() const { return flags & SceneEntityFlags::Error; }
143
144 StringView getTypeName() const
145 {
146 if (isAsset()) return "Asset";
147 else if (isModel()) return "Model";
148 else if (isLodGroup()) return "LodGroup";
149 else return Strings::get(type);
150 }
151 };
152
153 constexpr uint32_t NoParentEntity = static_cast<uint32_t>(-1);
154
156 {
158 entities(MemBlockType::AssetDefintion),
159 properties(MemBlockType::AssetProperties)
160 {}
161
162 uint32_t createEntity(uint32_t parent)
163 {
164 const size_t index = entities.size();
165 SceneEntityDefinition& entity = entities.grow();
166 entity = SceneEntityDefinition{
167 .index = static_cast<uint32_t>(index),
168 .nameIndex = 0,
169 .parentIndex = parent,
170 .type = NoString,
171
172 .firstField = 0,
173 .numFields = 0,
174
175 .firstProperty = 0,
176 .numProperties = 0,
177
178 .firstChild = 0,
179 .numChildren = 0,
180
181 .nextSibling = static_cast<uint32_t>(-1),
182 .nextLodSibling = static_cast<uint32_t>(-1),
183 .objectId = static_cast<uint32_t>(-1),
184 .flags = 0
185 };
186 return entity.index;
187 }
188
189 PropertyRange getProperties(const SceneEntityDefinition & e) const
190 {
191 PropertyRange range;
192 range.store = &properties;
193 range.firstProperty = e.firstProperty;
194 range.numProperties = e.numProperties;
195 return range;
196 }
197
198 SceneEntityDefinition & operator[](size_t index)
199 {
200 return entities[index];
201 }
202
203 const SceneEntityDefinition & operator[](size_t index) const
204 {
205 return entities[index];
206 }
207
208 uint32_t getChild(uint32_t firstChild, uint32_t childIndex) const
209 {
210 if (childIndex == static_cast<uint32_t>(-1)) return static_cast<uint32_t>(-1);
211 if (firstChild >= entities.size()) return static_cast<uint32_t>(-1);
212
213 auto childDefinition = &entities[firstChild];
214
215 for (uint32_t i = 0; i < childIndex; ++i) {
216 if (childDefinition->nextSibling >= entities.size()) return static_cast<uint32_t>(-1);
217
218 childDefinition = &entities[childDefinition->nextSibling];
219 }
220
221 return childDefinition->index;
222 }
223
224 uint32_t numTopLevelEntities = 0;
225 uint32_t numLodGroups = 0;
226
228
229 PropertyStore properties;
230 std::vector<FieldValue> fieldValues;
231 };
232
234 {
235 std::string name;
236 std::string reference;
237 ResourceTypes type = ResourceTypes::Unknown;
238 std::string source;
239
240 // Material
241 std::string material;
242 std::string permutation;
243 std::unordered_map<std::string, std::string> options;
244 std::unordered_map<std::string, std::string> variants;
245 std::unordered_map<std::string, FieldValue> properties;
246
247 // Texture
248 TextureDescription textureDescription;
249 bool textureGenerator = false;
250 ImageDefinition imageDefinition;
252 };
253
256
257 using ResourcesDefinition = std::vector<ResourceDefinition>;
258
260 {
261 std::string name;
262
263 SceneDefinition scene;
264 ResourcesDefinition resources;
265 };
266}
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
ResourceTypes
Resource types.
Definition: ResourceBase.h:64
TextureLoadFlags
Texture loading flags. May be combined with resource load flags.
Definition: ResourceFlags.h:50
Model resources define a template for a set of connected entities, with resources such as meshes,...
Definition: Model.h:56
struct Cogs::Core::SceneEntityDefinition::@28::@31 model
SceneEntityFlags::Model is set.
uint32_t flags
Really enum of SceneEntityFlags.
uint32_t nextSibling
Next sibling in this or next lod-level.
struct Cogs::Core::SceneEntityDefinition::@28::@32 lod
SceneEntityFlags::LodGroup is set.
uint32_t nextLodSibling
Next sibling within this lod-level.
StringRef type
Neither SceneEntityFlags::Asset, SceneEntityFlags::Model, nor SceneEntityFlags::LodGroup is set.
struct Cogs::Core::SceneEntityDefinition::@28::@30 asset
SceneEntityFlags::Asset is set.