Vastly simplified entity stringifying and diffing

This commit is contained in:
2023-09-14 22:37:04 +00:00
parent 772c12af0e
commit e392f65485
8 changed files with 153 additions and 207 deletions

View File

@@ -979,10 +979,10 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
return num2js(js2go(argv[1])->scale);
case 104:
return bool2js(js2go(argv[1])->flipx);
return bool2js(js2go(argv[1])->flipx == -1 ? 1 : 0);
case 105:
return bool2js(js2go(argv[1])->flipy);
return bool2js(js2go(argv[1])->flipy == -1 ? 1 : 0);
case 106:
js2go(argv[1])->e = js2number(argv[2]);

View File

@@ -107,7 +107,7 @@ void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go) {
moment += s->moi(s->data, go->mass);
if (moment < 0) moment = 1;
cpBodySetMoment(go->body, moment);
cpBodySetMoment(go->body, 1);
}
void gameobject_apply(struct gameobject *go) {

View File

@@ -57,22 +57,23 @@ int make_sprite(int go) {
.layer = 0,
.enabled = 1};
int slot = 0;
if (first < 0) {
arrput(sprites, sprite);
arrlast(sprites).id = arrlen(sprites) - 1;
return arrlen(sprites) - 1;
slot = arrlen(sprites)-1;
} else {
int slot = first;
slot = first;
first = id2sprite(first)->next;
*id2sprite(slot) = sprite;
return slot;
}
return slot;
}
void sprite_delete(int id) {
struct sprite *sp = id2sprite(id);
sp->go = -1;
sp->enabled = 0;
sp->next = first;
first = id;
}
@@ -121,6 +122,7 @@ void sprite_draw_all() {
for (int i = 0; i < arrlen(sprites); i++)
if (sprites[i].go >= 0 && sprites[i].enabled) arrpush(layers[sprites[i].layer], &sprites[i]);
for (int i = 4; i >= 0; i--)
for (int j = 0; j < arrlen(layers[i]); j++)
@@ -137,8 +139,6 @@ void sprite_settex(struct sprite *sprite, struct Texture *tex) {
sprite_setframe(sprite, &ST_UNIT);
}
void sprite_initialize() {
shader_sprite = sg_compile_shader("shaders/spritevert.glsl", "shaders/spritefrag.glsl", &(sg_shader_desc){
.vs.uniform_blocks[0] = {

View File

@@ -7,22 +7,20 @@
#include "HandmadeMath.h"
#include "render.h"
struct datastream;
struct gameobject;
struct sprite {
HMM_Vec2 pos;
HMM_Vec2 size;
float rotation;
struct rgba color;
int go;
int id;
struct Texture *tex;
struct glrect frame;
int next;
int enabled;
int layer;
HMM_Vec2 pos;
HMM_Vec2 size;
float rotation;
struct rgba color;
int go; /* id of gameobject */
struct Texture *tex;
struct glrect frame;
int enabled;
int layer;
int next;
};
int make_sprite(int go);