prosperon/source/engine/ffi.c

110 lines
2.1 KiB
C
Raw Normal View History

2023-01-10 07:13:00 -06:00
#include "ffi.h"
#include "script.h"
cpVect duk2vec2(duk_context *duk, int p) {
cpVect pos;
duk_get_prop_index(duk, p, 0);
duk_get_prop_index(duk, p, 1);
pos.x = duk_to_number(duk, -2);
pos.y = duk_to_number(duk, -1);
return pos;
}
duk_ret_t duk_gui_text(duk_context *duk) {
const char *s = duk_to_string(duk, 0);
cpVect pos = duk2vec2(duk, 1);
duk_get_prop_index(duk, 1, 0);
float fpos[2] = {pos.x, pos.y};
float size = duk_to_number(duk, 2);
renderText(s, fpos, size, white, 1800);
return 0;
}
duk_ret_t duk_win_make(duk_context *duk) {
const char *title = duk_to_string(duk, 0);
int w = duk_to_int(duk, 1);
int h = duk_to_int(duk, 2);
struct window *win = MakeSDLWindow(title, w, h, 0);
duk_push_int(duk, win->id);
return 1;
}
duk_ret_t duk_sys_cmd(duk_context *duk) {
int cmd = duk_to_int(duk, 0);
switch (cmd) {
case 0:
quit();
break;
case 1:
sim_start();
break;
case 2:
sim_stop();
break;
case 3:
sim_pause();
break;
case 4:
sim_step();
break;
case 5:
duk_push_boolean(duk, sim_playing());
return 1;
case 6:
duk_push_boolean(duk, sim_paused());
return 1;
case 7:
duk_push_int(duk, MakeGameobject());
return 1;
case 8:
duk_push_int(duk, frame_fps());
return 1;
case 9: /* Clear the level out */
new_level();
break;
}
return 0;
}
duk_ret_t duk_
duk_ret_t duk_make_gameobject(duk_context *duk) {
int g = MakeGameobject();
struct gameobject *go = get_gameobject_from_id(g);
go->scale = duk_to_number(duk, 0);
go->bodytype = duk_to_int(duk, 1);
go->mass = duk_to_number(duk, 2);
go->f = duk_to_number(duk, 3);
go->e = duk_to_number(duk, 4);
go->flipx = duk_to_boolean(5);
go->flipy = duk_to_boolean(6);
gameobject_apply(go);
duk_push_int(g);
return 1;
}
void ffi_load()
{
}