diff options
-rw-r--r-- | src/scene/scene_memory.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/src/scene/scene_memory.c b/src/scene/scene_memory.c index 85c27e7..4d7020a 100644 --- a/src/scene/scene_memory.c +++ b/src/scene/scene_memory.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "object_impl.h" | 12 | #include "object_impl.h" |
13 | #include "scene_impl.h" | 13 | #include "scene_impl.h" |
14 | 14 | ||
15 | #include <log/log.h> | ||
15 | #include <mempool.h> | 16 | #include <mempool.h> |
16 | 17 | ||
17 | DEF_MEMPOOL(anima_pool, Anima, GFX_MAX_NUM_ANIMAS) | 18 | DEF_MEMPOOL(anima_pool, Anima, GFX_MAX_NUM_ANIMAS) |
@@ -90,13 +91,40 @@ void scene_mem_destroy() { | |||
90 | // NOTE: the dummy objects are not constructed, so the destruction code below | 91 | // NOTE: the dummy objects are not constructed, so the destruction code below |
91 | // always skips index 0. (I don't really like the conditional inside the loop, | 92 | // always skips index 0. (I don't really like the conditional inside the loop, |
92 | // but this gets the job done without having to specialize the loop macro.) | 93 | // but this gets the job done without having to specialize the loop macro.) |
93 | #define DESTROY(name) \ | 94 | #define DESTROY(NAME) \ |
94 | mempool_foreach(&MEM_FIELD(name), obj, { \ | 95 | mempool_foreach(&MEM_FIELD(NAME), obj, { \ |
95 | if (i > 0) { \ | 96 | if (i > 0) { \ |
96 | gfx_destroy_##name(&obj); \ | 97 | gfx_destroy_##NAME(&obj); \ |
97 | } \ | 98 | } \ |
98 | }) | 99 | }) |
99 | 100 | ||
101 | // Print memory diagnostics. | ||
102 | #define PRINT_POOL(POOL_NAME, POOL) \ | ||
103 | { \ | ||
104 | const size_t capacity = mempool_capacity(POOL); \ | ||
105 | const size_t size = mempool_size(POOL); \ | ||
106 | const size_t block_size_bytes = mempool_block_size_bytes(POOL); \ | ||
107 | const size_t size_bytes = size * block_size_bytes; \ | ||
108 | const size_t capacity_bytes = capacity * block_size_bytes; \ | ||
109 | LOGI( \ | ||
110 | "%s pool: %lu/%lu (%lu/%lu bytes)", POOL_NAME, size, capacity, \ | ||
111 | size_bytes, capacity_bytes); \ | ||
112 | } | ||
113 | |||
114 | LOGI("Pool diagnostics:"); | ||
115 | PRINT_POOL("Animas", &mem.animas); | ||
116 | PRINT_POOL("Animations", &mem.animations); | ||
117 | PRINT_POOL("Cameras", &mem.cameras); | ||
118 | PRINT_POOL("Lights", &mem.lights); | ||
119 | PRINT_POOL("Materials", &mem.materials); | ||
120 | PRINT_POOL("Meshes", &mem.meshs); | ||
121 | PRINT_POOL("Mesh links", &mem.mesh_links); | ||
122 | PRINT_POOL("Models", &mem.models); | ||
123 | PRINT_POOL("Nodes", &mem.nodes); | ||
124 | PRINT_POOL("Objects", &mem.objects); | ||
125 | PRINT_POOL("Scenes", &mem.scenes); | ||
126 | PRINT_POOL("Skeletons", &mem.skeletons); | ||
127 | |||
100 | // Models contain scene elements. Destruction is handled by the remainder of | 128 | // Models contain scene elements. Destruction is handled by the remainder of |
101 | // scene destructionb elow. | 129 | // scene destructionb elow. |
102 | // | 130 | // |
@@ -119,20 +147,20 @@ void scene_mem_destroy() { | |||
119 | // Skeletons are owned by animas and do not have a destructor. | 147 | // Skeletons are owned by animas and do not have a destructor. |
120 | } | 148 | } |
121 | 149 | ||
122 | #define DEF_MEMORY(name, type) \ | 150 | #define DEF_MEMORY(NAME, TYPE) \ |
123 | /* xyz* mem_alloc_xyz(); */ \ | 151 | /* xyz* mem_alloc_xyz(); */ \ |
124 | type* mem_alloc_##name() { return mempool_alloc(&MEM_FIELD(name)); } \ | 152 | TYPE* mem_alloc_##NAME() { return mempool_alloc(&MEM_FIELD(NAME)); } \ |
125 | /* void mem_free_xyz(xyz**); */ \ | 153 | /* void mem_free_xyz(xyz**); */ \ |
126 | void mem_free_##name(type** obj) { mempool_free(&MEM_FIELD(name), obj); } \ | 154 | void mem_free_##NAME(TYPE** obj) { mempool_free(&MEM_FIELD(NAME), obj); } \ |
127 | /* xyz* mem_get_xyz(xyz_idx); */ \ | 155 | /* xyz* mem_get_xyz(xyz_idx); */ \ |
128 | type* mem_get_##name(NAMED_INDEX(name) index) { \ | 156 | TYPE* mem_get_##NAME(NAMED_INDEX(NAME) index) { \ |
129 | assert(index.val != 0); /* 0 is the dummy allocation. */ \ | 157 | assert(index.val != 0); /* 0 is the dummy allocation. */ \ |
130 | return mempool_get_block(&MEM_FIELD(name), index.val); \ | 158 | return mempool_get_block(&MEM_FIELD(NAME), index.val); \ |
131 | } \ | 159 | } \ |
132 | /* xyz_idx mem_get_xyz_index(const xyz*); */ \ | 160 | /* xyz_idx mem_get_xyz_index(const xyz*); */ \ |
133 | NAMED_INDEX(name) mem_get_##name##_index(const type* obj) { \ | 161 | NAMED_INDEX(NAME) mem_get_##NAME##_index(const TYPE* obj) { \ |
134 | return (NAMED_INDEX(name)){ \ | 162 | return (NAMED_INDEX(NAME)){ \ |
135 | .val = mempool_get_block_index(&MEM_FIELD(name), obj)}; \ | 163 | .val = mempool_get_block_index(&MEM_FIELD(NAME), obj)}; \ |
136 | } | 164 | } |
137 | 165 | ||
138 | DEF_MEMORY(anima, Anima) | 166 | DEF_MEMORY(anima, Anima) |