diff --git a/source/engine/config.h b/source/engine/config.h index cda361b..6fef7cf 100644 --- a/source/engine/config.h +++ b/source/engine/config.h @@ -17,7 +17,7 @@ #define INITIAL_HEAP_SIZE 4096 #define INITIAL_STACK_SIZE 4096 #define DEFAULT_BIGNUM_PRECISION 128 -#define WITH_PURE_S7 1 +#define WITH_PURE_S7 0 #define WITH_SYSTEM_EXTRAS 0 #define WITH_C_LOADER 0 #define WITH_NUMBER_SEPARATOR 1 diff --git a/source/engine/engine.c b/source/engine/engine.c index 81f6686..5270b90 100644 --- a/source/engine/engine.c +++ b/source/engine/engine.c @@ -66,5 +66,5 @@ void engine_init() phys2d_init(); YughInfo("Starting sound ..."); - //sound_init(); + sound_init(); } diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 2451702..05bde0e 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -54,9 +54,8 @@ static void gameobject_setpickcolor(struct gameobject *go) int MakeGameobject() { - if (gameobjects == NULL) arrsetcap(gameobjects, 100); + if (gameobjects == NULL) arrsetcap(gameobjects, 5000); - YughInfo("Making new gameobject"); struct gameobject go = { .editor.id = arrlen(gameobjects), .scale = 1.f, diff --git a/source/engine/gameobject.h b/source/engine/gameobject.h index ef0e02f..75c5e76 100644 --- a/source/engine/gameobject.h +++ b/source/engine/gameobject.h @@ -34,6 +34,8 @@ struct gameobject { float mass; float f; /* friction */ float e; /* elasticity */ + int flipx; /* 1 or -1 */ + int flipy; cpBody *body; struct component *components; struct phys_cbs *cbs; diff --git a/source/engine/mrbffi.c b/source/engine/mrbffi.c index 08402bd..6164482 100644 --- a/source/engine/mrbffi.c +++ b/source/engine/mrbffi.c @@ -344,6 +344,14 @@ s7_pointer s7_set_body(s7_scheme *sc, s7_pointer args) { case 4: cpBodyApplyImpulseAtWorldPoint(go->body, s7tovec2(sc, s7_caddr(args)), cpBodyGetPosition(go->body)); break; + + case 5: + go->flipx = s7_boolean(sc, s7_caddr(args)) ? -1 : 1; + break; + + case 6: + go->flipy = s7_boolean(sc, s7_caddr(args)) ? -1 : 1; + break; } return args; @@ -499,8 +507,8 @@ s7_pointer s7_make_gameobject(s7_scheme *sc, s7_pointer args) { go->mass = s7_real(s7_caddr(args)); go->f = s7_real(s7_cadddr(args)); go->e = s7_real(s7_list_ref(sc, args, 4)); - - YughInfo("static %d, dynamic %d, kinematic %d", CP_BODY_TYPE_STATIC, CP_BODY_TYPE_DYNAMIC, CP_BODY_TYPE_KINEMATIC); + go->flipx = s7_boolean(sc, s7_list_ref(sc, args, 5)) ? -1 : 1; + go->flipy = s7_boolean(sc, s7_list_ref(sc, args, 6)) ? -1 : 1; gameobject_apply(go); @@ -512,8 +520,6 @@ s7_pointer s7_make_sprite(s7_scheme *sc, s7_pointer args) { const char *path = s7_string(s7_cadr(args)); cpVect pos = s7tovec2(sc, s7_caddr(args)); - YughInfo("Using gameid %d.", go); - struct sprite *sp = make_sprite(get_gameobject_from_id(go)); sprite_loadtex(sp, path); @@ -595,7 +601,7 @@ void ffi_load() { S7_FUNC(anim, 2); S7_FUNC(anim_cmd, 3); - S7_FUNC(make_gameobject, 5); + S7_FUNC(make_gameobject, 7); S7_FUNC(make_sprite, 3); S7_FUNC(make_box2d, 3); S7_FUNC(make_circ2d, 3); diff --git a/source/engine/openglrender.c b/source/engine/openglrender.c index fc9fb09..effebd0 100644 --- a/source/engine/openglrender.c +++ b/source/engine/openglrender.c @@ -92,7 +92,7 @@ void openglInit() glClearColor(editorClearColor[0], editorClearColor[1], editorClearColor[2], editorClearColor[3]); - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_BLEND); diff --git a/source/engine/script.c b/source/engine/script.c index d87c837..142b717 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -5,6 +5,8 @@ #include "mrbffi.h" +#include "ftw.h" + #include "stb_ds.h" s7_scheme *s7 = NULL; @@ -52,11 +54,26 @@ static void my_print(s7_scheme *sc, uint8_t c, s7_pointer port) { } } +static int load_prefab(const char *fpath, const struct stat *sb, int typeflag) { + if (typeflag != FTW_F) + return 0; + + if (!strcmp(".prefab", strrchr(fpath, '.'))) + s7_load(s7, fpath); + + return 0; +} + void script_init() { s7 = s7_init(); s7_set_current_error_port(s7, s7_open_output_function(s7, my_err)); s7_set_current_output_port(s7, s7_open_output_function(s7, my_print)); ffi_load(); + + /* Load all prefabs into memory */ + script_dofile("scripts/engine.scm"); + script_dofile("config.scm"); + ftw(".", load_prefab, 10); } void script_run(const char *script) { diff --git a/source/engine/sprite.c b/source/engine/sprite.c index 7270967..f4574cb 100644 --- a/source/engine/sprite.c +++ b/source/engine/sprite.c @@ -36,8 +36,6 @@ struct sprite *make_sprite(struct gameobject *go) void sprite_init(struct sprite *sprite, struct gameobject *go) { sprite->go = go; - - YughInfo("Added sprite address %p to sprite array %p.", sprite, &arrlast(sprites)); } void sprite_io(struct sprite *sprite, FILE *f, int read) @@ -120,7 +118,7 @@ void tex_draw(struct Texture *tex, float pos[2], float angle, float size[2], flo memcpy(r_model, UNITMAT4, sizeof(UNITMAT4)); memcpy(s_model, UNITMAT4, sizeof(UNITMAT4)); - mfloat_t t_scale[2] = { size[0] * tex->width, size[1] * tex->height }; + mfloat_t t_scale[2] = { tex->width, tex->height }; mfloat_t t_offset[2] = { offset[0] * t_scale[0], offset[1] * t_scale[1] }; mat4_translate_vec2(model, t_offset); @@ -142,9 +140,9 @@ void tex_draw(struct Texture *tex, float pos[2], float angle, float size[2], flo float vertices[] = { 0.f, 0.f, r.s0, r.t1, - 1.f, 0.f, r.s1, r.t1, - 0.f, 1.f, r.s0, r.t0, - 1.f, 1.f, r.s1, r.t0 + size[0], 0.f, r.s1, r.t1, + 0.f, size[1], r.s0, r.t0, + size[0], size[1], r.s1, r.t0 }; glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); @@ -167,7 +165,7 @@ void sprite_draw(struct sprite *sprite) //size[1] = sprite->tex->anim.dimensions[1] * sprite->go->scale; tex_draw(sprite->tex, pos, cpBodyGetAngle(sprite->go->body), size, sprite->pos, anim_get_rect(&sprite->anim)); } else { - float size[2] = { sprite->size[0] * sprite->go->scale, sprite->size[1] * sprite->go->scale }; + float size[2] = { sprite->size[0] * sprite->go->scale * sprite->go->flipx, sprite->size[1] * sprite->go->scale * sprite->go->flipy }; tex_draw(sprite->tex, pos, cpBodyGetAngle(sprite->go->body), size, sprite->pos, tex_get_rect(sprite->tex)); } diff --git a/source/engine/texture.c b/source/engine/texture.c index 68c741f..d73e552 100644 --- a/source/engine/texture.c +++ b/source/engine/texture.c @@ -59,7 +59,7 @@ struct Texture *texture_pullfromfile(const char *path) break; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); diff --git a/source/engine/yugine.c b/source/engine/yugine.c index ef373b5..c33c559 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -157,9 +157,6 @@ int main(int argc, char **args) { renderMS = 1.0/vidmode->refreshRate; - script_dofile("scripts/engine.scm"); - script_dofile("config.scm"); - window_set_icon("icon.png"); if (ed) { diff --git a/source/scripts/engine.scm b/source/scripts/engine.scm index 1b4d196..8ad7ca3 100644 --- a/source/scripts/engine.scm +++ b/source/scripts/engine.scm @@ -109,6 +109,8 @@ (define (body_angle! body angle) (set_body body 0 angle)) (define (body_pos! body pos) (set_body body 2 pos)) (define (body_move! body vec) (set_body body 3 vec)) +(define (body_flipx! body flip) (set_body body 5 flip)) +(define (body_flipy! body flip) (set_body body 6 flip)) (define (gravity! x y) (phys_set 0 x y))