This commit is contained in:
2026-06-17 11:07:13 -05:00
parent 0ea6dd9219
commit f5db2458cd
14 changed files with 726 additions and 12 deletions
+49 -4
View File
@@ -7,14 +7,18 @@
#pragma once
#include "entitybase.h"
#include "error/error.h"
#define X(enumName, type, field, init, dispose, render) \
#include <yyjson.h>
#define X(enumName, type, field, init, dispose, render, serialize, deserialize) \
// do nothing
#include "componentlist.h"
#undef X
typedef union {
#define X(enumName, type, field, init, dispose, render) type field;
#define X(enumName, type, field, init, dispose, render, serialize, deserialize) \
type field;
#include "componentlist.h"
#undef X
} componentdata_t;
@@ -25,12 +29,23 @@ typedef struct {
void (*init)(const entityid_t, const componentid_t);
void (*dispose)(const entityid_t, const componentid_t);
errorret_t (*render)(const entityid_t, const componentid_t);
void (*serialize)(
const entityid_t,
const componentid_t,
yyjson_mut_doc *,
yyjson_mut_val *
);
errorret_t (*deserialize)(
const entityid_t,
const componentid_t,
yyjson_val *
);
} componentdefinition_t;
typedef enum {
COMPONENT_TYPE_NULL,
#define X(enumName, type, field, init, dispose, render) \
#define X(enumName, type, field, init, dispose, render, serialize, deserialize) \
COMPONENT_TYPE_##enumName,
#include "componentlist.h"
#undef X
@@ -117,4 +132,34 @@ void componentDispose(
*
* @return Error state.
*/
errorret_t componentRenderAll(void);
errorret_t componentRenderAll(void);
/**
* Serializes a component's configurable state into a JSON object. The caller
* is responsible for creating and owning the doc and obj.
*
* @param entityId The entity ID.
* @param componentId The component ID.
* @param doc The mutable JSON document to allocate values from.
* @param obj The JSON object to write fields into.
*/
void componentSerialize(
const entityid_t entityId,
const componentid_t componentId,
yyjson_mut_doc *doc,
yyjson_mut_val *obj
);
/**
* Deserializes a component's configurable state from a JSON object.
*
* @param entityId The entity ID.
* @param componentId The component ID.
* @param obj The JSON object to read fields from.
* @return Error state.
*/
errorret_t componentDeserialize(
const entityid_t entityId,
const componentid_t componentId,
yyjson_val *obj
);