From b293168cc158d65f1a5146f155921ff82119d1bc Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 23 Dec 2024 14:41:01 +1100 Subject: Texture conversion and loading --- asset.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'asset.cpp') diff --git a/asset.cpp b/asset.cpp index 09260e0..fc6d22b 100644 --- a/asset.cpp +++ b/asset.cpp @@ -8,6 +8,7 @@ extern "C" { } #define max_asset_types 32 +#define asset_scratch_size (1024 * 1024) struct RLoader { char magic[4]; @@ -68,13 +69,19 @@ void register_asset_loader( void Asset_Arena::init(Arena* arena, const char* pack_name) { p = pack_open(pack_name, arena); a = arena; + s = (Arena*)arena_alloc(a, sizeof *s); + init_arena( + s, + arena_alloc(a, asset_scratch_size), + asset_scratch_size + ); assets = 0; } void Asset_Arena::destroy() { Asset* a; for (a = assets; a; a = a->next) { - a->unload(a->loader); + a->loader->unload(a); } pack_close(p); } @@ -93,9 +100,12 @@ Asset* Asset_Arena::load(const char* name) { pack_read(f, magic, 4); pack_seek(f, 0, seek_rel_start); Asset_Loader& loader = manager.get_loader(magic); - Asset* asset = loader.load(a, f); - asset->loader = &loader; + clear_arena(s); + Asset* asset = loader.load(a, s, f); + if (asset) { + asset->loader = &loader; + claim(asset); + } pack_close_file(f); - claim(asset); return asset; } -- cgit v1.2.3-54-g00ecf