diff --git a/source/engine/engine.c b/source/engine/engine.c index 6aa1371..4e61a44 100644 --- a/source/engine/engine.c +++ b/source/engine/engine.c @@ -64,5 +64,5 @@ void engine_init() phys2d_init(); YughInfo("Starting sound ..."); -// sound_init(); + sound_init(); } diff --git a/source/engine/ffi.c b/source/engine/ffi.c index d0d8dce..5814ec5 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -110,7 +110,12 @@ duk_ret_t duk_cmd(duk_context *duk) { break; case 12: - anim2d_delete(duk_to_int(duk, 1)); + //anim2d_delete(duk_to_int(duk, 1)); + break; + + + case 13: + play_song(duk_to_string(duk, 1), duk_to_string(duk, 2)); break; } @@ -149,7 +154,6 @@ duk_ret_t duk_register_collide(duk_context *duk) { int go = duk_get_int(duk, 3); struct callee c = {fn, obj}; - YughInfo("Registering ..."); phys2d_add_handler_type(0, go, c); @@ -223,10 +227,13 @@ duk_ret_t duk_make_gameobject(duk_context *duk) { return 1; } -duk_ret_t duk_loginfo(duk_context *duk) { - const char *s = duk_to_string(duk,0); +duk_ret_t duk_yughlog(duk_context *duk) { + int cmd = duk_to_int(duk, 0); + const char *s = duk_to_string(duk,1); + const char *f = duk_to_string(duk, 2); + int line = duk_to_int(duk, 3); - YughInfo("%s", s); + mYughLog(1, cmd, line, f, s); return 0; } @@ -342,7 +349,7 @@ duk_ret_t duk_make_anim2d(duk_context *duk) { const char *path = duk_to_string(duk, 1); cpVect pos = duk2vec2(duk, 2); - + return 0; } duk_ret_t duk_make_box2d(duk_context *duk) { @@ -421,13 +428,11 @@ duk_ret_t duk_timer_cmd(duk_context *duk) { void ffi_load() { - DUK_FUNC(loginfo, 1); + DUK_FUNC(yughlog, 4); DUK_FUNC(make_gameobject, 7); DUK_FUNC(set_body, 3); DUK_FUNC(q_body, 2); - DUK_FUNC(sprite, 3); - DUK_FUNC(sys_cmd, 1); DUK_FUNC(win_make, 3); @@ -435,7 +440,7 @@ void ffi_load() DUK_FUNC(make_anim2d, 3); DUK_FUNC(make_box2d, 3); DUK_FUNC(make_circle2d, 3); - DUK_FUNC(cmd, 2); + DUK_FUNC(cmd, DUK_VARARGS); DUK_FUNC(register, 3); DUK_FUNC(register_collide, 4); diff --git a/source/engine/script.c b/source/engine/script.c index c4c9cf8..937cdb7 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -57,6 +57,15 @@ time_t file_mod_secs(const char *file) { return attr.st_mtime; } +void duk_run_err() { + duk_get_prop_string(duk, -1, "lineNumber"); + duk_get_prop_string(duk, -2, "fileName"); + duk_get_prop_string(duk, -3, "stack"); + mYughLog(1, 2, duk_get_int(duk, -3), duk_safe_to_string(duk, -2), "%s\n%s", duk_safe_to_string(duk, -4), duk_safe_to_string(duk, -1)); + + duk_pop_3(duk); +} + int script_dofile(const char *file) { const char *script = slurp_text(file); if (!script) { @@ -65,14 +74,18 @@ int script_dofile(const char *file) { } duk_push_string(duk, script); free(script); - if (duk_peval(duk) != 0) { - printf("ERROR: %s\n", duk_safe_to_string(duk, -1)); + duk_push_string(duk, file); + + if (duk_pcompile(duk, 0) != 0) { + duk_run_err(); return 1; } + + if (duk_pcall(duk, 0)) + duk_run_err(); + duk_pop(duk); - - return file_mod_secs(file); } @@ -105,15 +118,18 @@ void script_eval_w_env(const char *s, void *env) { return; } duk_push_string(duk, s); - duk_call_prop(duk, -2, 0); - duk_pop(duk); - duk_pop(duk); + if (duk_pcall_prop(duk, -2, 0)) + duk_run_err(); + + duk_pop_2(duk); } void script_call_sym(void *sym) { duk_push_heapptr(duk, sym); - duk_call(duk, 0); + if (duk_pcall(duk, 0)) + duk_run_err(); + duk_pop(duk); } @@ -143,7 +159,10 @@ void register_physics(struct callee c) { void call_callee(struct callee c) { duk_push_heapptr(duk, c.fn); duk_push_heapptr(duk, c.obj); - duk_call_method(duk, 0); + + if (duk_pcall_method(duk, 0)) + duk_run_err(); + duk_pop(duk); } @@ -151,7 +170,10 @@ void callee_dbl(struct callee c, double d) { duk_push_heapptr(duk, c.fn); duk_push_heapptr(duk, c.obj); duk_push_number(duk, d); - duk_call_method(duk, 1); + + if (duk_pcall_method(duk, 1)) + duk_run_err(); + duk_pop(duk); } diff --git a/source/engine/sound.h b/source/engine/sound.h index 095d235..50078da 100644 --- a/source/engine/sound.h +++ b/source/engine/sound.h @@ -73,13 +73,8 @@ void sound_pause(struct sound *s); void sound_resume(struct sound *s); void sound_stop(struct sound *s); - - struct music make_music(const char *ogg); - - - const char *get_audio_driver(); void soundstream_fillbuf(struct soundstream *stream, short *buf, int n); diff --git a/source/engine/texture.c b/source/engine/texture.c index d73e552..6d7d8e0 100644 --- a/source/engine/texture.c +++ b/source/engine/texture.c @@ -7,6 +7,7 @@ #include "log.h" #include #include "util.h" +#include "parson.h" static struct { char *key; @@ -22,7 +23,14 @@ struct Texture *texture_pullfromfile(const char *path) return texhash[index].value; struct Texture *tex = calloc(1, sizeof(*tex)); - tex->opts.sprite = 1; + + /* Find texture's asset; otherwise load default asset */ + JSON_Value *rv = json_parse_file("texture.asset"); + JSON_Object *ro = json_value_get_object(rv); + tex->opts.sprite = json_object_get_boolean(ro, "sprite"); + tex->opts.mips = json_object_get_boolean(ro, "mips"); + json_value_free(rv); + tex->opts.gamma = 0; tex->anim.ms = 1; @@ -61,7 +69,8 @@ struct Texture *texture_pullfromfile(const char *path) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - glGenerateMipmap(GL_TEXTURE_2D); + if (tex->opts.mips) + glGenerateMipmap(GL_TEXTURE_2D); if (tex->opts.sprite) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); diff --git a/source/engine/texture.h b/source/engine/texture.h index 45a874b..a0a45f1 100644 --- a/source/engine/texture.h +++ b/source/engine/texture.h @@ -48,6 +48,7 @@ struct TexAnim { struct TextureOptions { int sprite; + int mips; unsigned int gamma:1; int animation; };