ECS rendering

This commit is contained in:
2025-08-22 16:15:42 -05:00
parent 94ad64675d
commit f9385ed233
17 changed files with 161 additions and 215 deletions

View File

@@ -8,4 +8,5 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE
mesh.c
quad.c
meshrenderer.c
)

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "meshrenderer.h"
meshrenderer_t MESH_RENDERER_DATA[ECS_ENTITY_COUNT_MAX] = { 0 };
ecscomponent_t MESH_RENDERER_COMPONENT = ecsComponentInit(
MESH_RENDERER_DATA,
((ecscomponentcallbacks_t){
.init = NULL,
.entityAdd = NULL,
.entityRemove = NULL
})
);
void meshRendererDraw(const ecsid_t id) {
if(!meshRendererHas(id)) return;
meshrenderer_t *renderer = &MESH_RENDERER_DATA[id];
if(!renderer->mesh) return;
meshDraw(renderer->mesh, 0, -1);
}

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "ecs/ecscomponent.h"
#include "display/mesh/mesh.h"
typedef struct {
mesh_t *mesh;
} meshrenderer_t;
extern meshrenderer_t MESH_RENDERER_DATA[ECS_ENTITY_COUNT_MAX];
extern ecscomponent_t MESH_RENDERER_COMPONENT;
#define meshRendererAdd(id) \
((meshrenderer_t*)ecsComponentDataAdd(&MESH_RENDERER_COMPONENT, id))
#define meshRendererGet(id) \
((meshrenderer_t*)ecsComponentDataGet(&MESH_RENDERER_COMPONENT, id))
#define meshRendererHas(id) \
(ecsComponentDataHas(&MESH_RENDERER_COMPONENT, id))
#define meshRendererRemove(id) \
ecsComponentDataRemove(&MESH_RENDERER_COMPONENT, id)
#define meshRendererGetAll(out) \
ecsComponentGetAll(&MESH_RENDERER_COMPONENT, out)
/**
* Draw the mesh for the given entity.
*
* @param id The ID of the entity with the mesh renderer component.
*/
void meshRendererDraw(const ecsid_t id);