MCPcopy Create free account
hub / github.com/crownengine/crown / blob

Function blob

src/resource/unit_compiler.cpp:1279–1335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1277 }
1278
1279 s32 blob(Buffer &output, UnitCompiler &c)
1280 {
1281 FileBuffer fb(output);
1282 BinaryWriter bw(fb);
1283
1284 // Count component types.
1285 u32 num_component_types = 0;
1286 auto cur = hash_map::begin(c._component_data);
1287 auto end = hash_map::end(c._component_data);
1288 for (; cur != end; ++cur) {
1289 HASH_MAP_SKIP_HOLE(c._component_data, cur);
1290
1291 if (cur->second._num > 0)
1292 ++num_component_types;
1293 }
1294
1295 // Write header.
1296 UnitResource ur;
1297 ur.version = RESOURCE_HEADER(RESOURCE_VERSION_UNIT);
1298 ur.num_units = c._num_units;
1299 ur.num_component_types = num_component_types;
1300
1301 bw.write(ur.version);
1302 bw.write(ur.num_units);
1303 bw.write(ur.num_component_types);
1304
1305 // Write parents.
1306 for (u32 ii = 0; ii < c._num_units; ++ii)
1307 bw.write(c._unit_parents[ii]);
1308
1309 for (u32 ii = 0; ii < array::size(c._component_info); ++ii) {
1310 const StringId32 comp_type = c._component_info[ii]._type;
1311
1312 const ComponentTypeData ctd_deffault(default_allocator());
1313 const ComponentTypeData &ctd = hash_map::get(c._component_data, comp_type, ctd_deffault);
1314
1315 if (ctd._num == 0)
1316 continue;
1317
1318 // Write component data.
1319 ComponentData cd;
1320 cd.type = comp_type;
1321 cd.num_instances = ctd._num;
1322 cd.data_size = array::size(ctd._data);
1323
1324 bw.align(alignof(cd));
1325 bw.write(cd.type);
1326 bw.write(cd.num_instances);
1327 bw.write(cd.data_size);
1328 for (u32 jj = 0; jj < array::size(ctd._unit_index); ++jj)
1329 bw.write(ctd._unit_index[jj]);
1330 bw.align(16);
1331 bw.write(array::begin(ctd._data), array::size(ctd._data));
1332 }
1333
1334 return 0;
1335 }
1336

Callers 2

compileFunction · 0.85
compileFunction · 0.85

Calls 6

getFunction · 0.85
beginFunction · 0.50
endFunction · 0.50
sizeFunction · 0.50
writeMethod · 0.45
alignMethod · 0.45

Tested by

no test coverage detected