??
This commit is contained in:
parent
02d4396010
commit
c56e2841b6
|
@ -64,7 +64,6 @@ void engine_init()
|
|||
|
||||
//stbi_set_flip_vertically_on_load(1);
|
||||
phys2d_init();
|
||||
gui_init();
|
||||
sound_init();
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,10 @@ void gameobject_save(struct mGameObject *go, FILE * file)
|
|||
{
|
||||
fwrite(go, sizeof(*go), 1, file);
|
||||
|
||||
fwrite(arrlen(go->components), sizeof(int), 1, file);
|
||||
printf("Number of components is %d.\n", arrlen(go->components));
|
||||
|
||||
int n = arrlen(go->components);
|
||||
fwrite(&n, sizeof(n), 1, file);
|
||||
for (int i = 0; i < arrlen(go->components); i++) {
|
||||
fwrite(go->components[i].id, sizeof(int), 1, file);
|
||||
fwrite(go->components[i].data, go->components[i].datasize, 1, file);
|
||||
|
@ -131,8 +134,8 @@ void gameobject_init(struct mGameObject *go, FILE * fprefab)
|
|||
|
||||
for (int i = 0; i < comp_n; i++) {
|
||||
fread(&n, sizeof(int), 1, fprefab);
|
||||
arrput(go->components, components[n]);
|
||||
struct component *newc = &arrlast(go->components);
|
||||
go->components[i] = components[n];
|
||||
struct component *newc = &go->components[i];
|
||||
newc->go = go;
|
||||
newc->data = malloc(newc->datasize);
|
||||
fread(newc->data, newc->datasize, 1, fprefab);
|
||||
|
|
|
@ -24,8 +24,6 @@ void save_level(char name[MAXNAME])
|
|||
|
||||
void load_level(char name[MAXNAME])
|
||||
{
|
||||
|
||||
|
||||
FILE *lfile = fopen(name, "rb");
|
||||
|
||||
if (!lfile) return;
|
||||
|
|
|
@ -192,10 +192,6 @@ mrb_value mrb_settings_cmd(mrb_state *mrb, mrb_value self) {
|
|||
return self;
|
||||
}
|
||||
|
||||
mrb_value mrb_sprite_make(mrb_state *mrb, mrb_value self) {
|
||||
struct mSprite *new = gui_makesprite();
|
||||
}
|
||||
|
||||
mrb_value mrb_editor_render(mrb_state *mrb, mrb_value self) {
|
||||
editor_render();
|
||||
return self;
|
||||
|
@ -216,8 +212,6 @@ void ffi_load() {
|
|||
|
||||
MRB_FUNC(ui_rendertext, MRB_ARGS_REQ(5));
|
||||
|
||||
MRB_FUNC(sprite_make, MRB_ARGS_REQ(1));
|
||||
|
||||
MRB_FUNC(c_reload, MRB_ARGS_REQ(1));
|
||||
|
||||
MRB_FUNC(win_make, MRB_ARGS_REQ(1));
|
||||
|
|
|
@ -21,12 +21,12 @@ void registry_init()
|
|||
REGISTER_COMP(2d_edge);
|
||||
*/
|
||||
|
||||
register_component("Sprite", sizeof(struct mSprite), MakeSprite, NULL, sprite_gui, sprite_init);
|
||||
register_component("2D Circle Collider", sizeof(struct phys2d_circle), Make2DCircle, phys2d_dbgdrawcircle, circle_gui, phys2d_circleinit);
|
||||
register_component("2D Segment", sizeof(struct phys2d_segment), Make2DSegment, phys2d_dbgdrawseg, segment_gui, phys2d_seginit);
|
||||
register_component("2D Box", sizeof(struct phys2d_box), Make2DBox, phys2d_dbgdrawbox, box_gui, phys2d_boxinit);
|
||||
register_component("2D Polygon", sizeof(struct phys2d_poly), Make2DPoly, phys2d_dbgdrawpoly, poly_gui,phys2d_polyinit);
|
||||
register_component("2D Edge", sizeof(struct phys2d_edge), Make2DEdge, phys2d_dbgdrawedge, edge_gui, phys2d_edgeinit);
|
||||
register_component("Sprite", sizeof(struct mSprite), MakeSprite, sprite_delete, NULL, sprite_gui, sprite_init);
|
||||
register_component("2D Circle Collider", sizeof(struct phys2d_circle), Make2DCircle, NULL, phys2d_dbgdrawcircle, circle_gui, phys2d_circleinit);
|
||||
register_component("2D Segment", sizeof(struct phys2d_segment), NULL, Make2DSegment, phys2d_dbgdrawseg, segment_gui, phys2d_seginit);
|
||||
register_component("2D Box", sizeof(struct phys2d_box), Make2DBox, NULL, phys2d_dbgdrawbox, box_gui, phys2d_boxinit);
|
||||
register_component("2D Polygon", sizeof(struct phys2d_poly), Make2DPoly, NULL, phys2d_dbgdrawpoly, poly_gui,phys2d_polyinit);
|
||||
register_component("2D Edge", sizeof(struct phys2d_edge), Make2DEdge, NULL, phys2d_dbgdrawedge, edge_gui, phys2d_edgeinit);
|
||||
}
|
||||
|
||||
void register_component(const char *name, size_t size,
|
||||
|
|
|
@ -13,6 +13,7 @@ struct component {
|
|||
struct mGameObject *go;
|
||||
void (*draw_debug)(void *data);
|
||||
void (*draw_gui)(void *data);
|
||||
void (*delete)(void *data);
|
||||
int id;
|
||||
int datasize;
|
||||
void (*init)(void *data, struct mGameObject * go);
|
||||
|
@ -29,6 +30,7 @@ void comp_update(struct component *c, struct mGameObject *go);
|
|||
void registry_init();
|
||||
void register_component(const char *name, size_t size,
|
||||
void (*make)(struct mGameObject * go, struct component * c),
|
||||
void (*delete)(void *data),
|
||||
void(*draw_debug)(void *data),
|
||||
void(*draw_gui)(void *data),
|
||||
void(*init)(void *data, struct mGameObject * go));
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
#include <string.h>
|
||||
#include "stb_ds.h"
|
||||
|
||||
|
||||
static struct mGameObject *gui_go = NULL;
|
||||
|
||||
struct TextureOptions TEX_SPRITE = { 1, 0, 0 };
|
||||
|
||||
struct mSprite *sprites;
|
||||
|
@ -22,6 +19,9 @@ static uint32_t quadVAO;
|
|||
|
||||
struct mSprite *MakeSprite(struct mGameObject *go)
|
||||
{
|
||||
if (arrcap(sprites) == 0)
|
||||
arrsetcap(sprites, 100);
|
||||
|
||||
struct mSprite sprite = {
|
||||
.color = {1.f, 1.f, 1.f},
|
||||
.size = {1.f, 1.f},
|
||||
|
@ -31,17 +31,20 @@ struct mSprite *MakeSprite(struct mGameObject *go)
|
|||
sprite_init(&sprite, go);
|
||||
arrput(sprites, sprite);
|
||||
return &arrlast(sprites);
|
||||
sprite->go = go;
|
||||
}
|
||||
|
||||
void sprite_init(struct mSprite *sprite, struct mGameObject *go)
|
||||
void sprite_delete(struct mSprite *sprite)
|
||||
.3+
|
||||
{
|
||||
sprite->go = go;
|
||||
|
||||
}
|
||||
|
||||
void sprite_draw_all()
|
||||
{
|
||||
//shader_use(spriteShader);
|
||||
arrwalk(sprites, sprite_draw);
|
||||
for (int i = 0; i < arrlen(sprites); i++)
|
||||
sprite_draw(&sprites[i]);
|
||||
}
|
||||
|
||||
void sprite_loadtex(struct mSprite *sprite, const char *path)
|
||||
|
@ -199,14 +202,3 @@ void video_draw(struct datastream *stream, mfloat_t position[2], mfloat_t size[2
|
|||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
void gui_init()
|
||||
{
|
||||
gui_go = MakeGameobject();
|
||||
}
|
||||
|
||||
struct mSprite *gui_makesprite()
|
||||
{
|
||||
struct mSprite *new = MakeSprite(gui_go);
|
||||
return new;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ struct mSprite {
|
|||
};
|
||||
|
||||
struct mSprite *MakeSprite(struct mGameObject *go);
|
||||
void sprite_delete(struct mSprite *sprite);
|
||||
void sprite_init(struct mSprite *sprite, struct mGameObject *go);
|
||||
void sprite_loadtex(struct mSprite *sprite, const char *path);
|
||||
void sprite_loadanim(struct mSprite *sprite, const char *path, struct Anim2D anim);
|
||||
|
@ -42,11 +43,5 @@ void video_draw(struct datastream *ds, mfloat_t pos[2], mfloat_t size[2], float
|
|||
void sprite_draw_all();
|
||||
unsigned int incrementAnimFrame(unsigned int interval, struct mSprite *sprite);
|
||||
|
||||
struct mSprite *gui_makesprite();
|
||||
void gui_init();
|
||||
|
||||
void sprite_draw_all();
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,6 @@ struct Texture *texture_pullfromfile(const char *path)
|
|||
if (index != -1)
|
||||
return texhash[index].value;
|
||||
|
||||
|
||||
struct Texture *tex = calloc(1, sizeof(*tex));
|
||||
tex->flipy = 0;
|
||||
tex->opts.sprite = 1;
|
||||
|
|
Loading…
Reference in a new issue