summaryrefslogtreecommitdiff
path: root/asset.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-23 14:41:01 +1100
committerquou <quou@disroot.org>2024-12-23 14:41:01 +1100
commitb293168cc158d65f1a5146f155921ff82119d1bc (patch)
tree08cc5ee235b4b7ca6ead45c43f9b407664971613 /asset.cpp
parent58245585cbe77e6c03ebe13f29e10393ff3c45b4 (diff)
Texture conversion and loading
Diffstat (limited to 'asset.cpp')
-rw-r--r--asset.cpp18
1 files changed, 14 insertions, 4 deletions
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;
}