diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-27 14:01:16 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-27 14:01:16 +1000 |
commit | aa0fe8457cfff9c47c0c9fa4a1c86a79c7cbf9c5 (patch) | |
tree | a7fa374cb59c6c59e386086dcdae8a7efc372b5f | |
parent | 2e2c57a8c04575eec164279a49947cfdba250853 (diff) |
add a pool insert function. move RenderEnt to use handles
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | examples/game_demo/game_demo.c | 9 | ||||
-rw-r--r-- | src/core/core.c | 4 | ||||
-rw-r--r-- | src/defines.h | 2 | ||||
-rw-r--r-- | src/maths/maths.h | 20 | ||||
-rw-r--r-- | src/maths/maths_types.h | 4 | ||||
-rw-r--r-- | src/new_render/pbr.c | 12 | ||||
-rw-r--r-- | src/new_render/pbr.h | 1 | ||||
-rw-r--r-- | src/new_render/render.c | 21 | ||||
-rw-r--r-- | src/new_render/render.h | 7 | ||||
-rw-r--r-- | src/new_render/render_types.h | 59 | ||||
-rw-r--r-- | src/new_render/shadows.c | 6 | ||||
-rw-r--r-- | src/new_render/skybox.h | 2 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 3 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.h | 2 | ||||
-rw-r--r-- | src/ral/ral_types.h | 2 | ||||
-rw-r--r-- | src/resources/gltf.c | 21 | ||||
-rw-r--r-- | src/std/mem.c | 7 | ||||
-rw-r--r-- | src/std/mem.h | 7 |
19 files changed, 128 insertions, 67 deletions
@@ -145,4 +145,8 @@ All third-party dependencies are licensed under their own license. - [ ] Replace screenshot with one using PBR + skybox + shadows - [ ] Update website -- [ ] Check licenses of assets currently in `assets` folder
\ No newline at end of file +- [ ] Check licenses of assets currently in `assets` folder + +## Questions + +- How to expose material properties in the immediate mode UI?
\ No newline at end of file diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c index 7b746d3..5b69251 100644 --- a/examples/game_demo/game_demo.c +++ b/examples/game_demo/game_demo.c @@ -60,6 +60,7 @@ int main() { // gltf file Geometry cube_geo = Geo_CreateCuboid(f32x3(2.0, 2.0, 2.0)); Mesh crate_mesh = Mesh_Create(&cube_geo, false); // dont free as we may use later + MeshHandle crate_mesh_handle = Mesh_pool_insert(Render_GetMeshPool(), &crate_mesh); // TextureHandle albedo_map = // TextureLoadFromFile("assets/demo/crate/Wood_Crate_001_basecolor.jpg"); TextureHandle roughness_map = @@ -75,6 +76,7 @@ int main() { crate_mat.ambient_occlusion_map = ao_map; crate_mat.base_colour = vec3(1.0, 1.0, 1.0); crate_mat.metallic = 0.0; + MaterialHandle crate_mat_handle = Material_pool_insert(Render_GetMaterialPool(), &crate_mat); // ModelHandle cube_handle = ModelLoad_gltf("assets/models/gltf/Cube/glTF/Cube.gltf", false); // ModelHandle cube_handle = ModelLoad_gltf("../../assets/prototyper/prototyper_m.gltf", false); @@ -84,9 +86,10 @@ int main() { // .affine = mat4_ident(), // .casts_shadows = true }; - RenderEnt crate_renderable = { - .mesh = &crate_mesh, .material = &crate_mat, .affine = mat4_scale(3.0), .casts_shadows = true - }; + RenderEnt crate_renderable = { .mesh = crate_mesh_handle, + .material = crate_mat_handle, + .affine = mat4_scale(3.0), + .flags = (REND_ENT_CASTS_SHADOWS | REND_ENT_VISIBLE) }; RenderEnt entities[] = { crate_renderable }; size_t entity_count = 1; diff --git a/src/core/core.c b/src/core/core.c index fffb43d..20bc813 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -78,4 +78,6 @@ Core* get_global_core() { return &g_core; } GLFWwindow* Core_GetGlfwWindowPtr(Core* core) { return g_core.window; } -struct Renderer* Core_GetRenderer(Core* core) { return core->renderer; }
\ No newline at end of file +struct Renderer* Core_GetRenderer(Core* core) { + return core->renderer; +}
\ No newline at end of file diff --git a/src/defines.h b/src/defines.h index b7bf34d..108edef 100644 --- a/src/defines.h +++ b/src/defines.h @@ -56,7 +56,7 @@ CORE_DEFINE_HANDLE( #define PUB // For collecting public APIs to expose in an amalgamation header file // #define c_static_inline static inline -#define c_static_inline inline +#define c_static_inline #define KB(x) ((size_t)x * 1000) #define MB(x) ((size_t)x * 1000 * 1000) diff --git a/src/maths/maths.h b/src/maths/maths.h index a6f8d80..5055637 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -48,14 +48,14 @@ static const Vec3 VEC3_NEG_Z = vec3(0.0, 0.0, -1.0); static const Vec3 VEC3_ZERO = vec3(0.0, 0.0, 0.0); static const Vec3 VEC3_ONES = vec3(1.0, 1.0, 1.0); -c_static_inline void print_vec3(Vec3 v) { +static void print_vec3(Vec3 v) { printf("{ x: %f, y: %f, z: %f )\n", (f64)v.x, (f64)v.y, (f64)v.z); } // TODO: Dimension 2 -c_static_inline Vec2 vec2_create(f32 x, f32 y) { return (Vec2){ x, y }; } +static Vec2 vec2_create(f32 x, f32 y) { return (Vec2){ x, y }; } #define vec2(x, y) ((Vec2){ x, y }) -c_static_inline Vec2 vec2_div(Vec2 a, f32 s) { return (Vec2){ a.x / s, a.y / s }; } +static Vec2 vec2_div(Vec2 a, f32 s) { return (Vec2){ a.x / s, a.y / s }; } // TODO: Dimension 4 static Vec4 vec4_create(f32 x, f32 y, f32 z, f32 w) { return (Vec4){ x, y, z, w }; } @@ -64,17 +64,15 @@ static Vec4 vec4_create(f32 x, f32 y, f32 z, f32 w) { return (Vec4){ x, y, z, w // --- Quaternion Implementations -c_static_inline f32 quat_dot(Quat a, Quat b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; -} +static f32 quat_dot(Quat a, Quat b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } -c_static_inline Quat quat_normalise(Quat a) { +static Quat quat_normalise(Quat a) { f32 length = sqrtf(quat_dot(a, a)); // same as len squared return (Quat){ a.x / length, a.y / length, a.z / length, a.w / length }; } -c_static_inline Quat quat_ident() { return (Quat){ .x = 0.0, .y = 0.0, .z = 0.0, .w = 1.0 }; } +static Quat quat_ident() { return (Quat){ .x = 0.0, .y = 0.0, .z = 0.0, .w = 1.0 }; } static Quat quat_from_axis_angle(Vec3 axis, f32 angle, bool normalize) { const f32 half_angle = 0.5f * angle; @@ -89,7 +87,7 @@ static Quat quat_from_axis_angle(Vec3 axis, f32 angle, bool normalize) { } // TODO: grok this. -c_static_inline Quat quat_slerp(Quat a, Quat b, f32 percentage) { +static Quat quat_slerp(Quat a, Quat b, f32 percentage) { Quat out_quaternion; Quat q0 = quat_normalise(a); @@ -158,7 +156,7 @@ static Mat4 mat4_scale(f32 scale) { } // TODO: double check this -c_static_inline Mat4 mat4_rotation(Quat rotation) { +static Mat4 mat4_rotation(Quat rotation) { Mat4 out_matrix = mat4_ident(); Quat n = quat_normalise(rotation); @@ -313,7 +311,7 @@ static Transform transform_create(Vec3 pos, Quat rot, f32 scale) { return (Transform){ .position = pos, .rotation = rot, .scale = scale, .is_dirty = true }; } -c_static_inline Mat4 transform_to_mat(Transform *tf) { +static Mat4 transform_to_mat(Transform *tf) { Mat4 scale = mat4_scale(tf->scale); Mat4 rotation = mat4_rotation(tf->rotation); Mat4 translation = mat4_translation(tf->position); diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h index 3fa3dac..2f84774 100644 --- a/src/maths/maths_types.h +++ b/src/maths/maths_types.h @@ -44,10 +44,10 @@ typedef struct Mat4 { typedef struct Bbox_3D { Vec3 min; // minimum point of the box Vec3 max; // maximum point of the box -} Bbox_3d; +} Bbox_3D; /** @brief 3D Axis-aligned bounding box */ -typedef Bbox_3d Aabb_3D; +typedef Bbox_3D Aabb_3D; /** @brief 3D affine transformation */ typedef struct Transform { diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c index ccc4dcf..09da50e 100644 --- a/src/new_render/pbr.c +++ b/src/new_render/pbr.c @@ -103,12 +103,16 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te enc, 3, (ShaderData){ .data = &lights_data, .get_layout = &Binding_Lights_GetLayout }); // TODO: Add shadowmap texture to uniforms + Mesh_pool* mesh_pool = Render_GetMeshPool(); + Material_pool* material_pool = Render_GetMaterialPool(); for (size_t ent_i = 0; ent_i < entity_count; ent_i++) { RenderEnt renderable = entities[ent_i]; + Mesh* mesh = Mesh_pool_get(mesh_pool, renderable.mesh); + Material* mat = Material_pool_get(material_pool, renderable.material); // upload material data - PBRMaterialUniforms material_data = { .mat = *renderable.material }; + PBRMaterialUniforms material_data = { .mat = *mat }; GPU_EncodeBindShaderData( enc, 2, (ShaderData){ .data = &material_data, .get_layout = PBRMaterial_GetLayout }); @@ -118,10 +122,10 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te enc, 1, (ShaderData){ .data = &model_data, .get_layout = &Binding_Model_GetLayout }); // set buffers - GPU_EncodeSetVertexBuffer(enc, renderable.mesh->vertex_buffer); - GPU_EncodeSetIndexBuffer(enc, renderable.mesh->index_buffer); + GPU_EncodeSetVertexBuffer(enc, mesh->vertex_buffer); + GPU_EncodeSetIndexBuffer(enc, mesh->index_buffer); // draw - GPU_EncodeDrawIndexed(enc, renderable.mesh->geometry.indices->len); + GPU_EncodeDrawIndexed(enc, mesh->geometry.index_count); } GPU_CmdEncoder_EndRender(enc); diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h index 0aa9dfe..d8c9405 100644 --- a/src/new_render/pbr.h +++ b/src/new_render/pbr.h @@ -48,7 +48,6 @@ typedef struct PBR_Textures { TextureHandle ao_map; } PBR_Textures; - // --- Internal typedef struct MaterialMap MaterialMap; diff --git a/src/new_render/render.c b/src/new_render/render.c index 5202cd3..235f1cb 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -23,6 +23,10 @@ #include <stb_image.h> #define FRAME_ARENA_SIZE MB(1) +#define POOL_SIZE_BYTES \ + MB(10) // we will reserve 10 megabytes up front to store resource, mesh, and material pools +#define MAX_MESHES 1024 +#define MAX_MATERIALS 256 extern Core g_core; @@ -37,8 +41,10 @@ struct Renderer { PBR_Storage* pbr; Shadow_Storage* shadows; Terrain_Storage* terrain; - // Text_Storage text; + // Text_Storage* text; ResourcePools* resource_pools; + Mesh_pool mesh_pool; + Material_pool material_pool; arena frame_arena; TextureHandle white_1x1; }; @@ -53,9 +59,11 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window // init resource pools DEBUG("Initialise GPU resource pools"); - arena pool_arena = arena_create(malloc(1024 * 1024), 1024 * 1024); + arena pool_arena = arena_create(malloc(POOL_SIZE_BYTES), POOL_SIZE_BYTES); ren->resource_pools = arena_alloc(&pool_arena, sizeof(struct ResourcePools)); ResourcePools_Init(&pool_arena, ren->resource_pools); + ren->mesh_pool = Mesh_pool_create(&pool_arena, MAX_MESHES, sizeof(Mesh)); + ren->material_pool = Material_pool_create(&pool_arena, MAX_MATERIALS, sizeof(Material)); // GLFW window creation GLFWwindow* window; @@ -288,4 +296,13 @@ TextureHandle Render_GetWhiteTexture() { arena* Render_GetFrameArena() { Renderer* ren = Core_GetRenderer(&g_core); return &ren->frame_arena; +} + +Mesh_pool* Render_GetMeshPool() { + Renderer* ren = Core_GetRenderer(&g_core); + return &ren->mesh_pool; +} +Material_pool* Render_GetMaterialPool() { + Renderer* ren = Core_GetRenderer(&g_core); + return &ren->material_pool; }
\ No newline at end of file diff --git a/src/new_render/render.h b/src/new_render/render.h index b8c34b9..ef11b5f 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -26,6 +26,9 @@ typedef struct RenderCtx { Mat4 projection; } RenderCtx; +// #define MESH_GET(h) (Mesh_pool_get(g_core.renderer->meshes, h)) +// #define MATERIAL_GET(h) (Material_pool_get(g_core.renderer->material, h)) + // --- Lifecycle PUB bool Renderer_Init(RendererConfig config, Renderer* renderer, GLFWwindow** out_window, @@ -79,4 +82,6 @@ RenderScene* Render_GetScene(); Shadow_Storage* Render_GetShadowStorage(); Terrain_Storage* Render_GetTerrainStorage(); TextureHandle Render_GetWhiteTexture(); -arena* Render_GetFrameArena();
\ No newline at end of file +arena* Render_GetFrameArena(); +Mesh_pool* Render_GetMeshPool(); +Material_pool* Render_GetMaterialPool();
\ No newline at end of file diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index f4f108a..2b7a77a 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -5,20 +5,24 @@ #pragma once #include "defines.h" -#include "maths.h" #include "maths_types.h" -#include "ral.h" +#include "mem.h" #include "ral_types.h" // --- Handles CORE_DEFINE_HANDLE(ModelHandle); -#define ABSENT_MODEL_HANDLE 999999999 +CORE_DEFINE_HANDLE(MaterialHandle); +CORE_DEFINE_HANDLE(MeshHandle); +#define INVALID_MODEL_HANDLE ((ModelHandle){ .raw = 9999991 }) +#define INVALID_MATERIAL_HANDLE ((MaterialHandle){ .raw = 9999992 }) +#define INVALID_MESH_HANDLE ((MeshHandle){ .raw = 9999993 }) typedef struct Geometry { VertexFormat format; Vertex_darray* vertices; - bool has_indices; u32_darray* indices; + bool has_indices; + size_t index_count; } Geometry; typedef struct u32_opt { @@ -29,13 +33,15 @@ typedef struct u32_opt { typedef struct Mesh { BufferHandle vertex_buffer; BufferHandle index_buffer; - Geometry geometry; // NULL means it has been freed CPU-side - i32 material_index; // -1 => no material - bool is_uploaded; // has the data been uploaded to the GPU + Geometry geometry; // NULL means it has been freed CPU-side + // i32 material_index; // -1 => no material + MaterialHandle material; + bool is_uploaded; // has the data been uploaded to the GPU } Mesh; -#ifndef TYPED_MESH_ARRAY +#ifndef TYPED_MESH_CONTAINERS KITC_DECL_TYPED_ARRAY(Mesh) -#define TYPED_MESH_ARRAY +TYPED_POOL(Mesh, Mesh) +#define TYPED_MESH_CONTAINERS #endif typedef struct TextureData { @@ -55,12 +61,12 @@ static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "P /** * @brief - * @note mostly references https://google.github.io/filament/Filament.html#materialsystem/standardmodel + * @note based on https://google.github.io/filament/Filament.html#materialsystem/standardmodel */ typedef struct Material { char name[64]; - MaterialKind kind; // at the moment all materials are PBR materials - Vec3 base_colour; // linear RGB {0,0,0} to {1,1,1} + MaterialKind kind; // at the moment all materials are PBR materials + Vec3 base_colour; // linear RGB {0,0,0} to {1,1,1} f32 metallic; f32 roughness; f32 ambient_occlusion; @@ -70,16 +76,19 @@ typedef struct Material { TextureHandle ambient_occlusion_map; } Material; -#ifndef TYPED_MATERIAL_ARRAY +#ifndef TYPED_MATERIAL_CONTAINERS KITC_DECL_TYPED_ARRAY(Material) -#define TYPED_MATERIAL_ARRAY +TYPED_POOL(Material, Material) +#define TYPED_MATERIAL_CONTAINERS #endif +/** @brief Convenient wrapper around a number of meshes each with a material */ typedef struct Model { Str8 name; - // meshes - Mesh_darray* meshes; - Material_darray* materials; + MeshHandle* meshes; + size_t mesh_count; + MaterialHandle* materials; + size_t material_count; } Model; #ifndef TYPED_MODEL_ARRAY KITC_DECL_TYPED_ARRAY(Model) @@ -106,13 +115,19 @@ typedef struct DirectionalLight { // --- -// A renderable 'thing' +typedef enum RenderEntityFlag { + REND_ENT_CASTS_SHADOWS = 1 << 0, + REND_ENT_VISIBLE = 1 << 1, +} RenderEntityFlag; +typedef u32 RenderEntityFlags; + +/** @brief A renderable 'thing' */ typedef struct RenderEnt { - Mesh* mesh; - Material* material; + MeshHandle mesh; + MaterialHandle material; Mat4 affine; // In the future this should be updated by the transform graph - // Bbox_3D bounding_box; - bool casts_shadows; + Bbox_3D bounding_box; + RenderEntityFlags flags; } RenderEnt; #ifndef TYPED_RENDERENT_ARRAY diff --git a/src/new_render/shadows.c b/src/new_render/shadows.c index 6a9fe02..92fce81 100644 --- a/src/new_render/shadows.c +++ b/src/new_render/shadows.c @@ -1,9 +1,9 @@ #include "shadows.h" #include <string.h> -#include "core.h" #include "file.h" #include "glad/glad.h" #include "log.h" +#include "maths.h" #include "maths_types.h" #include "primitives.h" #include "ral_common.h" @@ -197,12 +197,12 @@ void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform for (size_t ent_i = 0; ent_i < entity_count; ent_i++) { RenderEnt renderable = entities[ent_i]; - if (renderable.casts_shadows) { + if (renderable.flags && REND_ENT_CASTS_SHADOWS) { // Model* model = MODEL_GET(renderable.model); uniforms.model = renderable.affine; // update the model transform - Mesh* mesh = renderable.mesh; + Mesh* mesh = Mesh_pool_get(Render_GetMeshPool(), renderable.mesh); GPU_EncodeBindShaderData(&shadow_encoder, 0, shader_data); GPU_EncodeSetVertexBuffer(&shadow_encoder, mesh->vertex_buffer); GPU_EncodeSetIndexBuffer(&shadow_encoder, mesh->index_buffer); diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h index 3b5b55b..c2ef3a2 100644 --- a/src/new_render/skybox.h +++ b/src/new_render/skybox.h @@ -5,7 +5,7 @@ #pragma once #include "camera.h" #include "defines.h" -#include "ral_types.h" +#include "ral_impl.h" #include "render_types.h" typedef struct Skybox { diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index 7929a16..305ab36 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -57,7 +57,8 @@ bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, } // All of these are no-ops in OpenGL -void GPU_Backend_Shutdown() { /* TODO */ } +void GPU_Backend_Shutdown() { /* TODO */ +} bool GPU_Device_Create(GPU_Device* out_device) { return true; } void GPU_Device_Destroy(GPU_Device* device) {} bool GPU_Swapchain_Create(GPU_Swapchain* out_swapchain) { return true; } diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h index b27d782..3e40945 100644 --- a/src/ral/backends/opengl/backend_opengl.h +++ b/src/ral/backends/opengl/backend_opengl.h @@ -53,7 +53,7 @@ typedef struct GPU_Buffer { } id; union { u32 vao; - u32 ubo_binding_point + u32 ubo_binding_point; }; // Optional char *name; u64 size; diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h index fa93cd5..c950fe2 100644 --- a/src/ral/ral_types.h +++ b/src/ral/ral_types.h @@ -21,7 +21,7 @@ CORE_DEFINE_HANDLE(ShaderHandle); CORE_DEFINE_HANDLE(PipelineLayoutHandle); CORE_DEFINE_HANDLE(PipelineHandle); CORE_DEFINE_HANDLE(RenderpassHandle); -#define INVALID_TEX_HANDLE ((TextureHandle){ .raw = 9999999 }) +#define INVALID_TEX_HANDLE ((TextureHandle){ .raw = 9999981 }) // --- Buffers typedef enum GPU_BufferType { diff --git a/src/resources/gltf.c b/src/resources/gltf.c index c575fb9..ef7569f 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -320,15 +320,16 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 rel i32 mat_idx = -1; if (primitive.material != NULL) { DEBUG("Primitive Material %s", primitive.material->name); - for (u32 i = 0; i < Material_darray_len(out_model->materials); i++) { - printf("%s vs %s \n", primitive.material->name, out_model->materials->data[i].name); - if (strcmp(primitive.material->name, out_model->materials->data[i].name) == 0) { - INFO("Found material"); - mat_idx = i; - // mesh.material_index = i; - break; - } - } + // FIXME! + // for (u32 i = 0; i < Material_darray_len(out_model->materials); i++) { + // printf("%s vs %s \n", primitive.material->name, out_model->materials->data[i].name); + // if (strcmp(primitive.material->name, out_model->materials->data[i].name) == 0) { + // INFO("Found material"); + // mat_idx = i; + // // mesh.material_index = i; + // break; + // } + // } } TRACE("Vertex data has been loaded"); @@ -417,7 +418,7 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 rel // m.material_index = (u32_opt){ .has_value = mat_idx == 9999, .value = mat_idx }; Mesh m = Mesh_Create(geometry, false); - m.material_index = mat_idx; + // m.material_index = mat_idx; FIXME Mesh_darray_push(out_model->meshes, m); } diff --git a/src/std/mem.c b/src/std/mem.c index 4a4454a..a537330 100644 --- a/src/std/mem.c +++ b/src/std/mem.c @@ -126,3 +126,10 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle) { pool->count--; } + +u32 void_pool_insert(void_pool* pool, void* item) { + u32 raw_handle; + void* item_dest = void_pool_alloc(pool, &raw_handle); + memcpy(item_dest, item, pool->entry_size); + return raw_handle; +}
\ No newline at end of file diff --git a/src/std/mem.h b/src/std/mem.h index c9346cc..56c1230 100644 --- a/src/std/mem.h +++ b/src/std/mem.h @@ -66,6 +66,7 @@ bool void_pool_is_full(void_pool* pool); void* void_pool_get(void_pool* pool, u32 raw_handle); void* void_pool_alloc(void_pool* pool, u32* out_raw_handle); void void_pool_dealloc(void_pool* pool, u32 raw_handle); +u32 void_pool_insert(void_pool* pool, void* item); // TODO: fn to dealloc from the pointer that was handed out // TODO: macro that lets us specialise @@ -88,4 +89,8 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle); } \ static inline void Name##_pool_dealloc(Name##_pool* pool, Name##Handle handle) { \ void_pool_dealloc(&pool->inner, handle.raw); \ - }\ + } \ + static Name##Handle Name##_pool_insert(Name##_pool* pool, T* item) { \ + u32 raw_handle = void_pool_insert(pool, item); \ + return (Name##Handle){ .raw = raw_handle }; \ + } |