prosperon/source/engine/registry.c

87 lines
2.7 KiB
C
Raw Normal View History

2021-11-30 21:29:18 -06:00
#include "registry.h"
#include "gameobject.h"
#include "2dphysics.h"
2022-08-12 14:03:56 -05:00
#include "editor.h"
2021-11-30 21:29:18 -06:00
#include "sprite.h"
2023-01-03 09:06:36 -06:00
#include "stb_ds.h"
2021-11-30 21:29:18 -06:00
2023-01-03 09:06:36 -06:00
struct component *components;
struct component_interface *interfaces;
2022-08-12 14:03:56 -05:00
2021-11-30 21:29:18 -06:00
void registry_init()
{
2022-08-28 22:34:33 -05:00
register_component("Sprite",
sizeof(struct sprite),
make_sprite,
2022-08-28 22:34:33 -05:00
sprite_delete,
sprite_io,
NULL,
sprite_gui,
sprite_init);
register_component("2D Circle Collider",
sizeof(struct phys2d_circle),
Make2DCircle,
phys2d_circledel,
NULL,
phys2d_dbgdrawcircle,
circle_gui,
phys2d_circleinit);
2023-01-03 09:06:36 -06:00
register_component("2D Segment", sizeof(struct phys2d_segment), Make2DSegment, phys2d_segdel, NULL, phys2d_dbgdrawseg, segment_gui, phys2d_seginit);
2022-08-28 22:34:33 -05:00
register_component("2D Box", sizeof(struct phys2d_box), Make2DBox, phys2d_boxdel, NULL, phys2d_dbgdrawbox, box_gui, phys2d_boxinit);
register_component("2D Polygon", sizeof(struct phys2d_poly), Make2DPoly, phys2d_polydel, NULL, phys2d_dbgdrawpoly, poly_gui,phys2d_polyinit);
register_component("2D Edge", sizeof(struct phys2d_edge), Make2DEdge, phys2d_edgedel, NULL, phys2d_dbgdrawedge, edge_gui, phys2d_edgeinit);
2021-11-30 21:29:18 -06:00
}
void register_component(const char *name, size_t size,
2023-01-03 09:06:36 -06:00
void (*make)(struct gameobject * go),
2022-08-28 22:34:33 -05:00
void (*delete)(void *data),
void (*io)(void *data, FILE *f, int read),
2021-11-30 21:29:18 -06:00
void(*draw_debug)(void *data),
void(*draw_gui)(void *data),
2022-11-19 17:13:57 -06:00
void(*init)(void *data, struct gameobject * go))
2021-11-30 21:29:18 -06:00
{
2023-01-03 09:06:36 -06:00
struct component_interface c;
c.name = name;
c.make = make;
c.io = io;
c.draw_debug = draw_debug;
c.draw_gui = draw_gui;
c.delete = delete;
c.init = init;
arrput(interfaces, c);
}
struct component comp_make(struct component_interface *interface)
{
struct component c;
c.data = interface->make(NULL);
c.ref = interface;
return c;
2021-11-30 21:29:18 -06:00
}
2022-06-21 15:21:00 -05:00
void comp_draw_debug(struct component *c) {
2023-01-03 09:06:36 -06:00
c->ref->draw_debug(c->data);
2022-06-21 15:21:00 -05:00
}
void comp_draw_gui(struct component *c) {
2023-01-03 09:06:36 -06:00
c->ref->draw_gui(c->data);
}
2023-01-02 17:43:07 -06:00
2023-01-03 09:06:36 -06:00
void comp_delete(struct component *c)
{
c->ref->delete(c->data);
}
2023-01-03 17:13:31 -06:00
void comp_init(struct component *c, struct gameobject *go)
2023-01-03 09:06:36 -06:00
{
2023-01-03 17:13:31 -06:00
c->ref->init(c->data, go);
2023-01-03 09:06:36 -06:00
}
2023-01-03 17:13:31 -06:00
void comp_io(struct component *c, FILE *f, int read)
2023-01-03 09:06:36 -06:00
{
2023-01-03 17:13:31 -06:00
c->ref->io(c->data, f, read);
2023-01-02 17:43:07 -06:00
}