2022-08-03 17:00:27 -05:00
|
|
|
#include "mrbffi.h"
|
2022-12-12 10:48:21 -06:00
|
|
|
#include "s7.h"
|
2022-08-05 14:23:39 -05:00
|
|
|
|
|
|
|
#include "font.h"
|
|
|
|
|
2022-08-03 17:00:27 -05:00
|
|
|
#include "script.h"
|
2022-08-05 14:23:39 -05:00
|
|
|
#include "string.h"
|
2022-08-07 01:43:45 -05:00
|
|
|
#include "window.h"
|
2022-08-12 14:03:56 -05:00
|
|
|
#include "editor.h"
|
|
|
|
#include "engine.h"
|
2022-11-18 12:03:07 -06:00
|
|
|
#include "log.h"
|
2022-12-16 11:54:05 -06:00
|
|
|
#include "input.h"
|
2022-08-03 17:00:27 -05:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
#include "s7.h"
|
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
#include "nuke.h"
|
2022-08-03 20:49:56 -05:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
extern s7_scheme *s7;
|
|
|
|
|
2022-08-03 17:00:27 -05:00
|
|
|
/* FFI */
|
2022-12-12 10:48:21 -06:00
|
|
|
s7_pointer s7_ui_label(s7_scheme *sc, s7_pointer args) {
|
|
|
|
if (s7_is_string(s7_car(args))) {
|
|
|
|
nuke_label(s7_string(s7_car(args)));
|
|
|
|
return s7_make_boolean(sc, 1);
|
|
|
|
}
|
2022-08-03 17:00:27 -05:00
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
return s7_wrong_type_arg_error(sc, "ui_label", 1, args, "Should be a string.");
|
2022-08-03 17:00:27 -05:00
|
|
|
}
|
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
s7_pointer s7_ui_btn(s7_scheme *sc, s7_pointer args) {
|
|
|
|
return s7_make_boolean(sc, nuke_btn(s7_string(s7_car(args))));
|
2022-08-03 20:49:56 -05:00
|
|
|
}
|
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
s7_pointer s7_ui_nel(s7_scheme *sc, s7_pointer args) {
|
|
|
|
nuke_nel(s7_integer(s7_cadr(args)));
|
|
|
|
return s7_make_boolean(sc, 1);
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
s7_pointer s7_ui_prop(s7_scheme *sc, s7_pointer args) {
|
|
|
|
float val = s7_real(s7_cadr(args));
|
|
|
|
nuke_prop_float(s7_string(s7_car(args)), (float)s7_real(s7_caddr(args)), &val, s7_real(s7_cadddr(args)), s7_real(s7_car(s7_cddddr(args))), s7_real(s7_car(s7_cdr(s7_cddddr(args)))));
|
|
|
|
return s7_make_real(sc, val);
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
s7_pointer s7_ui_text(s7_scheme *sc, s7_pointer args) {
|
|
|
|
const char *s = s7_string(s7_car(args));
|
|
|
|
int len = s7_integer(s7_cadr(args));
|
|
|
|
char str[len+1];
|
|
|
|
strncpy(str,s,len);
|
|
|
|
nuke_edit_str(str);
|
|
|
|
return s7_make_string(sc, str);
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
s7_pointer s7_settings_cmd(s7_scheme *sc, s7_pointer args) {
|
|
|
|
int cmd = s7_integer(s7_car(args));
|
|
|
|
double val = s7_real(s7_cadr(args));
|
|
|
|
YughInfo("Changing a setting.");
|
|
|
|
switch(cmd) {
|
|
|
|
case 0: // render fps
|
2022-12-16 11:54:05 -06:00
|
|
|
renderMS = val;
|
2022-12-15 17:30:22 -06:00
|
|
|
break;
|
2022-08-05 14:23:39 -05:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
case 1:
|
2022-12-16 11:54:05 -06:00
|
|
|
updateMS = val;
|
2022-12-15 17:30:22 -06:00
|
|
|
break;
|
2022-08-05 14:23:39 -05:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
case 2:
|
2022-12-16 11:54:05 -06:00
|
|
|
physMS = val;
|
2022-12-15 17:30:22 -06:00
|
|
|
break;
|
|
|
|
}
|
2022-08-05 14:23:39 -05:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
return args;
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
s7_pointer s7_log(s7_scheme *sc, s7_pointer args) {
|
|
|
|
int lvl = s7_integer(s7_car(args));
|
|
|
|
const char *msg = s7_string(s7_object_to_string(sc, s7_cadr(args), 0));
|
|
|
|
const char *file = s7_string(s7_caddr(args));
|
|
|
|
int line = s7_integer(s7_cadddr(args));
|
|
|
|
mYughLog(1, lvl, line, file, msg);
|
|
|
|
//YughInfo(s7_string(s7_object_to_string(sc, s7_car(args), 0)));
|
2022-12-12 10:48:21 -06:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
return args;
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
/* Call like (ui_rendertext "string" (xpos ypos) size) */
|
|
|
|
s7_pointer s7_ui_rendertext(s7_scheme *sc, s7_pointer args) {
|
|
|
|
const char *s = s7_string(s7_car(args));
|
|
|
|
double pos[2];
|
|
|
|
pos[0] = s7_real(s7_car(s7_cadr(args)));
|
|
|
|
pos[1] = s7_real(s7_cadr(s7_cadr(args)));
|
|
|
|
double size = s7_real(s7_caddr(args));
|
|
|
|
double white[3] = {1.f, 1.f, 1.f};
|
|
|
|
|
|
|
|
renderText(s, pos, size, white, 0);
|
|
|
|
|
|
|
|
return args;
|
2022-08-07 01:43:45 -05:00
|
|
|
}
|
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
s7_pointer s7_win_cmd(s7_scheme *sc, s7_pointer args) {
|
|
|
|
int win = s7_integer(s7_car(args));
|
|
|
|
int cmd = s7_integer(s7_cadr(args));
|
|
|
|
struct window *w = window_i(win);
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
switch (cmd) {
|
2022-08-12 14:03:56 -05:00
|
|
|
case 0: // toggle fullscreen
|
2022-12-15 17:30:22 -06:00
|
|
|
window_togglefullscreen(w);
|
2022-08-12 14:03:56 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // Fullscreen on
|
2022-12-15 17:30:22 -06:00
|
|
|
window_makefullscreen(w);
|
2022-08-12 14:03:56 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // Fullscreen off
|
2022-12-15 17:30:22 -06:00
|
|
|
window_unfullscreen(w);
|
2022-08-12 14:03:56 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
s7_pointer s7_win_make(s7_scheme *sc, s7_pointer args) {
|
|
|
|
const char *title = s7_string(s7_car(args));
|
|
|
|
int w = s7_integer(s7_cadr(args));
|
|
|
|
int h = s7_integer(s7_caddr(args));
|
|
|
|
struct window *win = MakeSDLWindow(title, w, h, 0);
|
|
|
|
return s7_make_integer(sc, win->id);
|
|
|
|
}
|
2022-12-15 17:30:22 -06:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
s7_pointer s7_gen_cmd(s7_scheme *sc, s7_pointer args) {
|
|
|
|
int cmd = s7_integer(s7_car(args));
|
|
|
|
const char *s = s7_string(s7_cadr(args));
|
2022-12-15 17:30:22 -06:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
/* Branch table for general commands from scheme */
|
|
|
|
/* 0 : load level */
|
|
|
|
/* 1: load prefab */
|
2022-12-15 17:30:22 -06:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
switch (cmd) {
|
|
|
|
case 0:
|
|
|
|
load_level(s);
|
|
|
|
break;
|
2022-12-15 17:30:22 -06:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
case 1:
|
|
|
|
gameobject_makefromprefab(s);
|
|
|
|
break;
|
|
|
|
}
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
return args;
|
2022-08-07 01:43:45 -05:00
|
|
|
}
|
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
s7_pointer s7_sys_cmd(s7_scheme *sc, s7_pointer args) {
|
|
|
|
int cmd = s7_integer(s7_car(args));
|
2022-08-07 01:43:45 -05:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
switch (cmd) {
|
|
|
|
case 0:
|
|
|
|
quit();
|
|
|
|
break;
|
|
|
|
}
|
2022-08-07 01:43:45 -05:00
|
|
|
}
|
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
s7_pointer s7_sound_cmd(s7_scheme *sc, s7_pointer args) {
|
|
|
|
int sound = s7_integer(s7_car(args));
|
|
|
|
int cmd = s7_integer(s7_cadr(args));
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
switch (cmd) {
|
2022-08-12 14:03:56 -05:00
|
|
|
case 0: // play
|
|
|
|
break;
|
2022-08-05 14:23:39 -05:00
|
|
|
|
2022-08-12 14:03:56 -05:00
|
|
|
case 1: // pause
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // stop
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // play from beginning
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
return args;
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
/*
|
|
|
|
mrb_value mrb_nuke_cb(mrb_state *mrb, mrb_value self) {
|
|
|
|
mrb_float win;
|
|
|
|
mrb_sym cb;
|
|
|
|
mrb_get_args(mrb, "fn", &win, &cb);
|
|
|
|
window_i((int)win)->nuke_cb = cb;
|
|
|
|
return self;
|
|
|
|
}
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
mrb_value mrb_gui_cb(mrb_state *mrb, mrb_value self) {
|
|
|
|
mrb_float win;
|
|
|
|
mrb_sym cb;
|
|
|
|
mrb_get_args(mrb, "fn", &win, &cb);
|
|
|
|
window_i((int)win)->gui_cb = cb;
|
2022-08-12 14:03:56 -05:00
|
|
|
return self;
|
|
|
|
}
|
2022-12-16 11:54:05 -06:00
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
*/
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-12 10:48:21 -06:00
|
|
|
#define S7_FUNC(NAME, ARGS) s7_define_function(s7, #NAME, s7_ ##NAME, ARGS, 0, 0, "")
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-08-03 17:00:27 -05:00
|
|
|
void ffi_load() {
|
2022-12-15 17:30:22 -06:00
|
|
|
S7_FUNC(ui_label, 1);
|
|
|
|
S7_FUNC(ui_btn, 1);
|
|
|
|
S7_FUNC(ui_nel, 1);
|
|
|
|
S7_FUNC(ui_prop, 6);
|
|
|
|
S7_FUNC(ui_text, 2);
|
|
|
|
S7_FUNC(settings_cmd, 2);
|
|
|
|
S7_FUNC(win_cmd, 2);
|
|
|
|
S7_FUNC(ui_rendertext, 3);
|
|
|
|
S7_FUNC(log, 4);
|
2022-12-16 11:54:05 -06:00
|
|
|
S7_FUNC(win_make, 3);
|
|
|
|
S7_FUNC(gen_cmd, 2);
|
|
|
|
S7_FUNC(sys_cmd, 1);
|
|
|
|
S7_FUNC(sound_cmd, 2);
|
2022-08-03 17:00:27 -05:00
|
|
|
}
|
|
|
|
|