diff options
Diffstat (limited to 'asset.cpp')
-rw-r--r-- | asset.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -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; } |