splines
This commit is contained in:
parent
68850b558a
commit
38da3627e7
2
Makefile
2
Makefile
|
@ -73,7 +73,7 @@ SEM = 0.0.1
|
|||
COM != git rev-parse --short HEAD
|
||||
VER = $(SEM)-$(COM)
|
||||
|
||||
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@
|
||||
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@
|
||||
|
||||
LIBPATH = -L$(BIN)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string.h>
|
||||
#include "mathc.h"
|
||||
#include "nuke.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "debugdraw.h"
|
||||
#include "gameobject.h"
|
||||
|
@ -12,6 +13,8 @@
|
|||
#include "stb_ds.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include "tinyspline.h"
|
||||
|
||||
#include "script.h"
|
||||
|
||||
#include "log.h"
|
||||
|
@ -106,6 +109,9 @@ void init_phys2dshape(struct phys2d_shape *shape, int go, void *data)
|
|||
cpShapeSetCollisionType(shape->shape, go);
|
||||
cpShapeSetUserData(shape->shape, shape);
|
||||
phys2d_shape_apply(shape);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void phys2d_shape_del(struct phys2d_shape *shape)
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#include "sound.h"
|
||||
#include "music.h"
|
||||
#include "level.h"
|
||||
#include "tinyspline.h"
|
||||
|
||||
void duk_dump_stack(duk_context *duk)
|
||||
{
|
||||
duk_push_context_dump(duk);
|
||||
YughInfo("DUK STACK\n%s", duk_to_string(duk, -1));
|
||||
duk_pop(duk);
|
||||
}
|
||||
|
||||
struct color duk2color(duk_context *duk, int p)
|
||||
|
@ -47,9 +49,13 @@ cpVect duk2vec2(duk_context *duk, int p) {
|
|||
|
||||
duk_get_prop_index(duk, p, 0);
|
||||
pos.x = duk_to_number(duk, -1);
|
||||
duk_pop(duk);
|
||||
|
||||
duk_get_prop_index(duk, p, 1);
|
||||
pos.y = duk_to_number(duk, -1);
|
||||
|
||||
duk_pop(duk);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
@ -126,6 +132,56 @@ duk_ret_t duk_win_make(duk_context *duk) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
duk_ret_t duk_spline_cmd(duk_context *duk)
|
||||
{
|
||||
tsBSpline spline;
|
||||
|
||||
int n = duk_get_length(duk, 4);
|
||||
int d = duk_to_int(duk, 2);
|
||||
cpVect points[n*d];
|
||||
|
||||
ts_bspline_new(n, d, duk_to_int(duk, 1), duk_to_int(duk, 3), &spline, NULL);
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
duk_get_prop_index(duk, 4, i);
|
||||
|
||||
points[i] = duk2vec2(duk, -1);
|
||||
|
||||
duk_pop(duk);
|
||||
}
|
||||
|
||||
ts_bspline_set_control_points(&spline, points, NULL);
|
||||
|
||||
|
||||
int nsamples = duk_to_int(duk, 5);
|
||||
cpVect samples[nsamples];
|
||||
int rsamples;
|
||||
ts_bspline_sample(&spline, nsamples, &samples, &rsamples, NULL);
|
||||
|
||||
int arridx = duk_push_array(duk);
|
||||
|
||||
duk_require_stack(duk, nsamples*3);
|
||||
|
||||
for (int i = 0; i < nsamples; i++) {
|
||||
int pidx = duk_push_array(duk);
|
||||
|
||||
|
||||
duk_push_number(duk, samples[i].x);
|
||||
duk_put_prop_index(duk, pidx, 0);
|
||||
duk_push_number(duk, samples[i].y);
|
||||
duk_put_prop_index(duk, pidx, 1);
|
||||
duk_put_prop_index(duk, arridx, i);
|
||||
}
|
||||
|
||||
free(samples);
|
||||
ts_bspline_free(&spline);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
duk_ret_t duk_cmd(duk_context *duk) {
|
||||
int cmd = duk_to_int(duk, 0);
|
||||
|
||||
|
@ -730,6 +786,7 @@ void ffi_load()
|
|||
|
||||
DUK_FUNC(make_sprite, 3);
|
||||
DUK_FUNC(make_anim2d, 3);
|
||||
DUK_FUNC(spline_cmd, 6);
|
||||
DUK_FUNC(make_box2d, 3);
|
||||
DUK_FUNC(cmd_box2d, DUK_VARARGS);
|
||||
DUK_FUNC(make_circle2d, 3);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#elif defined(SWIG)
|
||||
#define TS_DEPRECATED
|
||||
#else
|
||||
#warning "WARNING: TS_DEPRECATED is not supported by the compiler"
|
||||
#warning "WARNING: TS_DEPRECATED is not supported by compiler"
|
||||
#define TS_DEPRECATED
|
||||
#endif
|
||||
/*! @} */
|
||||
|
|
Loading…
Reference in a new issue