From f3801e978aa352660d57724936b0ff7615326cb3 Mon Sep 17 00:00:00 2001 From: Daniele Bartolini Date: Sun, 11 Jan 2026 00:14:37 +0100 Subject: [PATCH 1/2] resource: cleanup --- src/resource/mesh_animation_resource.h | 9 --------- src/resource/mesh_skeleton_resource.h | 9 --------- 2 files changed, 18 deletions(-) diff --git a/src/resource/mesh_animation_resource.h b/src/resource/mesh_animation_resource.h index 8bae6fe21..e322ac7a1 100644 --- a/src/resource/mesh_animation_resource.h +++ b/src/resource/mesh_animation_resource.h @@ -62,15 +62,6 @@ struct MeshAnimationResource // u16 bone_ids[num_bones] }; -#if CROWN_CAN_COMPILE -namespace mesh_animation_resource_internal -{ - /// - s32 compile(CompileOptions &opts); - -} // namespace mesh_animation_resource_internal -#endif - namespace mesh_animation_resource { /// diff --git a/src/resource/mesh_skeleton_resource.h b/src/resource/mesh_skeleton_resource.h index 3cbdd2b0b..70ec3185f 100644 --- a/src/resource/mesh_skeleton_resource.h +++ b/src/resource/mesh_skeleton_resource.h @@ -33,15 +33,6 @@ struct MeshSkeletonResource // Matrix4x4 binding_matrices[num_bones]; }; -#if CROWN_CAN_COMPILE -namespace mesh_skeleton_resource_internal -{ - /// - s32 compile(CompileOptions &opts); - -} // namespace mesh_skeleton_resource_internal -#endif - namespace mesh_skeleton_resource { /// From 9000bb4c336d62becfc8649dbbd8f4534c9ebb56 Mon Sep 17 00:00:00 2001 From: Daniele Bartolini Date: Sun, 11 Jan 2026 00:39:27 +0100 Subject: [PATCH 2/2] resource: move resource access functions to .inl files --- src/lua/lua_environment.cpp | 2 +- src/resource/font_resource.cpp | 23 +----- src/resource/font_resource.inl | 28 +++++++ src/resource/level_resource.cpp | 32 +------- src/resource/level_resource.inl | 36 +++++++++ src/resource/lua_resource.cpp | 14 +--- src/resource/lua_resource.inl | 19 +++++ src/resource/material_resource.cpp | 56 -------------- src/resource/material_resource.inl | 66 +++++++++++++++++ src/resource/mesh_animation_resource.cpp | 20 +---- src/resource/mesh_animation_resource.inl | 24 ++++++ src/resource/mesh_skeleton_resource.cpp | 25 +------ src/resource/mesh_skeleton_resource.inl | 29 ++++++++ src/resource/package_resource.cpp | 21 +----- src/resource/package_resource.inl | 27 +++++++ src/resource/physics_resource.cpp | 57 +------------- src/resource/physics_resource.inl | 62 ++++++++++++++++ src/resource/resource_package.cpp | 2 +- src/resource/sound_resource.cpp | 19 +---- src/resource/sound_resource.inl | 24 ++++++ src/resource/sprite_resource.cpp | 21 ------ src/resource/sprite_resource.inl | 29 ++++++++ src/resource/state_machine_resource.cpp | 84 --------------------- src/resource/state_machine_resource.inl | 94 ++++++++++++++++++++++++ src/resource/unit_resource.cpp | 28 ------- src/resource/unit_resource.inl | 38 ++++++++++ src/world/animation_state_machine.cpp | 3 +- src/world/gui.cpp | 2 +- src/world/level.cpp | 2 +- src/world/material_manager.cpp | 2 +- src/world/mesh_animation_player.cpp | 1 + src/world/physics_world_bullet.cpp | 2 +- src/world/render_world.cpp | 2 +- src/world/sound_world_al.cpp | 2 +- src/world/world.cpp | 2 +- 35 files changed, 515 insertions(+), 383 deletions(-) create mode 100644 src/resource/font_resource.inl create mode 100644 src/resource/level_resource.inl create mode 100644 src/resource/lua_resource.inl create mode 100644 src/resource/material_resource.inl create mode 100644 src/resource/mesh_animation_resource.inl create mode 100644 src/resource/mesh_skeleton_resource.inl create mode 100644 src/resource/package_resource.inl create mode 100644 src/resource/physics_resource.inl create mode 100644 src/resource/sound_resource.inl create mode 100644 src/resource/sprite_resource.inl create mode 100644 src/resource/state_machine_resource.inl create mode 100644 src/resource/unit_resource.inl diff --git a/src/lua/lua_environment.cpp b/src/lua/lua_environment.cpp index fcedca0bc..c83a4e382 100644 --- a/src/lua/lua_environment.cpp +++ b/src/lua/lua_environment.cpp @@ -15,7 +15,7 @@ #include "device/log.h" #include "lua/lua_environment.h" #include "lua/lua_stack.inl" -#include "resource/lua_resource.h" +#include "resource/lua_resource.inl" #include "resource/resource_manager.h" #include diff --git a/src/resource/font_resource.cpp b/src/resource/font_resource.cpp index aa20e7a9a..45fc08965 100644 --- a/src/resource/font_resource.cpp +++ b/src/resource/font_resource.cpp @@ -4,6 +4,8 @@ */ #include "config.h" + +#if CROWN_CAN_COMPILE #include "core/containers/array.inl" #include "core/filesystem/file.h" #include "core/filesystem/filesystem.h" @@ -19,25 +21,6 @@ namespace crown { -namespace font_resource -{ - const GlyphData *glyph(const FontResource *fr, CodePoint cp, const GlyphData *deffault) - { - const CodePoint *codes = (CodePoint *)&fr[1]; - const GlyphData *glyphs = (GlyphData *)(codes + fr->num_glyphs); - - // FIXME: Can do binary search - for (u32 i = 0; i < fr->num_glyphs; ++i) { - if (codes[i] == cp) - return &glyphs[i]; - } - - return deffault; - } - -} // namespace font_resource - -#if CROWN_CAN_COMPILE namespace font_resource_internal { struct GlyphInfo @@ -120,6 +103,6 @@ namespace font_resource_internal } } // namespace font_resource_internal -#endif // if CROWN_CAN_COMPILE } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/font_resource.inl b/src/resource/font_resource.inl new file mode 100644 index 000000000..99ce58f92 --- /dev/null +++ b/src/resource/font_resource.inl @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/font_resource.h" + +namespace crown +{ +namespace font_resource +{ + const GlyphData *glyph(const FontResource *fr, CodePoint cp, const GlyphData *deffault) + { + const CodePoint *codes = (CodePoint *)&fr[1]; + const GlyphData *glyphs = (GlyphData *)(codes + fr->num_glyphs); + + // FIXME: Can do binary search + for (u32 i = 0; i < fr->num_glyphs; ++i) { + if (codes[i] == cp) + return &glyphs[i]; + } + + return deffault; + } + +} // namespace font_resource + +} // namespace crown diff --git a/src/resource/level_resource.cpp b/src/resource/level_resource.cpp index 239d43453..8661e2fa9 100644 --- a/src/resource/level_resource.cpp +++ b/src/resource/level_resource.cpp @@ -3,6 +3,9 @@ * SPDX-License-Identifier: MIT */ +#include "config.h" + +#if CROWN_CAN_COMPILE #include "core/containers/array.inl" #include "core/filesystem/file.h" #include "core/filesystem/filesystem.h" @@ -18,33 +21,6 @@ namespace crown { -namespace level_resource -{ - const StringId32 *unit_names(const LevelResource *lr) - { - return (StringId32 *)((char *)lr + lr->unit_names_offset); - } - - const UnitResource *unit_resource(const LevelResource *lr) - { - return (UnitResource *)((char *)lr + lr->units_offset); - } - - u32 num_sounds(const LevelResource *lr) - { - return lr->num_sounds; - } - - const LevelSound *get_sound(const LevelResource *lr, u32 i) - { - CE_ASSERT(i < num_sounds(lr), "Index out of bounds"); - const LevelSound *begin = (LevelSound *)((char *)lr + lr->sounds_offset); - return &begin[i]; - } - -} // namespace level_resource - -#if CROWN_CAN_COMPILE namespace level_resource_internal { s32 compile(CompileOptions &opts) @@ -155,6 +131,6 @@ namespace level_resource_internal } } // namespace level_resource_internal -#endif // if CROWN_CAN_COMPILE } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/level_resource.inl b/src/resource/level_resource.inl new file mode 100644 index 000000000..523a27888 --- /dev/null +++ b/src/resource/level_resource.inl @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/level_resource.h" + +namespace crown +{ +namespace level_resource +{ + const StringId32 *unit_names(const LevelResource *lr) + { + return (StringId32 *)((char *)lr + lr->unit_names_offset); + } + + const UnitResource *unit_resource(const LevelResource *lr) + { + return (UnitResource *)((char *)lr + lr->units_offset); + } + + u32 num_sounds(const LevelResource *lr) + { + return lr->num_sounds; + } + + const LevelSound *get_sound(const LevelResource *lr, u32 i) + { + CE_ASSERT(i < num_sounds(lr), "Index out of bounds"); + const LevelSound *begin = (LevelSound *)((char *)lr + lr->sounds_offset); + return &begin[i]; + } + +} // namespace level_resource + +} // namespace crown diff --git a/src/resource/lua_resource.cpp b/src/resource/lua_resource.cpp index c8006b9fb..36596c733 100644 --- a/src/resource/lua_resource.cpp +++ b/src/resource/lua_resource.cpp @@ -4,6 +4,8 @@ */ #include "config.h" + +#if CROWN_CAN_COMPILE #include "core/containers/array.inl" #include "core/containers/hash_set.inl" #include "core/filesystem/file.h" @@ -17,16 +19,6 @@ namespace crown { -namespace lua_resource -{ - const char *program(const LuaResource *lr) - { - return (char *)&lr[1]; - } - -} // namespace lua_resource - -#if CROWN_CAN_COMPILE namespace lua_resource_internal { static const char *skip_blanks(const char *lua) @@ -180,6 +172,6 @@ namespace lua_resource_internal } } // namespace lua_resource_internal -#endif // if CROWN_CAN_COMPILE } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/lua_resource.inl b/src/resource/lua_resource.inl new file mode 100644 index 000000000..b7cda7cc9 --- /dev/null +++ b/src/resource/lua_resource.inl @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/lua_resource.h" + +namespace crown +{ +namespace lua_resource +{ + const char *program(const LuaResource *lr) + { + return (char *)&lr[1]; + } + +} // namespace lua_resource + +} // namespace crown diff --git a/src/resource/material_resource.cpp b/src/resource/material_resource.cpp index 33223571d..038242058 100644 --- a/src/resource/material_resource.cpp +++ b/src/resource/material_resource.cpp @@ -22,62 +22,6 @@ namespace crown { -namespace material_resource -{ - UniformData *uniform_data_array(const MaterialResource *mr) - { - return (UniformData *)((char *)mr + mr->uniform_data_offset); - } - - u32 uniform_data_index(const MaterialResource *mr, const UniformData *ud, StringId32 name) - { - for (u32 i = 0, n = mr->num_uniforms; i < n; ++i) { - if (ud[i].name == name) - return i; - } - - CE_FATAL("Unknown uniform name"); - return UINT32_MAX; - } - - const char *uniform_name(const MaterialResource *mr, const UniformData *ud, u32 i) - { - return (char *)mr + mr->names_data_offset + ud[i].name_offset; - } - - TextureData *texture_data_array(const MaterialResource *mr) - { - return (TextureData *)((char *)mr + mr->texture_data_offset); - } - - u32 texture_data_index(const MaterialResource *mr, const TextureData *td, StringId32 name) - { - for (u32 i = 0, n = mr->num_textures; i < n; ++i) { - if (td[i].name == name) - return i; - } - - CE_FATAL("Unknown texture name"); - return UINT32_MAX; - } - - const char *texture_name(const MaterialResource *mr, const TextureData *td, u32 i) - { - return (char *)mr + mr->names_data_offset + td[i].sampler_name_offset; - } - - UniformHandle *uniform_handle(const UniformData *ud, u32 i, char *dynamic) - { - return (UniformHandle *)(dynamic + ud[i].data_offset); - } - - TextureHandle *texture_handle(const TextureData *td, u32 i, char *dynamic) - { - return (TextureHandle *)(dynamic + td[i].data_offset); - } - -} // namespace material_resource - namespace material_resource_internal { void online(StringId64 id, ResourceManager &rm) diff --git a/src/resource/material_resource.inl b/src/resource/material_resource.inl new file mode 100644 index 000000000..b266e6055 --- /dev/null +++ b/src/resource/material_resource.inl @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/material_resource.h" + +namespace crown +{ +namespace material_resource +{ + UniformData *uniform_data_array(const MaterialResource *mr) + { + return (UniformData *)((char *)mr + mr->uniform_data_offset); + } + + u32 uniform_data_index(const MaterialResource *mr, const UniformData *ud, StringId32 name) + { + for (u32 i = 0, n = mr->num_uniforms; i < n; ++i) { + if (ud[i].name == name) + return i; + } + + CE_FATAL("Unknown uniform name"); + return UINT32_MAX; + } + + const char *uniform_name(const MaterialResource *mr, const UniformData *ud, u32 i) + { + return (char *)mr + mr->names_data_offset + ud[i].name_offset; + } + + TextureData *texture_data_array(const MaterialResource *mr) + { + return (TextureData *)((char *)mr + mr->texture_data_offset); + } + + u32 texture_data_index(const MaterialResource *mr, const TextureData *td, StringId32 name) + { + for (u32 i = 0, n = mr->num_textures; i < n; ++i) { + if (td[i].name == name) + return i; + } + + CE_FATAL("Unknown texture name"); + return UINT32_MAX; + } + + const char *texture_name(const MaterialResource *mr, const TextureData *td, u32 i) + { + return (char *)mr + mr->names_data_offset + td[i].sampler_name_offset; + } + + UniformHandle *uniform_handle(const UniformData *ud, u32 i, char *dynamic) + { + return (UniformHandle *)(dynamic + ud[i].data_offset); + } + + TextureHandle *texture_handle(const TextureData *td, u32 i, char *dynamic) + { + return (TextureHandle *)(dynamic + td[i].data_offset); + } + +} // namespace material_resource + +} // namespace crown diff --git a/src/resource/mesh_animation_resource.cpp b/src/resource/mesh_animation_resource.cpp index d622b8191..372c478a5 100644 --- a/src/resource/mesh_animation_resource.cpp +++ b/src/resource/mesh_animation_resource.cpp @@ -3,6 +3,9 @@ * SPDX-License-Identifier: MIT */ +#include "config.h" + +#if CROWN_CAN_COMPILE #include "resource/mesh_animation_resource.h" #include "core/json/json_object.inl" #include "core/json/sjson.h" @@ -15,7 +18,6 @@ namespace crown { -#if CROWN_CAN_COMPILE namespace mesh_animation_resource_internal { static s32 write(MeshAnimation &ma, CompileOptions &opts) @@ -61,20 +63,6 @@ namespace mesh_animation_resource_internal } } // namespace mesh_animation_resource_internal -#endif // if CROWN_CAN_COMPILE - -namespace mesh_animation_resource -{ - const AnimationKey *animation_keys(const MeshAnimationResource *mar) - { - return (AnimationKey *)((char *)mar + mar->keys_offset); - } - - const u16 *bone_ids(const MeshAnimationResource *mar) - { - return (u16 *)((char *)mar + mar->bone_ids_offset); - } - -} // namespace mesh_animation_resource } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/mesh_animation_resource.inl b/src/resource/mesh_animation_resource.inl new file mode 100644 index 000000000..27ad696af --- /dev/null +++ b/src/resource/mesh_animation_resource.inl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/mesh_animation_resource.h" + +namespace crown +{ +namespace mesh_animation_resource +{ + const AnimationKey *animation_keys(const MeshAnimationResource *mar) + { + return (AnimationKey *)((char *)mar + mar->keys_offset); + } + + const u16 *bone_ids(const MeshAnimationResource *mar) + { + return (u16 *)((char *)mar + mar->bone_ids_offset); + } + +} // namespace mesh_animation_resource + +} // namespace crown diff --git a/src/resource/mesh_skeleton_resource.cpp b/src/resource/mesh_skeleton_resource.cpp index cb52b2825..15b7ca138 100644 --- a/src/resource/mesh_skeleton_resource.cpp +++ b/src/resource/mesh_skeleton_resource.cpp @@ -3,6 +3,9 @@ * SPDX-License-Identifier: MIT */ +#include "config.h" + +#if CROWN_CAN_COMPILE #include "resource/mesh_skeleton_resource.h" #include "core/containers/array.inl" #include "core/json/json_object.inl" @@ -13,7 +16,6 @@ namespace crown { -#if CROWN_CAN_COMPILE namespace mesh_skeleton_resource_internal { s32 write(AnimationSkeleton &s, CompileOptions &opts) @@ -52,25 +54,6 @@ namespace mesh_skeleton_resource_internal } } // namespace mesh_skeleton_resource_internal -#endif // if CROWN_CAN_COMPILE - -namespace mesh_skeleton_resource -{ - const BoneTransform *local_transforms(const MeshSkeletonResource *asr) - { - return (BoneTransform *)((char *)asr + asr->local_transforms_offset); - } - - const u32 *parents(const MeshSkeletonResource *asr) - { - return (u32 *)((char *)asr + asr->parents_offset); - } - - const Matrix4x4 *binding_matrices(const MeshSkeletonResource *asr) - { - return (Matrix4x4 *)((char *)asr + asr->binding_matrices_offset); - } - -} // namespace mesh_skeleton_resource } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/mesh_skeleton_resource.inl b/src/resource/mesh_skeleton_resource.inl new file mode 100644 index 000000000..da312fe5d --- /dev/null +++ b/src/resource/mesh_skeleton_resource.inl @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/mesh_skeleton_resource.h" + +namespace crown +{ +namespace mesh_skeleton_resource +{ + const BoneTransform *local_transforms(const MeshSkeletonResource *asr) + { + return (BoneTransform *)((char *)asr + asr->local_transforms_offset); + } + + const u32 *parents(const MeshSkeletonResource *asr) + { + return (u32 *)((char *)asr + asr->parents_offset); + } + + const Matrix4x4 *binding_matrices(const MeshSkeletonResource *asr) + { + return (Matrix4x4 *)((char *)asr + asr->binding_matrices_offset); + } + +} // namespace mesh_skeleton_resource + +} // namespace crown diff --git a/src/resource/package_resource.cpp b/src/resource/package_resource.cpp index 40e537964..889768d9c 100644 --- a/src/resource/package_resource.cpp +++ b/src/resource/package_resource.cpp @@ -4,6 +4,8 @@ */ #include "config.h" + +#if CROWN_CAN_COMPILE #include "core/containers/array.inl" #include "core/containers/hash_map.inl" #include "core/containers/hash_set.inl" @@ -44,7 +46,6 @@ bool operator==(const ResourceOffset &a, const ResourceOffset &b) ; } -#if CROWN_CAN_COMPILE namespace package_resource_internal { s32 bring_in_requirements(HashSet &output @@ -308,22 +309,6 @@ namespace package_resource_internal } } // namespace package_resource_internal -#endif // if CROWN_CAN_COMPILE - -namespace package_resource -{ - const ResourceOffset *resource_offset(const PackageResource *pr, u32 index) - { - const ResourceOffset *ro = (ResourceOffset *)(pr + 1); - return ro + index; - } - - const u8 *data(const PackageResource *pr) - { - const u8 *data_offset = (u8 *)resource_offset(pr, pr->num_resources); - return (u8 *)memory::align_top(data_offset, 16); - } - -} // namespace package_resource } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/package_resource.inl b/src/resource/package_resource.inl new file mode 100644 index 000000000..d3660a41d --- /dev/null +++ b/src/resource/package_resource.inl @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "core/memory/memory.inl" +#include "resource/package_resource.h" + +namespace crown +{ +namespace package_resource +{ + const ResourceOffset *resource_offset(const PackageResource *pr, u32 index) + { + const ResourceOffset *ro = (ResourceOffset *)(pr + 1); + return ro + index; + } + + const u8 *data(const PackageResource *pr) + { + const u8 *data_offset = (u8 *)resource_offset(pr, pr->num_resources); + return (u8 *)memory::align_top(data_offset, 16); + } + +} // namespace package_resource + +} // namespace crown diff --git a/src/resource/physics_resource.cpp b/src/resource/physics_resource.cpp index 0c33f8336..2e9227b15 100644 --- a/src/resource/physics_resource.cpp +++ b/src/resource/physics_resource.cpp @@ -4,6 +4,8 @@ */ #include "config.h" + +#if CROWN_CAN_COMPILE #include "core/containers/array.inl" #include "core/containers/hash_map.inl" #include "core/filesystem/file.h" @@ -27,59 +29,6 @@ namespace crown { -namespace physics_config_resource -{ - const PhysicsMaterial *materials_array(const PhysicsConfigResource *pcr) - { - return (const PhysicsMaterial *)((char *)pcr + pcr->materials_offset); - } - - u32 material_index(const PhysicsMaterial *materials, u32 num, StringId32 name) - { - for (u32 i = 0; i < num; ++i) { - if (materials[i].name == name) - return i; - } - - CE_FATAL("Material not found"); - return UINT32_MAX; - } - - const PhysicsActor *actors_array(const PhysicsConfigResource *pcr) - { - return (const PhysicsActor *)((char *)pcr + pcr->actors_offset); - } - - u32 actor_index(const PhysicsActor *actors, u32 num, StringId32 name) - { - for (u32 i = 0; i < num; ++i) { - if (actors[i].name == name) - return i; - } - - CE_FATAL("Actor not found"); - return UINT32_MAX; - } - - const PhysicsCollisionFilter *filters_array(const PhysicsConfigResource *pcr) - { - return (const PhysicsCollisionFilter *)((char *)pcr + pcr->filters_offset); - } - - u32 filter_index(const PhysicsCollisionFilter *filters, u32 num, StringId32 name) - { - for (u32 i = 0; i < num; ++i) { - if (filters[i].name == name) - return i; - } - - CE_FATAL("Filter not found"); - return UINT32_MAX; - } - -} // namespace physics_config_resource - -#if CROWN_CAN_COMPILE namespace physics_resource_internal { struct ColliderInfo @@ -697,6 +646,6 @@ namespace physics_config_resource_internal } } // namespace physics_config_resource_internal -#endif // if CROWN_CAN_COMPILE } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/physics_resource.inl b/src/resource/physics_resource.inl new file mode 100644 index 000000000..ccdff5674 --- /dev/null +++ b/src/resource/physics_resource.inl @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/physics_resource.h" + +namespace crown +{ +namespace physics_config_resource +{ + const PhysicsMaterial *materials_array(const PhysicsConfigResource *pcr) + { + return (const PhysicsMaterial *)((char *)pcr + pcr->materials_offset); + } + + u32 material_index(const PhysicsMaterial *materials, u32 num, StringId32 name) + { + for (u32 i = 0; i < num; ++i) { + if (materials[i].name == name) + return i; + } + + CE_FATAL("Material not found"); + return UINT32_MAX; + } + + const PhysicsActor *actors_array(const PhysicsConfigResource *pcr) + { + return (const PhysicsActor *)((char *)pcr + pcr->actors_offset); + } + + u32 actor_index(const PhysicsActor *actors, u32 num, StringId32 name) + { + for (u32 i = 0; i < num; ++i) { + if (actors[i].name == name) + return i; + } + + CE_FATAL("Actor not found"); + return UINT32_MAX; + } + + const PhysicsCollisionFilter *filters_array(const PhysicsConfigResource *pcr) + { + return (const PhysicsCollisionFilter *)((char *)pcr + pcr->filters_offset); + } + + u32 filter_index(const PhysicsCollisionFilter *filters, u32 num, StringId32 name) + { + for (u32 i = 0; i < num; ++i) { + if (filters[i].name == name) + return i; + } + + CE_FATAL("Filter not found"); + return UINT32_MAX; + } + +} // namespace physics_config_resource + +} // namespace crown diff --git a/src/resource/resource_package.cpp b/src/resource/resource_package.cpp index 6df2c50c2..9bf1746b0 100644 --- a/src/resource/resource_package.cpp +++ b/src/resource/resource_package.cpp @@ -6,7 +6,7 @@ #include "core/containers/array.inl" #include "core/os.h" #include "core/strings/string_id.inl" -#include "resource/package_resource.h" +#include "resource/package_resource.inl" #include "resource/resource_id.inl" #include "resource/resource_manager.h" #include "resource/resource_package.h" diff --git a/src/resource/sound_resource.cpp b/src/resource/sound_resource.cpp index 67601ce78..042a9432f 100644 --- a/src/resource/sound_resource.cpp +++ b/src/resource/sound_resource.cpp @@ -4,6 +4,8 @@ */ #include "config.h" + +#if CROWN_CAN_COMPILE #include "core/containers/array.inl" #include "core/filesystem/file.h" #include "core/json/json_object.inl" @@ -17,21 +19,6 @@ namespace crown { -namespace sound_resource -{ - const u8 *stream_metadata(const SoundResource *sr) - { - return (u8 *)&sr[1]; - } - - const u8 *pcm_data(const SoundResource *sr) - { - return (u8 *)sr + sr->pcm_offset; - } - -} // namespace sound_resource - -#if CROWN_CAN_COMPILE namespace sound_resource_internal { s32 compile(CompileOptions &opts) @@ -43,6 +30,6 @@ namespace sound_resource_internal } } // namespace sound_resource_internal -#endif // if CROWN_CAN_COMPILE } // namespace crown +#endif // if CROWN_CAN_COMPILE diff --git a/src/resource/sound_resource.inl b/src/resource/sound_resource.inl new file mode 100644 index 000000000..0c68cb98d --- /dev/null +++ b/src/resource/sound_resource.inl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/sound_resource.h" + +namespace crown +{ +namespace sound_resource +{ + const u8 *stream_metadata(const SoundResource *sr) + { + return (u8 *)&sr[1]; + } + + const u8 *pcm_data(const SoundResource *sr) + { + return (u8 *)sr + sr->pcm_offset; + } + +} // namespace sound_resource + +} // namespace crown diff --git a/src/resource/sprite_resource.cpp b/src/resource/sprite_resource.cpp index 41a4281cd..9d79266bf 100644 --- a/src/resource/sprite_resource.cpp +++ b/src/resource/sprite_resource.cpp @@ -25,16 +25,6 @@ LOG_SYSTEM(SPRITE_ANIMATION_RESOURCE, "sprite_animation_resource") namespace crown { -namespace sprite_resource -{ - const f32 *frame_data(const SpriteResource *sr, u32 i) - { - CE_ENSURE(i < sr->num_frames); - return ((f32 *)&sr[1]) + 20*i; - } - -} // namespace sprite_resource - #if CROWN_CAN_COMPILE namespace sprite_resource_internal { @@ -184,18 +174,7 @@ namespace sprite_resource_internal } } // namespace sprite_resource_internal -#endif // if CROWN_CAN_COMPILE -namespace sprite_animation_resource -{ - const u32 *frames(const SpriteAnimationResource *sar) - { - return (u32 *)&sar[1]; - } - -} // namespace sprite_animation_resource - -#if CROWN_CAN_COMPILE struct SpriteAnimationFrame { u32 frame; // Sprite frame. diff --git a/src/resource/sprite_resource.inl b/src/resource/sprite_resource.inl new file mode 100644 index 000000000..f5fa17f24 --- /dev/null +++ b/src/resource/sprite_resource.inl @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/sprite_resource.h" + +namespace crown +{ +namespace sprite_resource +{ + const f32 *frame_data(const SpriteResource *sr, u32 i) + { + CE_ENSURE(i < sr->num_frames); + return ((f32 *)&sr[1]) + 20*i; + } + +} // namespace sprite_resource + +namespace sprite_animation_resource +{ + const u32 *frames(const SpriteAnimationResource *sar) + { + return (u32 *)&sar[1]; + } + +} // namespace sprite_animation_resource + +} // namespace crown diff --git a/src/resource/state_machine_resource.cpp b/src/resource/state_machine_resource.cpp index cf54c0db4..9f689bd7b 100644 --- a/src/resource/state_machine_resource.cpp +++ b/src/resource/state_machine_resource.cpp @@ -23,90 +23,6 @@ namespace crown { -namespace state_machine -{ - const State *initial_state(const StateMachineResource *smr) - { - return (State *)((char *)smr + smr->initial_state_offset); - } - - const State *state(const StateMachineResource *smr, const Transition *t) - { - return (State *)((char *)smr + t->state_offset); - } - - const State *trigger(const StateMachineResource *smr, const State *s, StringId32 event, const Transition **transition_out) - { - const TransitionArray *ta = state_transitions(s); - - for (u32 i = 0; i < ta->num; ++i) { - const Transition *transition_i = transition(ta, i); - - if (transition_i->event == event) { - *transition_out = transition_i; - return state(smr, transition_i); - } - } - - *transition_out = NULL; - return s; - } - - const TransitionArray *state_transitions(const State *s) - { - return &s->ta; - } - - const Transition *transition(const TransitionArray *ta, u32 index) - { - CE_ASSERT(index < ta->num, "Index out of bounds"); - const Transition *first = (Transition *)(&ta[1]); - return &first[index]; - } - - const AnimationArray *state_animations(const State *s) - { - const TransitionArray *ta = state_transitions(s); - const Transition *first = (Transition *)(&ta[1]); - return (AnimationArray *)(first + ta->num); - } - - const Animation *animation(const AnimationArray *aa, u32 index) - { - CE_ASSERT(index < aa->num, "Index out of bounds"); - Animation *first = (Animation *)(memory::align_top((void *)&aa[1], alignof(Animation))); - return &first[index]; - } - - static inline const StringId32 *variables_names(const StateMachineResource *smr) - { - return (StringId32 *)((char *)smr + smr->variables_offset); - } - - const f32 *variables(const StateMachineResource *smr) - { - const StringId32 *names = variables_names(smr); - return (f32 *)(names + smr->num_variables); - } - - u32 variable_index(const StateMachineResource *smr, StringId32 name) - { - const StringId32 *names = variables_names(smr); - for (u32 i = 0; i < smr->num_variables; ++i) { - if (names[i] == name) - return i; - } - - return UINT32_MAX; - } - - const u32 *byte_code(const StateMachineResource *smr) - { - return (u32 *)((char *)smr + smr->bytecode_offset); - } - -} // namespace state_machine - #if CROWN_CAN_COMPILE namespace state_machine_resource_internal { diff --git a/src/resource/state_machine_resource.inl b/src/resource/state_machine_resource.inl new file mode 100644 index 000000000..9948fcf18 --- /dev/null +++ b/src/resource/state_machine_resource.inl @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/state_machine_resource.h" + +namespace crown +{ +namespace state_machine +{ + const State *initial_state(const StateMachineResource *smr) + { + return (State *)((char *)smr + smr->initial_state_offset); + } + + const State *state(const StateMachineResource *smr, const Transition *t) + { + return (State *)((char *)smr + t->state_offset); + } + + const State *trigger(const StateMachineResource *smr, const State *s, StringId32 event, const Transition **transition_out) + { + const TransitionArray *ta = state_transitions(s); + + for (u32 i = 0; i < ta->num; ++i) { + const Transition *transition_i = transition(ta, i); + + if (transition_i->event == event) { + *transition_out = transition_i; + return state(smr, transition_i); + } + } + + *transition_out = NULL; + return s; + } + + const TransitionArray *state_transitions(const State *s) + { + return &s->ta; + } + + const Transition *transition(const TransitionArray *ta, u32 index) + { + CE_ASSERT(index < ta->num, "Index out of bounds"); + const Transition *first = (Transition *)(&ta[1]); + return &first[index]; + } + + const AnimationArray *state_animations(const State *s) + { + const TransitionArray *ta = state_transitions(s); + const Transition *first = (Transition *)(&ta[1]); + return (AnimationArray *)(first + ta->num); + } + + const Animation *animation(const AnimationArray *aa, u32 index) + { + CE_ASSERT(index < aa->num, "Index out of bounds"); + Animation *first = (Animation *)(memory::align_top((void *)&aa[1], alignof(Animation))); + return &first[index]; + } + + static inline const StringId32 *variables_names(const StateMachineResource *smr) + { + return (StringId32 *)((char *)smr + smr->variables_offset); + } + + const f32 *variables(const StateMachineResource *smr) + { + const StringId32 *names = variables_names(smr); + return (f32 *)(names + smr->num_variables); + } + + u32 variable_index(const StateMachineResource *smr, StringId32 name) + { + const StringId32 *names = variables_names(smr); + for (u32 i = 0; i < smr->num_variables; ++i) { + if (names[i] == name) + return i; + } + + return UINT32_MAX; + } + + const u32 *byte_code(const StateMachineResource *smr) + { + return (u32 *)((char *)smr + smr->bytecode_offset); + } + +} // namespace state_machine + +} // namespace crown diff --git a/src/resource/unit_resource.cpp b/src/resource/unit_resource.cpp index ab3e8fb27..2f6d9ba82 100644 --- a/src/resource/unit_resource.cpp +++ b/src/resource/unit_resource.cpp @@ -31,32 +31,4 @@ namespace unit_resource_internal } // namespace unit_resource_internal #endif -namespace unit_resource -{ - const u32 *parents(const UnitResource *ur) - { - return (u32 *)&ur[1]; - } - - const ComponentData *component_type_data(const UnitResource *ur, const ComponentData *component) - { - if (component == NULL) - return (ComponentData *)(parents(ur) + ur->num_units); - else - return (ComponentData *)memory::align_top(component_payload(component) + component->data_size, alignof(ComponentData)); - } - - const u32 *component_unit_index(const ComponentData *component) - { - return (u32 *)(&component[1]); - } - - const char *component_payload(const ComponentData *component) - { - const u32 *unit_index = component_unit_index(component); - return (char *)memory::align_top(unit_index + component->num_instances, 16); - } - -} // namespace unit_resource - } // namespace crown diff --git a/src/resource/unit_resource.inl b/src/resource/unit_resource.inl new file mode 100644 index 000000000..ce1cb10ad --- /dev/null +++ b/src/resource/unit_resource.inl @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012-2026 Daniele Bartolini et al. + * SPDX-License-Identifier: MIT + */ + +#include "resource/unit_resource.h" + +namespace crown +{ +namespace unit_resource +{ + const u32 *parents(const UnitResource *ur) + { + return (u32 *)&ur[1]; + } + + const ComponentData *component_type_data(const UnitResource *ur, const ComponentData *component) + { + if (component == NULL) + return (ComponentData *)(parents(ur) + ur->num_units); + else + return (ComponentData *)memory::align_top(component_payload(component) + component->data_size, alignof(ComponentData)); + } + + const u32 *component_unit_index(const ComponentData *component) + { + return (u32 *)(&component[1]); + } + + const char *component_payload(const ComponentData *component) + { + const u32 *unit_index = component_unit_index(component); + return (char *)memory::align_top(unit_index + component->num_instances, 16); + } + +} // namespace unit_resource + +} // namespace crown diff --git a/src/world/animation_state_machine.cpp b/src/world/animation_state_machine.cpp index 22cb3d145..9eb15a732 100644 --- a/src/world/animation_state_machine.cpp +++ b/src/world/animation_state_machine.cpp @@ -14,7 +14,8 @@ #include "resource/expression_language.h" #include "resource/resource_manager.h" #include "resource/sprite_resource.h" -#include "resource/state_machine_resource.h" +#include "resource/mesh_skeleton_resource.inl" +#include "resource/state_machine_resource.inl" #include "world/animation_state_machine.h" #include "world/event_stream.inl" #include "world/render_world.h" diff --git a/src/world/gui.cpp b/src/world/gui.cpp index 868787198..90f98a2e7 100644 --- a/src/world/gui.cpp +++ b/src/world/gui.cpp @@ -12,7 +12,7 @@ #include "core/strings/string.inl" #include "core/strings/string_id.inl" #include "core/strings/utf8.h" -#include "resource/font_resource.h" +#include "resource/font_resource.inl" #include "resource/material_resource.h" #include "resource/resource_manager.h" #include "world/gui.h" diff --git a/src/world/level.cpp b/src/world/level.cpp index cc43f9543..3ed252022 100644 --- a/src/world/level.cpp +++ b/src/world/level.cpp @@ -7,7 +7,7 @@ #include "core/math/constants.h" #include "core/memory/memory.inl" #include "core/strings/string_id.inl" -#include "resource/level_resource.h" +#include "resource/level_resource.inl" #include "world/level.h" namespace crown diff --git a/src/world/material_manager.cpp b/src/world/material_manager.cpp index 8e5d42fd8..a08faac8c 100644 --- a/src/world/material_manager.cpp +++ b/src/world/material_manager.cpp @@ -7,7 +7,7 @@ #include "core/containers/hash_map.inl" #include "core/filesystem/file.h" #include "core/strings/string_id.inl" -#include "resource/material_resource.h" +#include "resource/material_resource.inl" #include "resource/resource_manager.h" #include "resource/texture_resource.h" #include "world/material_manager.h" diff --git a/src/world/mesh_animation_player.cpp b/src/world/mesh_animation_player.cpp index 2803d340c..906875bcf 100644 --- a/src/world/mesh_animation_player.cpp +++ b/src/world/mesh_animation_player.cpp @@ -12,6 +12,7 @@ #include "core/profiler.h" #include "core/strings/string_id.inl" #include "device/device.h" +#include "resource/mesh_animation_resource.inl" #include "resource/resource_manager.h" #include "world/mesh_animation_player.h" #include "world/scene_graph.h" diff --git a/src/world/physics_world_bullet.cpp b/src/world/physics_world_bullet.cpp index c3276d60c..bf0eef691 100644 --- a/src/world/physics_world_bullet.cpp +++ b/src/world/physics_world_bullet.cpp @@ -18,7 +18,7 @@ #include "core/profiler.h" #include "core/strings/string_id.inl" #include "device/log.h" -#include "resource/physics_resource.h" +#include "resource/physics_resource.inl" #include "resource/resource_manager.h" #include "world/debug_line.h" #include "world/event_stream.inl" diff --git a/src/world/render_world.cpp b/src/world/render_world.cpp index 224e7f0df..0478b50bb 100644 --- a/src/world/render_world.cpp +++ b/src/world/render_world.cpp @@ -18,7 +18,7 @@ #include "resource/mesh_resource.h" #include "resource/render_config_resource.h" #include "resource/resource_manager.h" -#include "resource/sprite_resource.h" +#include "resource/sprite_resource.inl" #include "world/debug_line.h" #include "world/material.h" #include "world/material_manager.h" diff --git a/src/world/sound_world_al.cpp b/src/world/sound_world_al.cpp index 314101bb0..ed1c99501 100644 --- a/src/world/sound_world_al.cpp +++ b/src/world/sound_world_al.cpp @@ -15,7 +15,7 @@ #include "core/memory/temp_allocator.inl" #include "device/log.h" #include "resource/resource_manager.h" -#include "resource/sound_resource.h" +#include "resource/sound_resource.inl" #include "resource/sound_ogg.h" #include "world/sound_world.h" #include diff --git a/src/world/world.cpp b/src/world/world.cpp index 47eae1fb0..498e114cd 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -16,7 +16,7 @@ #include "lua/lua_environment.h" #include "resource/level_resource.h" #include "resource/resource_manager.h" -#include "resource/unit_resource.h" +#include "resource/unit_resource.inl" #include "world/animation_state_machine.h" #include "world/debug_line.h" #include "world/event_stream.inl"