Bug fixing
This commit is contained in:
parent
35a00c96ee
commit
6d69566857
|
@ -56,10 +56,11 @@ struct color float2color(float *fcolor)
|
|||
cpShape *phys2d_query_pos(cpVect pos)
|
||||
{
|
||||
cpShapeFilter filter;
|
||||
filter.group = 0;
|
||||
filter.group = CP_NO_GROUP;
|
||||
filter.mask = CP_ALL_CATEGORIES;
|
||||
filter.categories = CP_ALL_CATEGORIES;
|
||||
cpShape *find = cpSpacePointQueryNearest(space, pos, 0.f, filter, NULL);
|
||||
// cpShape *find = cpSpaceSegmentQueryFirst(space, pos, pos, 0.f, filter, NULL);
|
||||
|
||||
return find;
|
||||
}
|
||||
|
@ -165,6 +166,16 @@ float *shape_color(cpShape *shape)
|
|||
return dbg_color;
|
||||
}
|
||||
|
||||
struct color shape_color_s(cpShape *shape)
|
||||
{
|
||||
float *c = shape_color(shape);
|
||||
struct color col;
|
||||
col.r = c[0]*255;
|
||||
col.g = c[1]*255;
|
||||
col.b = c[2]*255;
|
||||
return col;
|
||||
}
|
||||
|
||||
void phys2d_init()
|
||||
{
|
||||
space = cpSpaceNew();
|
||||
|
@ -545,6 +556,8 @@ void phys2d_applyedge(struct phys2d_edge *edge)
|
|||
cpVect b = gotransformpoint(go, edge->points[i+1]);
|
||||
cpSegmentShapeSetEndpoints(edge->shapes[i], a, b);
|
||||
cpSegmentShapeSetRadius(edge->shapes[i], edge->thickness);
|
||||
if (i > 0 && i < arrlen(edge->shapes)-1)
|
||||
cpSegmentShapeSetNeighbors(edge->shapes[i], gotransformpoint(go, edge->points[i-1]), gotransformpoint(go, edge->points[i+2]));
|
||||
go_shape_apply(NULL, edge->shapes[i], go);
|
||||
cpShapeSetUserData(edge->shapes[i], &edge->shape);
|
||||
}
|
||||
|
@ -572,7 +585,7 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge)
|
|||
drawpoints[i] = bodytransformpoint(cpShapeGetBody(edge->shapes[0]), drawpoints[i]);
|
||||
}
|
||||
|
||||
draw_edge(drawpoints, arrlen(edge->points), shape_color(edge->shapes[0]), edge->thickness*2);
|
||||
draw_edge(drawpoints, arrlen(edge->points), shape_color_s(edge->shapes[0]), edge->thickness*2);
|
||||
draw_points(drawpoints, arrlen(edge->points), 2, kinematic_color);
|
||||
}
|
||||
|
||||
|
@ -622,16 +635,7 @@ void register_collide(void *sym) {
|
|||
|
||||
}
|
||||
|
||||
struct hit_call {
|
||||
cpVect norm;
|
||||
struct callee c;
|
||||
int hit;
|
||||
};
|
||||
|
||||
struct hit_call *frame_hits;
|
||||
|
||||
|
||||
void duk_call_phys_cb(cpVect norm, struct callee c, int hit)
|
||||
void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb)
|
||||
{
|
||||
duk_push_heapptr(duk, c.fn);
|
||||
duk_push_heapptr(duk, c.obj);
|
||||
|
@ -644,9 +648,15 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit)
|
|||
duk_push_int(duk, hit);
|
||||
duk_put_prop_literal(duk, obj, "hit");
|
||||
|
||||
/* vect2duk(cpArbiterGetSurfaceVelocity(arb));
|
||||
cpShape *shape1;
|
||||
cpShape *shape2;
|
||||
cpArbiterGetShapes(arb, &shape1, &shape2);
|
||||
duk_push_boolean(duk, cpShapeGetSensor(shape2));
|
||||
duk_put_prop_literal(duk,obj,"sensor");
|
||||
|
||||
vect2duk(cpArbiterGetSurfaceVelocity(arb));
|
||||
duk_put_prop_literal(duk, obj, "velocity");
|
||||
*/
|
||||
|
||||
duk_call_method(duk,1);
|
||||
|
||||
// if (duk_pcall_method(duk, 1))
|
||||
|
@ -654,57 +664,60 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit)
|
|||
duk_pop(duk);
|
||||
}
|
||||
|
||||
void push_phys_cb(cpVect norm, struct callee c, int hit)
|
||||
{
|
||||
struct hit_call newhit;
|
||||
newhit.norm = norm;
|
||||
newhit.c = c;
|
||||
newhit.hit = hit;
|
||||
#define CTYPE_BEGIN 0
|
||||
#define CTYPE_SEP 1
|
||||
|
||||
arrpush(frame_hits, newhit);
|
||||
}
|
||||
|
||||
void fire_hits()
|
||||
{
|
||||
if (arrlen(frame_hits) == 0) return;
|
||||
|
||||
for (int i = 0; i < arrlen(frame_hits); i++)
|
||||
duk_call_phys_cb(frame_hits[i].norm, frame_hits[i].c, frame_hits[i].hit);
|
||||
|
||||
arrfree(frame_hits);
|
||||
}
|
||||
|
||||
static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data)
|
||||
static cpBool handle_collision(cpArbiter *arb, int type)
|
||||
{
|
||||
cpBody *body1;
|
||||
cpBody *body2;
|
||||
cpArbiterGetBodies(arb, &body1, &body2);
|
||||
|
||||
cpShape *shape1;
|
||||
cpShape *shape2;
|
||||
cpArbiterGetShapes(arb, &shape1, &shape2);
|
||||
|
||||
int g1 = cpBodyGetUserData(body1);
|
||||
int g2 = cpBodyGetUserData(body2);
|
||||
struct gameobject *go = id2go(g1);
|
||||
struct gameobject *go2 = id2go(g2);
|
||||
|
||||
cpShape *shape1;
|
||||
cpShape *shape2;
|
||||
cpArbiterGetShapes(arb, &shape1, &shape2);
|
||||
struct phys2d_shape *pshape1 = cpShapeGetUserData(shape1);
|
||||
struct phys2d_shape *pshape2 = cpShapeGetUserData(shape2);
|
||||
|
||||
cpVect norm1 = cpArbiterGetNormal(arb);
|
||||
cpVect vel1 = cpArbiterGetSurfaceVelocity(arb);
|
||||
|
||||
switch (type) {
|
||||
case CTYPE_BEGIN:
|
||||
for (int i = 0; i < arrlen(go->shape_cbs); i++)
|
||||
if (go->shape_cbs[i].shape == pshape1)
|
||||
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2);
|
||||
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2, arb);
|
||||
|
||||
if (go->cbs.begin.obj)
|
||||
duk_call_phys_cb(norm1, go->cbs.begin, g2);
|
||||
duk_call_phys_cb(norm1, go->cbs.begin, g2, arb);
|
||||
|
||||
break;
|
||||
|
||||
case CTYPE_SEP:
|
||||
if (go->cbs.separate.obj)
|
||||
duk_call_phys_cb(norm1, go->cbs.separate, g2, arb);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
return handle_collision(arb, CTYPE_BEGIN);
|
||||
}
|
||||
|
||||
static cpBool script_phys_cb_separate(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
return handle_collision(arb, CTYPE_SEP);
|
||||
}
|
||||
|
||||
void phys2d_rm_go_handlers(int go)
|
||||
{
|
||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
||||
|
@ -718,6 +731,7 @@ void phys2d_setup_handlers(int go)
|
|||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
||||
handler->userData = go;
|
||||
handler->beginFunc = script_phys_cb_begin;
|
||||
handler->separateFunc = script_phys_cb_separate;
|
||||
}
|
||||
|
||||
void phys2d_add_handler_type(int cmd, int go, struct callee c) {
|
||||
|
@ -738,3 +752,18 @@ void phys2d_add_handler_type(int cmd, int go, struct callee c) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int airborne = 0;
|
||||
|
||||
void inair(cpBody *body, cpArbiter *arbiter, void *data)
|
||||
{
|
||||
airborne = 0;
|
||||
}
|
||||
|
||||
int phys2d_in_air(cpBody *body)
|
||||
{
|
||||
airborne = 1;
|
||||
cpBodyEachArbiter(body, inair, NULL);
|
||||
|
||||
return airborne;
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ struct color {
|
|||
|
||||
void color2float(struct color, float *fcolor);
|
||||
struct color float2color(float *fcolor);
|
||||
struct color shape_color_s(cpShape *shape);
|
||||
|
||||
void shape_gui(struct phys2d_shape *shape);
|
||||
void phys2d_setup_handlers(int go);
|
||||
|
@ -146,5 +147,5 @@ cpVect world2go(struct gameobject *go, cpVect worldpos);
|
|||
cpVect go2world(struct gameobject *go, cpVect gopos);
|
||||
extern unsigned int category_masks[32];
|
||||
void set_cat_mask(int cat, unsigned int mask);
|
||||
|
||||
int phys2d_in_air(cpBody *body);
|
||||
#endif
|
||||
|
|
|
@ -139,14 +139,18 @@ void inflatepoints(cpVect *r, cpVect *p, float d, int n)
|
|||
|
||||
}
|
||||
|
||||
void draw_edge(cpVect *points, int n, float *color, int thickness)
|
||||
void draw_edge(cpVect *points, int n, struct color color, int thickness)
|
||||
{
|
||||
static_assert(sizeof(cpVect) == 2*sizeof(float));
|
||||
|
||||
float col[3] = {(float)color.r/255, (float)color.g/255, (float)color.b/255};
|
||||
|
||||
shader_use(rectShader);
|
||||
shader_setvec3(rectShader, "linecolor", color);
|
||||
shader_setvec3(rectShader, "linecolor", col);
|
||||
|
||||
if (thickness <= 1) {
|
||||
// glLineStipple(1, 0x00FF);
|
||||
// glEnable(GL_LINE_STIPPLE);
|
||||
shader_setfloat(rectShader, "alpha", 1.f);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * n * 2, points, GL_DYNAMIC_DRAW);
|
||||
|
@ -236,12 +240,12 @@ void draw_box(struct cpVect c, struct cpVect wh, struct color color)
|
|||
draw_rect(c.x, c.y, wh.x, wh.y, col);
|
||||
}
|
||||
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct color color)
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct color color, int capsize)
|
||||
{
|
||||
float col[3] = {(float)color.r/255, (float)color.g/255, (float)color.b/255};
|
||||
draw_line(start.x, start.y, end.x, end.y, col);
|
||||
|
||||
draw_cppoint(end, 5, color);
|
||||
draw_cppoint(end, capsize, color);
|
||||
}
|
||||
|
||||
void draw_grid(int width, int span)
|
||||
|
|
|
@ -6,9 +6,9 @@ struct color;
|
|||
|
||||
void debugdraw_init();
|
||||
void draw_line(int x1, int y1, int x2, int y2, float *color);
|
||||
void draw_edge(struct cpVect *points, int n, float *color, int thickness);
|
||||
void draw_edge(struct cpVect *points, int n, struct color color, int thickness);
|
||||
void draw_points(struct cpVect *points, int n, float size, float *color);
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct color);
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct color, int capsize);
|
||||
void draw_circle(int x, int y, float radius, int pixels, float *color, int fill);
|
||||
void draw_grid(int width, int span);
|
||||
void draw_rect(int x, int y, int w, int h, float *color);
|
||||
|
|
|
@ -16,9 +16,10 @@ char *catstr[] = {"engine", "script"};
|
|||
|
||||
FILE *logfile = NULL;
|
||||
|
||||
#define CONSOLE_BUF 1024*1024/* 1MB */
|
||||
#define CONSOLE_BUF 1024*1024*5/* 5MB */
|
||||
|
||||
char lastlog[ERROR_BUFFER] = {'\0'};
|
||||
char consolelog[CONSOLE_BUF] = {'\0'};
|
||||
|
||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||
{
|
||||
|
@ -39,6 +40,8 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
fprintf(stderr, "%s", buffer);
|
||||
fflush(stderr);
|
||||
|
||||
strncat(consolelog, buffer, CONSOLE_BUF);
|
||||
|
||||
if (logfile) {
|
||||
fprintf(logfile, "%s", buffer);
|
||||
fflush(logfile);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#define LOG_CRITICAL 3
|
||||
|
||||
extern char lastlog[];
|
||||
extern char consolelog[];
|
||||
|
||||
#if DBG
|
||||
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, ##__VA_ARGS__)
|
||||
|
|
|
@ -162,7 +162,7 @@ duk_idx_t vect2duk(cpVect v) {
|
|||
void duk_dump_stack(duk_context *duk)
|
||||
{
|
||||
YughInfo("DUK CALLSTACK");
|
||||
for (int i = -2; ; i--) { /* Start at -2 to skip the invoked C function */
|
||||
for (int i = -1; ; i--) { /* Start at -2 to skip the invoked C function */
|
||||
duk_inspect_callstack_entry(duk, i);
|
||||
if (duk_is_undefined(duk, -1)) break;
|
||||
|
||||
|
@ -321,6 +321,14 @@ duk_ret_t duk_nuke(duk_context *duk)
|
|||
case 13:
|
||||
nuke_row(duk_to_int(duk,1));
|
||||
break;
|
||||
|
||||
case 14:
|
||||
nuke_scrolltext(duk_to_string(duk,1));
|
||||
break;
|
||||
|
||||
case 15:
|
||||
nuke_nel_h(duk_to_int(duk,1), duk_to_int(duk,2));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -619,7 +627,7 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
|||
break;
|
||||
|
||||
case 27:
|
||||
timer_remove(duk2timer(duk,1));
|
||||
timer_remove(duk_to_int(duk,1));
|
||||
break;
|
||||
|
||||
case 28:
|
||||
|
@ -840,8 +848,24 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
|||
return 1;
|
||||
|
||||
case 81:
|
||||
draw_arrow(duk2vec2(duk,1), duk2vec2(duk,2), duk2color(duk,3));
|
||||
draw_arrow(duk2vec2(duk,1), duk2vec2(duk,2), duk2color(duk,3), duk_to_int(duk,4));
|
||||
return 0;
|
||||
|
||||
case 82:
|
||||
gameobject_draw_debug(duk_to_int(duk,1));
|
||||
return 0;
|
||||
|
||||
case 83:
|
||||
draw_edge(duk2cpvec2arr(duk, 1), 2, duk2color(duk,2), 1);
|
||||
return 0;
|
||||
|
||||
case 84:
|
||||
duk_push_string(duk, consolelog);
|
||||
return 1;
|
||||
|
||||
case 85:
|
||||
vect2duk(cpvproject(duk2vec2(duk,1), duk2vec2(duk,2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -879,6 +903,9 @@ duk_ret_t duk_register(duk_context *duk) {
|
|||
unregister_gui(c);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
register_debug(c);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -906,11 +933,15 @@ duk_ret_t duk_register_collide(duk_context *duk) {
|
|||
|
||||
case 1:
|
||||
gameobject_add_shape_collider(go, c, duk_get_pointer(duk,4));
|
||||
YughInfo("Adding gameobject %d shape collider for shape %p", go, duk_get_pointer(duk,4));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
phys2d_rm_go_handlers(go);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
id2go(go)->cbs.separate = c;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1050,6 +1081,10 @@ duk_ret_t duk_set_body(duk_context *duk) {
|
|||
case 11:
|
||||
go->f = fmax(duk_to_number(duk,2),0);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
cpBodyApplyForceAtWorldPoint(go->body, duk2vec2(duk, 2), cpBodyGetPosition(go->body));
|
||||
return 0;
|
||||
}
|
||||
|
||||
cpSpaceReindexShapesForBody(space, go->body);
|
||||
|
@ -1091,6 +1126,10 @@ duk_ret_t duk_q_body(duk_context *duk) {
|
|||
case 6:
|
||||
duk_push_number(duk, cpBodyGetMoment(go->body));
|
||||
return 1;
|
||||
|
||||
case 7:
|
||||
duk_push_boolean(duk, phys2d_in_air(go->body));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1329,9 +1368,9 @@ duk_ret_t duk_make_timer(duk_context *duk) {
|
|||
struct callee *c = malloc(sizeof(*c));
|
||||
c->fn = sym;
|
||||
c->obj = obj;
|
||||
struct timer *timer = timer_make(secs, call_callee, c, 1);
|
||||
int id = timer_make(secs, call_callee, c, 1);
|
||||
|
||||
duk_push_int(duk, timer->timerid);
|
||||
duk_push_int(duk, id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -252,8 +252,6 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
|||
shader_setvec3(shader, "textColor", color);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void text_settype(struct sFont *mfont)
|
||||
|
@ -330,5 +328,9 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
|||
}
|
||||
}
|
||||
|
||||
if (caret > curchar) {
|
||||
draw_char_box(font->Characters[69], cursor, scale, color);
|
||||
}
|
||||
|
||||
// glDrawArrays(GL_TRIANGLE_STRIP, 0, 4*2);
|
||||
}
|
||||
|
|
|
@ -127,10 +127,8 @@ void gameobject_apply(struct gameobject *go)
|
|||
cpBodySetMoment(go->body, 0.f);
|
||||
cpBodyEachShape(go->body, go_shape_moi, go);
|
||||
|
||||
if (cpBodyGetMoment(go->body) <= 0.f) {
|
||||
YughError("Moment for object %d is zero. Setting to one.", go2id(go));
|
||||
if (cpBodyGetMoment(go->body) <= 0.f)
|
||||
cpBodySetMoment(go->body, 1.f);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -157,8 +155,12 @@ int MakeGameobject()
|
|||
.mass = 1.f,
|
||||
.next = -1,
|
||||
.sensor = 0,
|
||||
.shape_cbs = NULL,
|
||||
};
|
||||
|
||||
go.cbs.begin.obj = NULL;
|
||||
go.cbs.separate.obj = NULL;
|
||||
|
||||
go.body = cpSpaceAddBody(space, cpBodyNew(go.mass, 1.f));
|
||||
|
||||
int retid;
|
||||
|
@ -330,16 +332,20 @@ void body_draw_shapes_dbg(cpBody *body, cpShape *shape, void *data) {
|
|||
s->debugdraw(s->data);
|
||||
}
|
||||
|
||||
void gameobject_draw_debugs() {
|
||||
for (int i = 0; i < arrlen(gameobjects); i++) {
|
||||
if (!gameobjects[i].body) continue;
|
||||
void gameobject_draw_debug(int go)
|
||||
{
|
||||
struct gameobject *g = id2go(go);
|
||||
if (!g || !g->body) return;
|
||||
|
||||
cpVect pos = cpBodyGetPosition(gameobjects[i].body);
|
||||
cpVect pos = cpBodyGetPosition(g->body);
|
||||
float color[3] = {0.76f, 0.38f, 1.f};
|
||||
draw_point(pos.x, pos.y, 3.f, color);
|
||||
cpBodyEachShape(gameobjects[i].body, body_draw_shapes_dbg, NULL);
|
||||
cpBodyEachShape(g->body, body_draw_shapes_dbg, NULL);
|
||||
}
|
||||
|
||||
void gameobject_draw_debugs() {
|
||||
for (int i = 0; i < arrlen(gameobjects); i++)
|
||||
gameobject_draw_debug(i);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ void gameobject_setangle(struct gameobject *go, float angle);
|
|||
void gameobject_setpos(struct gameobject *go, cpVect vec);
|
||||
|
||||
void gameobject_draw_debugs();
|
||||
void gameobject_draw_debug(int go);
|
||||
|
||||
void object_gui(struct gameobject *go);
|
||||
|
||||
|
|
|
@ -338,6 +338,9 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods
|
|||
switch (action) {
|
||||
case GLFW_PRESS:
|
||||
snprintf(keystr, 50, "input_%s_pressed", kkey);
|
||||
call_input_signal(keystr);
|
||||
snprintf(keystr,50,"input_%s_pressrep", kkey);
|
||||
call_input_signal(keystr);
|
||||
add_downkey(key);
|
||||
call_input_signal("input_any_pressed");
|
||||
|
||||
|
@ -349,16 +352,18 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods
|
|||
|
||||
case GLFW_RELEASE:
|
||||
snprintf(keystr, 50, "input_%s_released", kkey);
|
||||
call_input_signal(keystr);
|
||||
rm_downkey(key);
|
||||
call_input_signal("input_any_released");
|
||||
break;
|
||||
|
||||
case GLFW_REPEAT:
|
||||
snprintf(keystr, 50, "input_%s_rep", kkey);
|
||||
call_input_signal(keystr);
|
||||
snprintf(keystr,50,"input_%s_pressrep", kkey);
|
||||
call_input_signal(keystr);
|
||||
break;
|
||||
}
|
||||
|
||||
call_input_signal(keystr);
|
||||
}
|
||||
|
||||
void cursor_hide()
|
||||
|
|
|
@ -113,10 +113,19 @@ void nuke_checkbox(const char *lbl, int *val) {
|
|||
nk_checkbox_label(ctx, lbl, val);
|
||||
}
|
||||
|
||||
void nuke_scrolltext(char *str)
|
||||
{
|
||||
nk_edit_string_zero_terminated(ctx, NK_EDIT_MULTILINE|NK_EDIT_GOTO_END_ON_ACTIVATE, str, 1024*1024*5, NULL);
|
||||
}
|
||||
|
||||
void nuke_nel(int cols) {
|
||||
nk_layout_row_dynamic(ctx, 25, cols);
|
||||
}
|
||||
|
||||
void nuke_nel_h(int cols, int h) {
|
||||
nk_layout_row_dynamic(ctx, h, cols);
|
||||
}
|
||||
|
||||
void nuke_label(const char *s) {
|
||||
nk_label(ctx, s, NK_TEXT_LEFT);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ void nuke_property_float3(const char *label, float min, float *val, float max, f
|
|||
void nuke_property_int(const char *lbl, int min, int *val, int max, int step);
|
||||
void nuke_radio_btn(const char *lbl, int *val, int cmp);
|
||||
void nuke_checkbox(const char *lbl, int *val);
|
||||
void nuke_nel_h(int cols, int h);
|
||||
void nuke_nel(int cols);
|
||||
void nuke_row(int height);
|
||||
void nuke_label(const char *s);
|
||||
|
@ -29,6 +30,9 @@ void nuke_prop_float(const char *label, float min, float *val, float max, float
|
|||
void nuke_edit_str(char *str);
|
||||
void nuke_img(char *path);
|
||||
|
||||
void nuke_scrolltext(char *str);
|
||||
|
||||
|
||||
int nuke_push_tree_id(const char *name, int id);
|
||||
void nuke_tree_pop();
|
||||
|
||||
|
|
|
@ -188,6 +188,8 @@ void openglRender(struct window *window)
|
|||
if (debugDrawPhysics)
|
||||
gameobject_draw_debugs();
|
||||
|
||||
call_debugs();
|
||||
|
||||
////// TEXT && GUI
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, ui_projection);
|
||||
|
|
|
@ -154,6 +154,7 @@ void script_call_sym_args(void *sym, void *args)
|
|||
struct callee *updates = NULL;
|
||||
struct callee *physics = NULL;
|
||||
struct callee *guis = NULL;
|
||||
struct callee *debugs = NULL;
|
||||
struct callee *nk_guis = NULL;
|
||||
|
||||
void unregister_obj(void *obj)
|
||||
|
@ -168,7 +169,14 @@ void unregister_obj(void *obj)
|
|||
if (guis[i].obj == obj) arrdel(guis,i);
|
||||
|
||||
for (int i = arrlen(nk_guis)-1; i >= 0; i--)
|
||||
if (guis[i].obj == obj) arrdel(nk_guis,i);
|
||||
if (nk_guis[i].obj == obj) arrdel(nk_guis,i);
|
||||
|
||||
for (int i = arrlen(debugs)-1; i >= 0; i--)
|
||||
if (debugs[i].obj == obj) arrdel(debugs,i);
|
||||
}
|
||||
|
||||
void register_debug(struct callee c) {
|
||||
arrput(debugs, c);
|
||||
}
|
||||
|
||||
void unregister_gui(struct callee c)
|
||||
|
@ -237,23 +245,32 @@ void callee_vec2(struct callee c, cpVect vec)
|
|||
}
|
||||
|
||||
void call_updates(double dt) {
|
||||
for (int i = 0; i < arrlen(updates); i++) {
|
||||
for (int i = 0; i < arrlen(updates); i++)
|
||||
callee_dbl(updates[i], dt);
|
||||
}
|
||||
}
|
||||
|
||||
void call_gui() {
|
||||
for (int i = 0; i < arrlen(guis); i++)
|
||||
call_callee(&guis[i]);
|
||||
}
|
||||
|
||||
void call_debug() {
|
||||
for (int i = 0; i < arrlen(debugs); i++)
|
||||
call_callee(&debugs[i]);
|
||||
}
|
||||
|
||||
void call_nk_gui() {
|
||||
for (int i = 0; i < arrlen(nk_guis); i++)
|
||||
call_callee(&nk_guis[i]);
|
||||
}
|
||||
|
||||
void call_physics(double dt) {
|
||||
for (int i = 0; i < arrlen(physics); i++) {
|
||||
callee_dbl(updates[i], dt);
|
||||
for (int i = 0; i < arrlen(physics); i++)
|
||||
callee_dbl(physics[i], dt);
|
||||
}
|
||||
|
||||
void call_debugs()
|
||||
{
|
||||
for (int i = 0; i < arrlen(debugs); i++)
|
||||
call_callee(&debugs[i]);
|
||||
}
|
||||
|
|
|
@ -35,9 +35,11 @@ time_t file_mod_secs(const char *file);
|
|||
|
||||
void register_update(struct callee c);
|
||||
void call_updates(double dt);
|
||||
void call_debugs();
|
||||
|
||||
void unregister_gui(struct callee c);
|
||||
void register_gui(struct callee c);
|
||||
void register_debug(struct callee c);
|
||||
void register_nk_gui(struct callee c);
|
||||
void call_gui();
|
||||
void call_nk_gui();
|
||||
|
|
|
@ -206,8 +206,6 @@ void play_oneshot(struct wav *wav) {
|
|||
struct sound *new = malloc(sizeof(*new));
|
||||
new->data = wav;
|
||||
new->bus = first_free_bus(dsp_filter(new, sound_fillbuf));
|
||||
YughInfo("Playing sound ...");
|
||||
YughInfo("Bus is on? %d", new->bus->on);
|
||||
new->playing=1;
|
||||
new->loop=0;
|
||||
new->frame = 0;
|
||||
|
|
|
@ -43,7 +43,6 @@ struct bus *first_free_bus(struct dsp_filter in) {
|
|||
if (!bus[i].on) {
|
||||
bus[i].on = 1;
|
||||
bus[i].in = in;
|
||||
YughInfo("Returning bus %d", i);
|
||||
return &bus[i];
|
||||
}
|
||||
|
||||
|
@ -67,7 +66,6 @@ struct bus *first_free_bus(struct dsp_filter in) {
|
|||
|
||||
void bus_free(struct bus *b)
|
||||
{
|
||||
YughInfo("Freeing bus %d", b->id);
|
||||
b->on = 0;
|
||||
return;
|
||||
|
||||
|
|
|
@ -31,32 +31,31 @@ void timer_update(double dt) {
|
|||
check_timer(&timers[i], dt);
|
||||
}
|
||||
|
||||
struct timer *timer_make(double interval, void (*callback)(void *param), void *param, int own) {
|
||||
int timer_make(double interval, void (*callback)(void *param), void *param, int own) {
|
||||
struct timer new;
|
||||
new.remain_time = interval;
|
||||
new.interval = interval;
|
||||
new.cb = callback;
|
||||
new.data = param;
|
||||
new.repeat = 1;
|
||||
new.timerid = arrlen(timers);
|
||||
new.owndata = own;
|
||||
new.next = -1;
|
||||
|
||||
if (first < 0) {
|
||||
timer_start(&new);
|
||||
arrput(timers, new);
|
||||
return &arrlast(timers);
|
||||
return arrlen(timers)-1;
|
||||
} else {
|
||||
int retid = first;
|
||||
first = id2timer(first)->next;
|
||||
*id2timer(retid) = new;
|
||||
timer_start(id2timer(retid));
|
||||
return id2timer(retid);
|
||||
return retid;
|
||||
}
|
||||
}
|
||||
|
||||
void timer_pause(struct timer *t) {
|
||||
if (!t->on) return;
|
||||
|
||||
t->on = 0;
|
||||
}
|
||||
|
||||
|
@ -71,11 +70,11 @@ void timer_start(struct timer *t) {
|
|||
t->on = 1;
|
||||
}
|
||||
|
||||
void timer_remove(struct timer *t) {
|
||||
int i = t->timerid;
|
||||
void timer_remove(int id) {
|
||||
struct timer *t = id2timer(id);
|
||||
if (t->owndata) free(t->data);
|
||||
timers[i].timerid =
|
||||
timers[i].timerid = i;
|
||||
t->next = first;
|
||||
first = id;
|
||||
}
|
||||
|
||||
void timerr_settime(struct timer *t, double interval) {
|
||||
|
|
|
@ -13,9 +13,9 @@ struct timer {
|
|||
int next;
|
||||
};
|
||||
|
||||
struct timer *timer_make(double interval, void (*callback)(void *param), void *param, int own);
|
||||
int timer_make(double interval, void (*callback)(void *param), void *param, int own);
|
||||
struct timer *id2timer(int id);
|
||||
void timer_remove(struct timer *t);
|
||||
void timer_remove(int id);
|
||||
void timer_start(struct timer *t);
|
||||
void timer_pause(struct timer *t);
|
||||
void timer_stop(struct timer *t);
|
||||
|
|
|
@ -21,14 +21,6 @@
|
|||
|
||||
#include "2dphysics.h"
|
||||
|
||||
#if ED
|
||||
#include "editor.h"
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
//#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -62,8 +54,9 @@ int fps;
|
|||
#define SIM_STEP 3
|
||||
|
||||
void seghandle(int sig) {
|
||||
/*
|
||||
#ifdef __linux__
|
||||
/* void *ents[512];
|
||||
void *ents[512];
|
||||
size_t size;
|
||||
|
||||
size = backtrace(ents, 512);
|
||||
|
@ -85,20 +78,19 @@ void seghandle(int sig) {
|
|||
|
||||
duk_dump_stack(duk);
|
||||
|
||||
exit(1);*/
|
||||
exit(1);
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
int main(int argc, char **args) {
|
||||
int logout = 1;
|
||||
ed = 1;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (args[i][0] == '-') {
|
||||
switch(args[i][1]) {
|
||||
case 'p':
|
||||
if (strncmp(&args[i][2], "lay", 3))
|
||||
continue;
|
||||
|
||||
ed = 0;
|
||||
break;
|
||||
|
||||
|
@ -135,9 +127,6 @@ int main(int argc, char **args) {
|
|||
}
|
||||
}
|
||||
|
||||
ed = 0;
|
||||
|
||||
|
||||
#if DBG
|
||||
if (logout) {
|
||||
time_t now = time(NULL);
|
||||
|
@ -175,6 +164,9 @@ int main(int argc, char **args) {
|
|||
|
||||
window_set_icon("icon.png");
|
||||
|
||||
if (ed)
|
||||
script_dofile("editor.js");
|
||||
else
|
||||
script_dofile("game.js");
|
||||
|
||||
input_init();
|
||||
|
@ -192,7 +184,7 @@ int main(int argc, char **args) {
|
|||
if (framei == FPSBUF) framei = 0;
|
||||
|
||||
if (sim_play == SIM_PLAY || sim_play == SIM_STEP) {
|
||||
timer_update(elapsed);
|
||||
timer_update(elapsed * timescale);
|
||||
physlag += elapsed;
|
||||
call_updates(elapsed * timescale);
|
||||
while (physlag >= physMS) {
|
||||
|
@ -200,7 +192,6 @@ int main(int argc, char **args) {
|
|||
physlag -= physMS;
|
||||
phys2d_update(physMS * timescale);
|
||||
call_physics(physMS * timescale);
|
||||
fire_hits();
|
||||
if (sim_play == SIM_STEP) sim_pause();
|
||||
phys_step = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue