unit_compiler.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. #include "config.h"
  6. #if CROWN_CAN_COMPILE
  7. #include "core/containers/array.inl"
  8. #include "core/containers/hash_map.inl"
  9. #include "core/filesystem/file_buffer.inl"
  10. #include "core/guid.inl"
  11. #include "core/json/json_object.inl"
  12. #include "core/json/sjson.h"
  13. #include "core/math/math.h"
  14. #include "core/memory/temp_allocator.inl"
  15. #include "core/strings/dynamic_string.inl"
  16. #include "core/strings/string_id.inl"
  17. #include "resource/compile_options.inl"
  18. #include "resource/physics_resource.h"
  19. #include "resource/unit_compiler.h"
  20. #include "resource/unit_resource.h"
  21. #include "world/types.h"
  22. #include <algorithm>
  23. namespace crown
  24. {
  25. struct ProjectionInfo
  26. {
  27. const char* name;
  28. ProjectionType::Enum type;
  29. };
  30. static const ProjectionInfo s_projection[] =
  31. {
  32. { "perspective", ProjectionType::PERSPECTIVE },
  33. { "orthographic", ProjectionType::ORTHOGRAPHIC }
  34. };
  35. CE_STATIC_ASSERT(countof(s_projection) == ProjectionType::COUNT);
  36. struct LightInfo
  37. {
  38. const char* name;
  39. LightType::Enum type;
  40. };
  41. static const LightInfo s_light[] =
  42. {
  43. { "directional", LightType::DIRECTIONAL },
  44. { "omni", LightType::OMNI },
  45. { "spot", LightType::SPOT }
  46. };
  47. CE_STATIC_ASSERT(countof(s_light) == LightType::COUNT);
  48. static ProjectionType::Enum projection_name_to_enum(const char* name)
  49. {
  50. for (u32 i = 0; i < countof(s_projection); ++i)
  51. {
  52. if (strcmp(name, s_projection[i].name) == 0)
  53. return s_projection[i].type;
  54. }
  55. return ProjectionType::COUNT;
  56. }
  57. static LightType::Enum light_name_to_enum(const char* name)
  58. {
  59. for (u32 i = 0; i < countof(s_light); ++i)
  60. {
  61. if (strcmp(name, s_light[i].name) == 0)
  62. return s_light[i].type;
  63. }
  64. return LightType::COUNT;
  65. }
  66. static s32 compile_transform(Buffer& output, const char* json, CompileOptions& /*opts*/)
  67. {
  68. TempAllocator4096 ta;
  69. JsonObject obj(ta);
  70. sjson::parse(obj, json);
  71. TransformDesc td;
  72. td.position = sjson::parse_vector3 (obj["position"]);
  73. td.rotation = sjson::parse_quaternion(obj["rotation"]);
  74. td.scale = sjson::parse_vector3 (obj["scale"]);
  75. FileBuffer fb(output);
  76. BinaryWriter bw(fb);
  77. bw.write(td.position);
  78. bw.write(td.rotation);
  79. bw.write(td.scale);
  80. return 0;
  81. }
  82. static s32 compile_camera(Buffer& output, const char* json, CompileOptions& opts)
  83. {
  84. TempAllocator4096 ta;
  85. JsonObject obj(ta);
  86. sjson::parse(obj, json);
  87. DynamicString type(ta);
  88. sjson::parse_string(type, obj["projection"]);
  89. ProjectionType::Enum pt = projection_name_to_enum(type.c_str());
  90. DATA_COMPILER_ASSERT(pt != ProjectionType::COUNT
  91. , opts
  92. , "Unknown projection type: '%s'"
  93. , type.c_str()
  94. );
  95. CameraDesc cd;
  96. cd.type = pt;
  97. cd.fov = sjson::parse_float(obj["fov"]);
  98. cd.near_range = sjson::parse_float(obj["near_range"]);
  99. cd.far_range = sjson::parse_float(obj["far_range"]);
  100. FileBuffer fb(output);
  101. BinaryWriter bw(fb);
  102. bw.write(cd.type);
  103. bw.write(cd.fov);
  104. bw.write(cd.near_range);
  105. bw.write(cd.far_range);
  106. return 0;
  107. }
  108. static s32 compile_mesh_renderer(Buffer& output, const char* json, CompileOptions& opts)
  109. {
  110. TempAllocator4096 ta;
  111. JsonObject obj(ta);
  112. sjson::parse(obj, json);
  113. DynamicString mesh_resource(ta);
  114. sjson::parse_string(mesh_resource, obj["mesh_resource"]);
  115. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("mesh"
  116. , mesh_resource.c_str()
  117. , opts
  118. );
  119. opts.add_requirement("mesh", mesh_resource.c_str());
  120. DynamicString material(ta);
  121. sjson::parse_string(material, obj["material"]);
  122. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("material"
  123. , material.c_str()
  124. , opts
  125. );
  126. opts.add_requirement("material", material.c_str());
  127. MeshRendererDesc mrd;
  128. mrd.mesh_resource = sjson::parse_resource_name(obj["mesh_resource"]);
  129. mrd.material_resource = sjson::parse_resource_name(obj["material"]);
  130. mrd.geometry_name = sjson::parse_string_id (obj["geometry_name"]);
  131. mrd.visible = sjson::parse_bool (obj["visible"]);
  132. mrd._pad0[0] = 0;
  133. mrd._pad0[1] = 0;
  134. mrd._pad0[2] = 0;
  135. FileBuffer fb(output);
  136. BinaryWriter bw(fb);
  137. bw.write(mrd.mesh_resource);
  138. bw.write(mrd.material_resource);
  139. bw.write(mrd.geometry_name);
  140. bw.write(mrd.visible);
  141. bw.write(mrd._pad0[0]);
  142. bw.write(mrd._pad0[1]);
  143. bw.write(mrd._pad0[2]);
  144. return 0;
  145. }
  146. static s32 compile_sprite_renderer(Buffer& output, const char* json, CompileOptions& opts)
  147. {
  148. TempAllocator4096 ta;
  149. JsonObject obj(ta);
  150. sjson::parse(obj, json);
  151. DynamicString sprite_resource(ta);
  152. sjson::parse_string(sprite_resource, obj["sprite_resource"]);
  153. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("sprite"
  154. , sprite_resource.c_str()
  155. , opts
  156. );
  157. opts.add_requirement("sprite", sprite_resource.c_str());
  158. DynamicString material(ta);
  159. sjson::parse_string(material, obj["material"]);
  160. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("material"
  161. , material.c_str()
  162. , opts
  163. );
  164. opts.add_requirement("material", material.c_str());
  165. SpriteRendererDesc srd;
  166. srd.sprite_resource = sjson::parse_resource_name(obj["sprite_resource"]);
  167. srd.material_resource = sjson::parse_resource_name(obj["material"]);
  168. srd.layer = sjson::parse_int (obj["layer"]);
  169. srd.depth = sjson::parse_int (obj["depth"]);
  170. srd.visible = sjson::parse_bool (obj["visible"]);
  171. srd._pad0[0] = 0;
  172. srd._pad0[1] = 0;
  173. srd._pad0[2] = 0;
  174. srd._pad1[0] = 0;
  175. srd._pad1[1] = 0;
  176. srd._pad1[2] = 0;
  177. srd._pad1[3] = 0;
  178. FileBuffer fb(output);
  179. BinaryWriter bw(fb);
  180. bw.write(srd.sprite_resource);
  181. bw.write(srd.material_resource);
  182. bw.write(srd.layer);
  183. bw.write(srd.depth);
  184. bw.write(srd.visible);
  185. bw.write(srd._pad0[0]);
  186. bw.write(srd._pad0[1]);
  187. bw.write(srd._pad0[2]);
  188. bw.write(srd._pad1[0]);
  189. bw.write(srd._pad1[1]);
  190. bw.write(srd._pad1[2]);
  191. bw.write(srd._pad1[3]);
  192. return 0;
  193. }
  194. static s32 compile_light(Buffer& output, const char* json, CompileOptions& opts)
  195. {
  196. TempAllocator4096 ta;
  197. JsonObject obj(ta);
  198. sjson::parse(obj, json);
  199. DynamicString type(ta);
  200. sjson::parse_string(type, obj["type"]);
  201. LightType::Enum lt = light_name_to_enum(type.c_str());
  202. DATA_COMPILER_ASSERT(lt != LightType::COUNT
  203. , opts
  204. , "Unknown light type: '%s'"
  205. , type.c_str()
  206. );
  207. LightDesc ld;
  208. ld.type = lt;
  209. ld.range = sjson::parse_float (obj["range"]);
  210. ld.intensity = sjson::parse_float (obj["intensity"]);
  211. ld.spot_angle = sjson::parse_float (obj["spot_angle"]);
  212. ld.color = sjson::parse_vector3(obj["color"]);
  213. FileBuffer fb(output);
  214. BinaryWriter bw(fb);
  215. bw.write(ld.type);
  216. bw.write(ld.range);
  217. bw.write(ld.intensity);
  218. bw.write(ld.spot_angle);
  219. bw.write(ld.color);
  220. return 0;
  221. }
  222. static s32 compile_script(Buffer& output, const char* json, CompileOptions& opts)
  223. {
  224. TempAllocator4096 ta;
  225. JsonObject obj(ta);
  226. sjson::parse(obj, json);
  227. DynamicString script_resource(ta);
  228. sjson::parse_string(script_resource, obj["script_resource"]);
  229. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("lua"
  230. , script_resource.c_str()
  231. , opts
  232. );
  233. opts.add_requirement("lua", script_resource.c_str());
  234. ScriptDesc sd;
  235. sd.script_resource = sjson::parse_resource_name(obj["script_resource"]);
  236. FileBuffer fb(output);
  237. BinaryWriter bw(fb);
  238. bw.write(sd.script_resource);
  239. return 0;
  240. }
  241. static s32 compile_animation_state_machine(Buffer& output, const char* json, CompileOptions& opts)
  242. {
  243. TempAllocator4096 ta;
  244. JsonObject obj(ta);
  245. sjson::parse(obj, json);
  246. DynamicString state_machine_resource(ta);
  247. sjson::parse_string(state_machine_resource, obj["state_machine_resource"]);
  248. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("state_machine"
  249. , state_machine_resource.c_str()
  250. , opts
  251. );
  252. opts.add_requirement("state_machine", state_machine_resource.c_str());
  253. AnimationStateMachineDesc asmd;
  254. asmd.state_machine_resource = sjson::parse_resource_name(obj["state_machine_resource"]);
  255. FileBuffer fb(output);
  256. BinaryWriter bw(fb);
  257. bw.write(asmd.state_machine_resource);
  258. return 0;
  259. }
  260. UnitCompiler::UnitCompiler(CompileOptions& opts)
  261. : _opts(opts)
  262. , _num_units(0)
  263. , _component_data(default_allocator())
  264. , _component_info(default_allocator())
  265. , _unit_names(default_allocator())
  266. {
  267. register_component_compiler("transform", &compile_transform, 0.0f);
  268. register_component_compiler("camera", &compile_camera, 1.0f);
  269. register_component_compiler("mesh_renderer", &compile_mesh_renderer, 1.0f);
  270. register_component_compiler("sprite_renderer", &compile_sprite_renderer, 1.0f);
  271. register_component_compiler("light", &compile_light, 1.0f);
  272. register_component_compiler("script", &compile_script, 1.0f);
  273. register_component_compiler("collider", &physics_resource_internal::compile_collider, 1.0f);
  274. register_component_compiler("actor", &physics_resource_internal::compile_actor, 2.0f);
  275. register_component_compiler("joint", &physics_resource_internal::compile_joint, 3.0f);
  276. register_component_compiler("animation_state_machine", &compile_animation_state_machine, 1.0f);
  277. }
  278. UnitCompiler::~UnitCompiler()
  279. {
  280. }
  281. Buffer UnitCompiler::read_unit(const char* path)
  282. {
  283. Buffer buf = _opts.read(path);
  284. array::push_back(buf, '\0');
  285. return buf;
  286. }
  287. s32 UnitCompiler::compile_unit(const char* path)
  288. {
  289. return compile_unit_from_json(array::begin(read_unit(path)));
  290. }
  291. u32 component_index(const JsonArray& components, const Guid& id)
  292. {
  293. for (u32 i = 0; i < array::size(components); ++i)
  294. {
  295. TempAllocator512 ta;
  296. JsonObject obj(ta);
  297. sjson::parse(obj, components[i]);
  298. if (sjson::parse_guid(obj["id"]) == id)
  299. return i;
  300. }
  301. return UINT32_MAX;
  302. }
  303. s32 UnitCompiler::collect_units(Buffer& data, Array<u32>& prefabs, const char* json)
  304. {
  305. u32 prefab_offt = array::size(data);
  306. array::push(data, json, strlen32(json));
  307. array::push_back(data, '\0');
  308. array::push_back(prefabs, prefab_offt);
  309. TempAllocator4096 ta;
  310. JsonObject prefab(ta);
  311. sjson::parse(prefab, json);
  312. if (json_object::has(prefab, "prefab"))
  313. {
  314. TempAllocator512 ta;
  315. DynamicString path(ta);
  316. sjson::parse_string(path, prefab["prefab"]);
  317. DATA_COMPILER_ASSERT_RESOURCE_EXISTS("unit"
  318. , path.c_str()
  319. , _opts
  320. );
  321. path += ".unit";
  322. Buffer buf = read_unit(path.c_str());
  323. return 1 + collect_units(data, prefabs, array::begin(buf));
  324. }
  325. return 1;
  326. }
  327. s32 UnitCompiler::compile_unit_from_json(const char* json)
  328. {
  329. Buffer data(default_allocator());
  330. Array<u32> offsets(default_allocator()); // Offsets to JSON objects into data
  331. // offsets[ 0] = { prefab = ..., comps = .., mods = ... } <- Original unit
  332. // offsets[ 1] = { prefab = ..., ... } <- Prefab of the original unit
  333. // offsets[ 2] = { prefab = ..., ... } <- Prefab of the prefab of the original unit
  334. // offsets[n-1] = { prefab = nil, ... } <- Root unit
  335. s32 err = 0;
  336. err = collect_units(data, offsets, json);
  337. DATA_COMPILER_ENSURE(err >= 0, _opts);
  338. TempAllocator4096 ta;
  339. JsonArray merged_components(ta);
  340. JsonArray merged_components_data(ta);
  341. u32 num_prefabs = array::size(offsets);
  342. // Merge components of all prefabs from the root unit up to the unit that
  343. // started the compilation.
  344. for (u32 ii = 0; ii < num_prefabs; ++ii)
  345. {
  346. JsonObject prefab(ta);
  347. sjson::parse(prefab, array::begin(data) + offsets[num_prefabs-1 - ii]);
  348. if (json_object::has(prefab, "components"))
  349. {
  350. JsonArray components(ta);
  351. sjson::parse_array(components, prefab["components"]);
  352. // Add components
  353. for (u32 cc = 0; cc < array::size(components); ++cc)
  354. {
  355. JsonObject component(ta);
  356. sjson::parse_object(component, components[cc]);
  357. array::push_back(merged_components, components[cc]);
  358. array::push_back(merged_components_data, component["data"]);
  359. }
  360. }
  361. if (json_object::has(prefab, "deleted_components"))
  362. {
  363. JsonObject deleted_components(ta);
  364. sjson::parse_object(deleted_components, prefab["deleted_components"]);
  365. // Delete components
  366. auto cur = json_object::begin(deleted_components);
  367. auto end = json_object::end(deleted_components);
  368. for (; cur != end; ++cur)
  369. {
  370. JSON_OBJECT_SKIP_HOLE(deleted_components, cur);
  371. auto key = cur->first;
  372. // Extract GUID from key #xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  373. char guid[37];
  374. strncpy(guid, key.data() + 1, sizeof(guid) - 1);
  375. guid[36] = '\0';
  376. Guid component_id = guid::parse(guid);
  377. u32 comp_idx = component_index(merged_components, component_id);
  378. if (comp_idx != UINT32_MAX)
  379. {
  380. u32 comp_last = array::size(merged_components) - 1;
  381. merged_components[comp_idx] = merged_components[comp_last];
  382. array::pop_back(merged_components);
  383. merged_components_data[comp_idx] = merged_components_data[comp_last];
  384. array::pop_back(merged_components_data);
  385. }
  386. else
  387. {
  388. char buf[GUID_BUF_LEN];
  389. DATA_COMPILER_ASSERT(false
  390. , _opts
  391. , "Deletion of unexisting component ID: %s\n"
  392. , guid::to_string(buf, sizeof(buf), component_id)
  393. );
  394. }
  395. }
  396. }
  397. if (json_object::has(prefab, "modified_components"))
  398. {
  399. JsonObject modified_components(ta);
  400. sjson::parse(modified_components, prefab["modified_components"]);
  401. // Modify components
  402. auto cur = json_object::begin(modified_components);
  403. auto end = json_object::end(modified_components);
  404. for (; cur != end; ++cur)
  405. {
  406. JSON_OBJECT_SKIP_HOLE(modified_components, cur);
  407. auto key = cur->first;
  408. auto val = cur->second;
  409. // Extract GUID from key #xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  410. char guid[37];
  411. strncpy(guid, key.data() + 1, sizeof(guid) - 1);
  412. guid[36] = '\0';
  413. Guid component_id = guid::parse(guid);
  414. // Patch component "data" key
  415. u32 comp_idx = component_index(merged_components, component_id);
  416. if (comp_idx != UINT32_MAX)
  417. {
  418. JsonObject modified_component(ta);
  419. sjson::parse_object(modified_component, val);
  420. merged_components_data[comp_idx] = modified_component["data"];
  421. }
  422. else
  423. {
  424. char buf[GUID_BUF_LEN];
  425. DATA_COMPILER_ASSERT(false
  426. , _opts
  427. , "Modification of unexisting component ID: %s\n"
  428. , guid::to_string(buf, sizeof(buf), component_id)
  429. );
  430. }
  431. }
  432. }
  433. if (ii == 0)
  434. {
  435. // Unnamed object hash == 0
  436. StringId32 name_hash;
  437. // Parse Level Editor data
  438. if (json_object::has(prefab, "editor"))
  439. {
  440. JsonObject editor(ta);
  441. sjson::parse(editor, prefab["editor"]);
  442. if (json_object::has(editor, "name"))
  443. name_hash = sjson::parse_string_id(editor["name"]);
  444. }
  445. array::push_back(_unit_names, name_hash);
  446. }
  447. }
  448. if (array::size(merged_components) > 0)
  449. {
  450. for (u32 cc = 0; cc < array::size(merged_components); ++cc)
  451. {
  452. const char* val = merged_components[cc];
  453. TempAllocator512 ta;
  454. JsonObject component(ta);
  455. sjson::parse(component, val);
  456. const StringId32 type = sjson::parse_string_id(component["type"]);
  457. Buffer output(default_allocator());
  458. err = compile_component(output, type, merged_components_data[cc]);
  459. DATA_COMPILER_ENSURE(err == 0, _opts);
  460. add_component_data(type, output, _num_units);
  461. }
  462. }
  463. ++_num_units;
  464. return 0;
  465. }
  466. s32 UnitCompiler::compile_multiple_units(const char* json)
  467. {
  468. TempAllocator4096 ta;
  469. JsonArray units(ta);
  470. sjson::parse_array(units, json);
  471. for (u32 i = 0; i < array::size(units); ++i)
  472. {
  473. s32 err = compile_unit_from_json(units[i]);
  474. DATA_COMPILER_ENSURE(err == 0, _opts);
  475. }
  476. return 0;
  477. }
  478. Buffer UnitCompiler::blob()
  479. {
  480. Buffer output(default_allocator());
  481. FileBuffer fb(output);
  482. BinaryWriter bw(fb);
  483. // Count component types
  484. u32 num_component_types = 0;
  485. auto cur = hash_map::begin(_component_data);
  486. auto end = hash_map::end(_component_data);
  487. for (; cur != end; ++cur)
  488. {
  489. HASH_MAP_SKIP_HOLE(_component_data, cur);
  490. if (cur->second._num > 0)
  491. ++num_component_types;
  492. }
  493. // Write header
  494. UnitResource ur;
  495. ur.version = RESOURCE_HEADER(RESOURCE_VERSION_UNIT);
  496. ur.num_units = _num_units;
  497. ur.num_component_types = num_component_types;
  498. bw.write(ur.version);
  499. bw.write(ur.num_units);
  500. bw.write(ur.num_component_types);
  501. for (u32 ii = 0; ii < array::size(_component_info); ++ii)
  502. {
  503. const StringId32 type = _component_info[ii]._type;
  504. const ComponentTypeData& ctd = hash_map::get(_component_data, type, ComponentTypeData(default_allocator()));
  505. const Buffer& data = ctd._data;
  506. const Array<u32>& unit_index = ctd._unit_index;
  507. const u32 num = ctd._num;
  508. if (num == 0)
  509. continue;
  510. // Write component data
  511. ComponentData cd;
  512. cd.type = type;
  513. cd.num_instances = num;
  514. cd.data_size = array::size(data);
  515. bw.align(alignof(cd));
  516. bw.write(cd.type);
  517. bw.write(cd.num_instances);
  518. bw.write(cd.data_size);
  519. for (u32 jj = 0; jj < array::size(unit_index); ++jj)
  520. bw.write(unit_index[jj]);
  521. bw.align(16);
  522. bw.write(array::begin(data), array::size(data));
  523. }
  524. return output;
  525. }
  526. void UnitCompiler::add_component_data(StringId32 type, const Buffer& data, u32 unit_index)
  527. {
  528. ComponentTypeData component_types_deffault(default_allocator());
  529. ComponentTypeData& ctd = const_cast<ComponentTypeData&>(hash_map::get(_component_data, type, component_types_deffault));
  530. array::push(ctd._data, array::begin(data), array::size(data));
  531. array::push_back(ctd._unit_index, unit_index);
  532. ++ctd._num;
  533. }
  534. void UnitCompiler::register_component_compiler(const char* type, CompileFunction fn, f32 spawn_order)
  535. {
  536. register_component_compiler(StringId32(type), fn, spawn_order);
  537. }
  538. void UnitCompiler::register_component_compiler(StringId32 type, CompileFunction fn, f32 spawn_order)
  539. {
  540. ComponentTypeData ctd(default_allocator());
  541. ctd._compiler = fn;
  542. ComponentTypeInfo cti;
  543. cti._type = type;
  544. cti._spawn_order = spawn_order;
  545. hash_map::set(_component_data, type, ctd);
  546. array::push_back(_component_info, cti);
  547. std::sort(array::begin(_component_info), array::end(_component_info));
  548. }
  549. s32 UnitCompiler::compile_component(Buffer& output, StringId32 type, const char* json)
  550. {
  551. DATA_COMPILER_ASSERT(hash_map::has(_component_data, type), _opts, "Unknown component");
  552. return hash_map::get(_component_data, type, ComponentTypeData(default_allocator()))._compiler(output, json, _opts);
  553. }
  554. } // namespace crown
  555. #endif // CROWN_CAN_COMPILE