Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lua/lua_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdarg.h>

Expand Down
23 changes: 3 additions & 20 deletions src/resource/font_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -120,6 +103,6 @@ namespace font_resource_internal
}

} // namespace font_resource_internal
#endif // if CROWN_CAN_COMPILE

} // namespace crown
#endif // if CROWN_CAN_COMPILE
28 changes: 28 additions & 0 deletions src/resource/font_resource.inl
Original file line number Diff line number Diff line change
@@ -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
32 changes: 4 additions & 28 deletions src/resource/level_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -155,6 +131,6 @@ namespace level_resource_internal
}

} // namespace level_resource_internal
#endif // if CROWN_CAN_COMPILE

} // namespace crown
#endif // if CROWN_CAN_COMPILE
36 changes: 36 additions & 0 deletions src/resource/level_resource.inl
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions src/resource/lua_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -180,6 +172,6 @@ namespace lua_resource_internal
}

} // namespace lua_resource_internal
#endif // if CROWN_CAN_COMPILE

} // namespace crown
#endif // if CROWN_CAN_COMPILE
19 changes: 19 additions & 0 deletions src/resource/lua_resource.inl
Original file line number Diff line number Diff line change
@@ -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
56 changes: 0 additions & 56 deletions src/resource/material_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
66 changes: 66 additions & 0 deletions src/resource/material_resource.inl
Original file line number Diff line number Diff line change
@@ -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
20 changes: 4 additions & 16 deletions src/resource/mesh_animation_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,7 +18,6 @@

namespace crown
{
#if CROWN_CAN_COMPILE
namespace mesh_animation_resource_internal
{
static s32 write(MeshAnimation &ma, CompileOptions &opts)
Expand Down Expand Up @@ -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
Loading