Many fixes
This commit is contained in:
parent
0826197b91
commit
3018a1a188
|
@ -30,6 +30,13 @@ float dynamic_color[3] = {255/255, 70/255, 46/255};
|
||||||
float kinematic_color[3] = {255/255, 206/255,71/255};
|
float kinematic_color[3] = {255/255, 206/255,71/255};
|
||||||
float static_color[3] = {0.22f, 0.271f, 1.f};
|
float static_color[3] = {0.22f, 0.271f, 1.f};
|
||||||
|
|
||||||
|
unsigned int category_masks[32];
|
||||||
|
|
||||||
|
void set_cat_mask(int cat, unsigned int mask)
|
||||||
|
{
|
||||||
|
category_masks[cat] = mask;
|
||||||
|
}
|
||||||
|
|
||||||
void color2float(struct color color, float *fcolor)
|
void color2float(struct color color, float *fcolor)
|
||||||
{
|
{
|
||||||
fcolor[0] = (float)color.r/255;
|
fcolor[0] = (float)color.r/255;
|
||||||
|
@ -565,9 +572,9 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge)
|
||||||
void shape_enabled(struct phys2d_shape *shape, int enabled)
|
void shape_enabled(struct phys2d_shape *shape, int enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
cpShapeSetFilter(shape->shape, CP_SHAPE_FILTER_ALL);
|
cpShapeSetFilter(shape->data, CP_SHAPE_FILTER_ALL);
|
||||||
else
|
else
|
||||||
cpShapeSetFilter(shape->shape, CP_SHAPE_FILTER_NONE);
|
cpShapeSetFilter(shape->data, CP_SHAPE_FILTER_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int shape_is_enabled(struct phys2d_shape *shape)
|
int shape_is_enabled(struct phys2d_shape *shape)
|
||||||
|
@ -606,6 +613,15 @@ 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)
|
||||||
{
|
{
|
||||||
duk_push_heapptr(duk, c.fn);
|
duk_push_heapptr(duk, c.fn);
|
||||||
|
@ -619,6 +635,9 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit)
|
||||||
duk_push_int(duk, hit);
|
duk_push_int(duk, hit);
|
||||||
duk_put_prop_literal(duk, obj, "hit");
|
duk_put_prop_literal(duk, obj, "hit");
|
||||||
|
|
||||||
|
/* vect2duk(cpArbiterGetSurfaceVelocity(arb));
|
||||||
|
duk_put_prop_literal(duk, obj, "velocity");
|
||||||
|
*/
|
||||||
duk_call_method(duk,1);
|
duk_call_method(duk,1);
|
||||||
|
|
||||||
// if (duk_pcall_method(duk, 1))
|
// if (duk_pcall_method(duk, 1))
|
||||||
|
@ -626,9 +645,28 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit)
|
||||||
duk_pop(duk);
|
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;
|
||||||
|
|
||||||
|
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 script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data)
|
||||||
{
|
{
|
||||||
|
|
||||||
cpBody *body1;
|
cpBody *body1;
|
||||||
cpBody *body2;
|
cpBody *body2;
|
||||||
cpArbiterGetBodies(arb, &body1, &body2);
|
cpArbiterGetBodies(arb, &body1, &body2);
|
||||||
|
@ -642,26 +680,19 @@ static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data)
|
||||||
struct gameobject *go = id2go(g1);
|
struct gameobject *go = id2go(g1);
|
||||||
struct gameobject *go2 = id2go(g2);
|
struct gameobject *go2 = id2go(g2);
|
||||||
|
|
||||||
|
struct phys2d_shape *pshape1 = cpShapeGetUserData(shape1);
|
||||||
|
struct phys2d_shape *pshape2 = cpShapeGetUserData(shape2);
|
||||||
|
|
||||||
cpVect norm1 = cpArbiterGetNormal(arb);
|
cpVect norm1 = cpArbiterGetNormal(arb);
|
||||||
|
cpVect vel1 = cpArbiterGetSurfaceVelocity(arb);
|
||||||
|
|
||||||
for (int i = 0; i < arrlen(go->shape_cbs); i++)
|
for (int i = 0; i < arrlen(go->shape_cbs); i++)
|
||||||
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2);
|
if (go->shape_cbs[i].shape == pshape1)
|
||||||
|
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2);
|
||||||
|
|
||||||
if (go->cbs.begin.obj)
|
if (go->cbs.begin.obj)
|
||||||
duk_call_phys_cb(norm1, go->cbs.begin, g2);
|
duk_call_phys_cb(norm1, go->cbs.begin, g2);
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
cpVect norm2 = norm1;
|
|
||||||
norm2.x *= -1;
|
|
||||||
norm2.y *= -1;
|
|
||||||
|
|
||||||
for (int i = 0; i < arrlen(go2->shape_cbs); i++)
|
|
||||||
duk_call_phys_cb(norm2, go2->shape_cbs[i].cbs.begin, g1);
|
|
||||||
|
|
||||||
if (go2->cbs.begin.obj)
|
|
||||||
duk_call_phys_cb(norm2, go2->cbs.begin, g1);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,14 +704,16 @@ void phys2d_rm_go_handlers(int go)
|
||||||
handler->separateFunc = NULL;
|
handler->separateFunc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void phys2d_setup_handlers(int go)
|
||||||
|
{
|
||||||
|
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
||||||
|
handler->userData = go;
|
||||||
|
handler->beginFunc = script_phys_cb_begin;
|
||||||
|
}
|
||||||
|
|
||||||
void phys2d_add_handler_type(int cmd, int go, struct callee c) {
|
void phys2d_add_handler_type(int cmd, int go, struct callee c) {
|
||||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
|
||||||
|
|
||||||
handler->userData = go;
|
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 0:
|
case 0:
|
||||||
handler->beginFunc = script_phys_cb_begin;
|
|
||||||
id2go(go)->cbs.begin = c;
|
id2go(go)->cbs.begin = c;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,12 @@ struct phys_cbs {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct shape_cb {
|
struct shape_cb {
|
||||||
cpShape *shape;
|
struct phys2d_shape *shape;
|
||||||
struct phys_cbs cbs;
|
struct phys_cbs cbs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void fire_hits();
|
||||||
|
|
||||||
void phys2d_add_handler_type(int cmd, int go, struct callee c);
|
void phys2d_add_handler_type(int cmd, int go, struct callee c);
|
||||||
void register_collide(void *sym);
|
void register_collide(void *sym);
|
||||||
void phys2d_rm_go_handlers(int go);
|
void phys2d_rm_go_handlers(int go);
|
||||||
|
@ -136,9 +138,12 @@ void color2float(struct color, float *fcolor);
|
||||||
struct color float2color(float *fcolor);
|
struct color float2color(float *fcolor);
|
||||||
|
|
||||||
void shape_gui(struct phys2d_shape *shape);
|
void shape_gui(struct phys2d_shape *shape);
|
||||||
|
void phys2d_setup_handlers(int go);
|
||||||
|
|
||||||
void phys2d_reindex_body(cpBody *body);
|
void phys2d_reindex_body(cpBody *body);
|
||||||
cpVect world2go(struct gameobject *go, cpVect worldpos);
|
cpVect world2go(struct gameobject *go, cpVect worldpos);
|
||||||
cpVect go2world(struct gameobject *go, cpVect gopos);
|
cpVect go2world(struct gameobject *go, cpVect gopos);
|
||||||
|
extern unsigned int category_masks[32];
|
||||||
|
void set_cat_mask(int cat, unsigned int mask);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -255,24 +255,13 @@ void draw_grid(int width, int span)
|
||||||
|
|
||||||
void draw_point(int x, int y, float r, float *color)
|
void draw_point(int x, int y, float r, float *color)
|
||||||
{
|
{
|
||||||
shader_use(circleShader);
|
draw_circle(x,y,r,r,color,1);
|
||||||
|
|
||||||
float verts[] = { x, y };
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, circleVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_DYNAMIC_DRAW);
|
|
||||||
glPointSize(r);
|
|
||||||
|
|
||||||
glBindVertexArray(circleVAO);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
|
||||||
glDrawArrays(GL_POINTS, 0, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_cppoint(struct cpVect point, float r)
|
void draw_cppoint(struct cpVect point, float r, struct color color)
|
||||||
{
|
{
|
||||||
float white[3] = {1.f, 1.f, 1.f};
|
float col[3] = {(float)color.r/255, (float)color.g/255, (float)color.b/255};
|
||||||
draw_point(point.x, point.y, r, white);
|
draw_point(point.x, point.y, r, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_points(struct cpVect *points, int n, float size, float *color)
|
void draw_points(struct cpVect *points, int n, float size, float *color)
|
||||||
|
|
|
@ -13,7 +13,7 @@ void draw_grid(int width, int span);
|
||||||
void draw_rect(int x, int y, int w, int h, float *color);
|
void draw_rect(int x, int y, int w, int h, float *color);
|
||||||
void draw_box(struct cpVect c, struct cpVect wh, struct color color);
|
void draw_box(struct cpVect c, struct cpVect wh, struct color color);
|
||||||
void draw_point(int x, int y, float r, float *color);
|
void draw_point(int x, int y, float r, float *color);
|
||||||
void draw_cppoint(struct cpVect point, float r);
|
void draw_cppoint(struct cpVect point, float r, struct color color);
|
||||||
void draw_poly(float *points, int n, float *color);
|
void draw_poly(float *points, int n, float *color);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define ERROR_BUFFER 2048
|
#define ERROR_BUFFER 1024*1024
|
||||||
|
|
||||||
#define LOG_INFO 0
|
#define LOG_INFO 0
|
||||||
#define LOG_WARN 1
|
#define LOG_WARN 1
|
||||||
|
|
|
@ -105,16 +105,13 @@ cpBitmask duk2bitmask(duk_context *duk, int p)
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
duk_get_prop_index(duk, p, i);
|
duk_get_prop_index(duk, p, i);
|
||||||
int val = duk_to_int(duk, -1);
|
int val = duk_to_boolean(duk, -1);
|
||||||
duk_pop(duk);
|
duk_pop(duk);
|
||||||
|
if (!val) continue;
|
||||||
|
|
||||||
if (val > 10) continue;
|
mask |= 1<<i;
|
||||||
|
|
||||||
mask |= 1<<val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YughInfo(BYTE_TO_BINARY_PATTERN,BYTE_TO_BINARY(mask));
|
|
||||||
|
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +196,7 @@ duk_ret_t duk_gui_text(duk_context *duk) {
|
||||||
|
|
||||||
float size = duk_to_number(duk, 2);
|
float size = duk_to_number(duk, 2);
|
||||||
const float white[3] = {1.f, 1.f, 1.f};
|
const float white[3] = {1.f, 1.f, 1.f};
|
||||||
renderText(s, &pos, size, white, 500);
|
renderText(s, &pos, size, white, 500,-1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,9 +208,21 @@ duk_ret_t duk_ui_text(duk_context *duk)
|
||||||
float size = duk_to_number(duk, 2);
|
float size = duk_to_number(duk, 2);
|
||||||
struct color c = duk2color(duk,3);
|
struct color c = duk2color(duk,3);
|
||||||
const float col[3] = {(float)c.r/255, (float)c.g/255, (float)c.b/255};
|
const float col[3] = {(float)c.r/255, (float)c.g/255, (float)c.b/255};
|
||||||
renderText(s, &pos, size, col, 500);
|
renderText(s, &pos, size, col, 500,-1);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_cursor_text(duk_context *duk)
|
||||||
|
{
|
||||||
|
const char *s = duk_to_string(duk, 0);
|
||||||
|
cpVect pos = duk2vec2(duk, 1);
|
||||||
|
|
||||||
|
float size = duk_to_number(duk, 2);
|
||||||
|
struct color c = duk2color(duk,3);
|
||||||
|
const float col[3] = {(float)c.r/255, (float)c.g/255, (float)c.b/255};
|
||||||
|
int cursor = duk_to_int(duk,4);
|
||||||
|
renderText(s, &pos, size, col, 500,cursor);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
duk_ret_t duk_gui_img(duk_context *duk) {
|
duk_ret_t duk_gui_img(duk_context *duk) {
|
||||||
|
@ -308,6 +317,10 @@ duk_ret_t duk_nuke(duk_context *duk)
|
||||||
case 12:
|
case 12:
|
||||||
nuke_tree_pop();
|
nuke_tree_pop();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case 13:
|
||||||
|
nuke_row(duk_to_int(duk,1));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -706,7 +719,7 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case 51:
|
case 51:
|
||||||
draw_cppoint(duk2vec2(duk, 1), duk_to_number(duk, 2));
|
draw_cppoint(duk2vec2(duk, 1), duk_to_number(duk, 2), duk2color(duk,3));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case 52:
|
case 52:
|
||||||
|
@ -801,6 +814,26 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
||||||
case 74:
|
case 74:
|
||||||
duk_push_number(duk, cpSpaceGetDamping(space));
|
duk_push_number(duk, cpSpaceGetDamping(space));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
case 75:
|
||||||
|
id2go(duk_to_int(duk,1))->layer = duk_to_int(duk,2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case 76:
|
||||||
|
set_cat_mask(duk_to_int(duk,1), duk2bitmask(duk,2));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case 77:
|
||||||
|
input_to_game();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 78:
|
||||||
|
input_to_nuke();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 79:
|
||||||
|
duk_push_boolean(duk, phys_stepping());
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -846,7 +879,7 @@ duk_ret_t duk_register(duk_context *duk) {
|
||||||
void gameobject_add_shape_collider(int go, struct callee c, struct phys2d_shape *shape)
|
void gameobject_add_shape_collider(int go, struct callee c, struct phys2d_shape *shape)
|
||||||
{
|
{
|
||||||
struct shape_cb shapecb;
|
struct shape_cb shapecb;
|
||||||
shapecb.shape = shape->shape;
|
shapecb.shape = shape;
|
||||||
shapecb.cbs.begin = c;
|
shapecb.cbs.begin = c;
|
||||||
arrpush(id2go(go)->shape_cbs, shapecb);
|
arrpush(id2go(go)->shape_cbs, shapecb);
|
||||||
}
|
}
|
||||||
|
@ -860,11 +893,12 @@ duk_ret_t duk_register_collide(duk_context *duk) {
|
||||||
|
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case 0:
|
case 0:
|
||||||
phys2d_add_handler_type(cmd, go, c);
|
id2go(go)->cbs.begin = c;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
gameobject_add_shape_collider(go, c, duk_get_pointer(duk,4));
|
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;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -1045,6 +1079,10 @@ duk_ret_t duk_q_body(duk_context *duk) {
|
||||||
case 5:
|
case 5:
|
||||||
duk_push_number(duk, cpBodyGetMass(go->body));
|
duk_push_number(duk, cpBodyGetMass(go->body));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
duk_push_number(duk, cpBodyGetMoment(go->body));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1322,9 +1360,8 @@ void ffi_load()
|
||||||
|
|
||||||
DUK_FUNC(gui_text, DUK_VARARGS);
|
DUK_FUNC(gui_text, DUK_VARARGS);
|
||||||
DUK_FUNC(ui_text, 4);
|
DUK_FUNC(ui_text, 4);
|
||||||
|
DUK_FUNC(cursor_text,5);
|
||||||
DUK_FUNC(gui_img, 2);
|
DUK_FUNC(gui_img, 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DUK_FUNC(anim, 2);
|
DUK_FUNC(anim, 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,20 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
||||||
static int curchar = 0;
|
static int curchar = 0;
|
||||||
static float *buffdraw;
|
static float *buffdraw;
|
||||||
|
|
||||||
|
void draw_char_box(struct Character c, float cursor[2], float scale, float color[3])
|
||||||
|
{
|
||||||
|
int x, y, w, h;
|
||||||
|
|
||||||
|
x = cursor[0];
|
||||||
|
y = cursor[1];
|
||||||
|
w = 8*scale;
|
||||||
|
h = 14;
|
||||||
|
x += w/2.f;
|
||||||
|
y += h/2.f;
|
||||||
|
|
||||||
|
draw_rect(x,y,w,h,color);
|
||||||
|
}
|
||||||
|
|
||||||
void fill_charverts(float *verts, float cursor[2], float scale, struct Character c, float *offset)
|
void fill_charverts(float *verts, float cursor[2], float scale, struct Character c, float *offset)
|
||||||
{
|
{
|
||||||
float w = c.Size[0] * scale;
|
float w = c.Size[0] * scale;
|
||||||
|
@ -182,6 +196,8 @@ void fill_charverts(float *verts, float cursor[2], float scale, struct Character
|
||||||
memcpy(verts, v, sizeof(float)*16);
|
memcpy(verts, v, sizeof(float)*16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int drawcaret = 0;
|
||||||
|
|
||||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3])
|
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3])
|
||||||
{
|
{
|
||||||
float shadowcolor[3] = {0.f, 0.f, 0.f};
|
float shadowcolor[3] = {0.f, 0.f, 0.f};
|
||||||
|
@ -191,11 +207,24 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
||||||
float offset[2] = {-1, 1};
|
float offset[2] = {-1, 1};
|
||||||
|
|
||||||
fill_charverts(verts, cursor, scale, c, offset);
|
fill_charverts(verts, cursor, scale, c, offset);
|
||||||
|
curchar++;
|
||||||
|
|
||||||
/* Check if the vertex is off screen */
|
/* Check if the vertex is off screen */
|
||||||
if (verts[5] < 0 || verts[10] < 0 || verts[0] > window_i(0)->width || verts[1] > window_i(0)->height)
|
if (verts[5] < 0 || verts[10] < 0 || verts[0] > window_i(0)->width || verts[1] > window_i(0)->height)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (drawcaret == curchar) {
|
||||||
|
draw_char_box(c, cursor, scale, color);
|
||||||
|
shader_use(shader);
|
||||||
|
shader_setvec3(shader, "textColor", color);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, font->texID);
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
shader_setvec3(shader, "textColor", shadowcolor);
|
shader_setvec3(shader, "textColor", shadowcolor);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
@ -224,7 +253,7 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
curchar++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_settype(struct sFont *mfont)
|
void text_settype(struct sFont *mfont)
|
||||||
|
@ -232,41 +261,52 @@ void text_settype(struct sFont *mfont)
|
||||||
font = mfont;
|
font = mfont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw)
|
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw, int caret)
|
||||||
{
|
{
|
||||||
shader_use(shader);
|
|
||||||
shader_setvec3(shader, "textColor", color);
|
|
||||||
|
|
||||||
int len = strlen(text);
|
int len = strlen(text);
|
||||||
|
drawcaret = caret;
|
||||||
|
|
||||||
mfloat_t cursor[2] = { 0.f };
|
mfloat_t cursor[2] = { 0.f };
|
||||||
cursor[0] = pos[0];
|
cursor[0] = pos[0];
|
||||||
cursor[1] = pos[1];
|
cursor[1] = pos[1];
|
||||||
|
shader_use(shader);
|
||||||
|
shader_setvec3(shader, "textColor", color);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, font->texID);
|
glBindTexture(GL_TEXTURE_2D, font->texID);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, len*16*sizeof(float)*2, NULL, GL_STREAM_DRAW); /* x2 on the size for the outline pass */
|
glBufferData(GL_ARRAY_BUFFER, len*16*sizeof(float)*2, NULL, GL_STREAM_DRAW); /* x2 on the size for the outline pass */
|
||||||
|
|
||||||
const unsigned char *line, *wordstart;
|
const unsigned char *line, *wordstart, *drawstart;
|
||||||
line = (unsigned char*)text;
|
line = drawstart = (unsigned char*)text;
|
||||||
|
|
||||||
curchar = 0;
|
curchar = 0;
|
||||||
|
|
||||||
|
float *usecolor = color;
|
||||||
|
float caretcolor[3] = {0.4,0.98,0.75};
|
||||||
|
|
||||||
while (*line != '\0') {
|
while (*line != '\0') {
|
||||||
|
|
||||||
switch (*line) {
|
switch (*line) {
|
||||||
case '\n':
|
case '\n':
|
||||||
|
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
|
||||||
cursor[1] -= scale * font->height;
|
cursor[1] -= scale * font->height;
|
||||||
|
cursor[0] = pos[0];
|
||||||
line++;
|
line++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
sdrawCharacter(font->Characters[*line], cursor, scale, shader, color);
|
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
|
||||||
cursor[0] += font->Characters[*line].Advance * scale;
|
cursor[0] += font->Characters[*line].Advance * scale;
|
||||||
line++;
|
line++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
|
||||||
|
cursor[0] += font->Characters[*line].Advance * scale;
|
||||||
|
line++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
wordstart = line;
|
wordstart = line;
|
||||||
|
@ -283,7 +323,7 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
||||||
}
|
}
|
||||||
|
|
||||||
while (wordstart < line) {
|
while (wordstart < line) {
|
||||||
sdrawCharacter(font->Characters[*wordstart], cursor, scale, shader, color);
|
sdrawCharacter(font->Characters[*wordstart], cursor, scale, shader, usecolor);
|
||||||
cursor[0] += font->Characters[*wordstart].Advance * scale;
|
cursor[0] += font->Characters[*wordstart].Advance * scale;
|
||||||
wordstart++;
|
wordstart++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct Character {
|
||||||
mfloat_t Bearing[2]; // Offset from baseline to left/top of glyph
|
mfloat_t Bearing[2]; // Offset from baseline to left/top of glyph
|
||||||
unsigned int Advance; // Horizontal offset to advance to next glyph
|
unsigned int Advance; // Horizontal offset to advance to next glyph
|
||||||
struct glrect rect;
|
struct glrect rect;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sFont {
|
struct sFont {
|
||||||
|
@ -27,7 +28,7 @@ void font_frame(struct window *w);
|
||||||
struct sFont *MakeFont(const char *fontfile, int height);
|
struct sFont *MakeFont(const char *fontfile, int height);
|
||||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3]);
|
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3]);
|
||||||
void text_settype(struct sFont *font);
|
void text_settype(struct sFont *font);
|
||||||
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw);
|
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw,int caret);
|
||||||
|
|
||||||
unsigned char *slurp_file(const char *filename);
|
unsigned char *slurp_file(const char *filename);
|
||||||
char *slurp_text(const char *filename);
|
char *slurp_text(const char *filename);
|
||||||
|
|
|
@ -95,11 +95,13 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
|
||||||
{
|
{
|
||||||
cpShapeSetFriction(shape, go->f);
|
cpShapeSetFriction(shape, go->f);
|
||||||
cpShapeSetElasticity(shape, go->e);
|
cpShapeSetElasticity(shape, go->e);
|
||||||
// cpShapeSetSensor(shape, go->sensor);
|
|
||||||
cpShapeSetCollisionType(shape, go2id(go));
|
cpShapeSetCollisionType(shape, go2id(go));
|
||||||
|
|
||||||
|
|
||||||
// cpShapeSetFilter(shape, go->filter);
|
cpShapeFilter filter;
|
||||||
|
filter.group = go2id(go);
|
||||||
|
filter.categories = 1<<go->layer;
|
||||||
|
filter.mask = category_masks[go->layer];
|
||||||
|
cpShapeSetFilter(shape, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go)
|
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go)
|
||||||
|
@ -170,10 +172,8 @@ int MakeGameobject()
|
||||||
*id2go(retid) = go;
|
*id2go(retid) = go;
|
||||||
}
|
}
|
||||||
|
|
||||||
go.filter.group = retid;
|
|
||||||
go.filter.mask = CP_ALL_CATEGORIES;
|
|
||||||
go.filter.categories = CP_ALL_CATEGORIES;
|
|
||||||
cpBodySetUserData(go.body, (int)retid);
|
cpBodySetUserData(go.body, (int)retid);
|
||||||
|
phys2d_setup_handlers(retid);
|
||||||
return retid;
|
return retid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,26 +205,21 @@ void gameobject_delete(int id)
|
||||||
id2go(id)->next = first;
|
id2go(id)->next = first;
|
||||||
first = id;
|
first = id;
|
||||||
|
|
||||||
if (cpSpaceIsLocked(space)) {
|
if (cpSpaceIsLocked(space))
|
||||||
YughInfo("Space is simulating; adding %d to queue ...", id);
|
|
||||||
arrpush(go_toclean, id);
|
arrpush(go_toclean, id);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
gameobject_clean(id);
|
gameobject_clean(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gameobjects_cleanup() {
|
void gameobjects_cleanup() {
|
||||||
for (int i = 0; i < arrlen(go_toclean); i++) {
|
for (int i = 0; i < arrlen(go_toclean); i++)
|
||||||
YughInfo("Cleaning object %d", go_toclean[i]);
|
|
||||||
gameobject_clean(go_toclean[i]);
|
gameobject_clean(go_toclean[i]);
|
||||||
}
|
|
||||||
|
|
||||||
arrsetlen(go_toclean, 0);
|
arrsetlen(go_toclean, 0);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int clean = first;
|
int clean = first;
|
||||||
YughInfo("Initiating a clean");
|
|
||||||
|
|
||||||
while (clean >= 0 && id2go(clean)->body) {
|
while (clean >= 0 && id2go(clean)->body) {
|
||||||
gameobject_clean(clean);
|
gameobject_clean(clean);
|
||||||
|
|
|
@ -22,6 +22,7 @@ struct gameobject {
|
||||||
int flipx; /* 1 or -1 */
|
int flipx; /* 1 or -1 */
|
||||||
int flipy;
|
int flipy;
|
||||||
int sensor;
|
int sensor;
|
||||||
|
unsigned int layer;
|
||||||
cpShapeFilter filter;
|
cpShapeFilter filter;
|
||||||
cpBody *body; /* NULL if this object is dead */
|
cpBody *body; /* NULL if this object is dead */
|
||||||
int id;
|
int id;
|
||||||
|
|
|
@ -128,12 +128,24 @@ void char_cb(GLFWwindow *w, unsigned int codepoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLFWcharfun nukechar;
|
||||||
|
|
||||||
void input_init()
|
void input_init()
|
||||||
{
|
{
|
||||||
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
|
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
|
||||||
glfwSetScrollCallback(mainwin->window, scroll_cb);
|
glfwSetScrollCallback(mainwin->window, scroll_cb);
|
||||||
glfwSetMouseButtonCallback(mainwin->window, mb_cb);
|
glfwSetMouseButtonCallback(mainwin->window, mb_cb);
|
||||||
glfwSetCharCallback(mainwin->window, char_cb);
|
nukechar = glfwSetCharCallback(mainwin->window, char_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
void input_to_nuke()
|
||||||
|
{
|
||||||
|
glfwSetCharCallback(mainwin->window, nukechar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void input_to_game()
|
||||||
|
{
|
||||||
|
glfwSetCharCallback(mainwin->window, char_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void call_input_signal(char *signal) {
|
void call_input_signal(char *signal) {
|
||||||
|
@ -309,7 +321,6 @@ void input_poll(double wait)
|
||||||
|
|
||||||
glfwWaitEventsTimeout(wait);
|
glfwWaitEventsTimeout(wait);
|
||||||
|
|
||||||
//editor_input(&e);
|
|
||||||
for (int i = 0; i < arrlen(downkeys); i++)
|
for (int i = 0; i < arrlen(downkeys); i++)
|
||||||
call_input_down(&downkeys[i]);
|
call_input_down(&downkeys[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,7 @@ struct inputaction
|
||||||
void set_pawn(void *pawn);
|
void set_pawn(void *pawn);
|
||||||
void remove_pawn(void *pawn);
|
void remove_pawn(void *pawn);
|
||||||
|
|
||||||
|
void input_to_nuke();
|
||||||
|
void input_to_game();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,7 +31,6 @@ void nuke_init(struct window *win) {
|
||||||
|
|
||||||
ctx = nk_glfw3_init(&nkglfw, win->window, NK_GLFW3_INSTALL_CALLBACKS);
|
ctx = nk_glfw3_init(&nkglfw, win->window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||||
|
|
||||||
|
|
||||||
struct nk_font_atlas *atlas;
|
struct nk_font_atlas *atlas;
|
||||||
nk_glfw3_font_stash_begin(&nkglfw, &atlas);
|
nk_glfw3_font_stash_begin(&nkglfw, &atlas);
|
||||||
struct nk_font *noto = nk_font_atlas_add_from_file(atlas, "fonts/teenytinypixels.tff", 14, 0);
|
struct nk_font *noto = nk_font_atlas_add_from_file(atlas, "fonts/teenytinypixels.tff", 14, 0);
|
||||||
|
@ -66,6 +65,11 @@ struct nk_rect nuke_win_get_bounds() {
|
||||||
return nk_window_get_bounds(ctx);
|
return nk_window_get_bounds(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nuke_row(int height)
|
||||||
|
{
|
||||||
|
nk_layout_row_dynamic(ctx, height, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void nuke_property_float3(const char *label, float min, float *val, float max, float step, float dragstep) {
|
void nuke_property_float3(const char *label, float min, float *val, float max, float step, float dragstep) {
|
||||||
nk_layout_row_dynamic(ctx, 25, 1);
|
nk_layout_row_dynamic(ctx, 25, 1);
|
||||||
nk_label(ctx, label, NK_TEXT_LEFT);
|
nk_label(ctx, label, NK_TEXT_LEFT);
|
||||||
|
|
|
@ -23,6 +23,7 @@ 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_radio_btn(const char *lbl, int *val, int cmp);
|
||||||
void nuke_checkbox(const char *lbl, int *val);
|
void nuke_checkbox(const char *lbl, int *val);
|
||||||
void nuke_nel(int cols);
|
void nuke_nel(int cols);
|
||||||
|
void nuke_row(int height);
|
||||||
void nuke_label(const char *s);
|
void nuke_label(const char *s);
|
||||||
void nuke_prop_float(const char *label, float min, float *val, float max, float step, float dragstep);
|
void nuke_prop_float(const char *label, float min, float *val, float max, float step, float dragstep);
|
||||||
void nuke_edit_str(char *str);
|
void nuke_edit_str(char *str);
|
||||||
|
|
|
@ -186,7 +186,7 @@ void openglRender(struct window *window)
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
//// DEBUG
|
//// DEBUG
|
||||||
if (debugDrawPhysics)
|
if (debugDrawPhysics)
|
||||||
gameobject_draw_debugs();
|
gameobject_draw_debugs();
|
||||||
|
|
||||||
////// TEXT && GUI
|
////// TEXT && GUI
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
||||||
|
|
|
@ -139,17 +139,15 @@ void print_devices()
|
||||||
|
|
||||||
void sound_init()
|
void sound_init()
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
mixer_init();
|
mixer_init();
|
||||||
PaError err = Pa_Initialize();
|
PaError err = Pa_Initialize();
|
||||||
check_pa_err(err);
|
check_pa_err(err);
|
||||||
|
|
||||||
err = Pa_OpenDefaultStream(&stream_def, 0, CHANNELS, paInt16, SAMPLERATE, BUF_FRAMES, patestCallback, NULL);
|
err = Pa_OpenDefaultStream(&stream_def, 0, CHANNELS, paInt16, SAMPLERATE, BUF_FRAMES, patestCallback, NULL);
|
||||||
check_pa_err(err);
|
check_pa_err(err);
|
||||||
|
|
||||||
err = Pa_StartStream(stream_def);
|
err = Pa_StartStream(stream_def);
|
||||||
check_pa_err(err);
|
check_pa_err(err);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wav *make_sound(const char *wav)
|
struct wav *make_sound(const char *wav)
|
||||||
|
@ -160,10 +158,9 @@ struct wav *make_sound(const char *wav)
|
||||||
struct wav mwav;
|
struct wav mwav;
|
||||||
mwav.data = drwav_open_file_and_read_pcm_frames_s16(wav, &mwav.ch, &mwav.samplerate, &mwav.frames, NULL);
|
mwav.data = drwav_open_file_and_read_pcm_frames_s16(wav, &mwav.ch, &mwav.samplerate, &mwav.frames, NULL);
|
||||||
|
|
||||||
|
|
||||||
if (mwav.samplerate != SAMPLERATE) {
|
if (mwav.samplerate != SAMPLERATE) {
|
||||||
YughInfo("Changing samplerate of %s from %d to %d.", wav, mwav.samplerate, SAMPLERATE);
|
YughInfo("Changing samplerate of %s from %d to %d.", wav, mwav.samplerate, SAMPLERATE);
|
||||||
mwav = change_samplerate(mwav, SAMPLERATE);
|
// mwav = change_samplerate(mwav, SAMPLERATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mwav.ch != CHANNELS) {
|
if (mwav.ch != CHANNELS) {
|
||||||
|
@ -205,10 +202,12 @@ void kill_oneshot(struct sound *s)
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_oneshot(struct wav *wav) {
|
void play_oneshot(struct wav *wav) {
|
||||||
struct sound *new = malloc(sizeof(*new));
|
struct sound *new = malloc(sizeof(*new));
|
||||||
new->data = wav;
|
new->data = wav;
|
||||||
new->bus = first_free_bus(dsp_filter(new, sound_fillbuf));
|
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->playing=1;
|
||||||
new->loop=0;
|
new->loop=0;
|
||||||
new->frame = 0;
|
new->frame = 0;
|
||||||
|
@ -224,7 +223,6 @@ struct sound *play_sound(struct wav *wav)
|
||||||
new->playing = 1;
|
new->playing = 1;
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sound_playing(const struct sound *s)
|
int sound_playing(const struct sound *s)
|
||||||
|
@ -292,7 +290,6 @@ void sound_fillbuf(struct sound *s, short *buf, int n)
|
||||||
short *in = s->data->data;
|
short *in = s->data->data;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
for (int j = 0; j < CHANNELS; j++) buf[i*CHANNELS+j] = in[s->frame+j] * gainmult;
|
for (int j = 0; j < CHANNELS; j++) buf[i*CHANNELS+j] = in[s->frame+j] * gainmult;
|
||||||
|
|
||||||
s->frame++;
|
s->frame++;
|
||||||
if (s->frame == s->data->frames) {
|
if (s->frame == s->data->frames) {
|
||||||
|
|
||||||
|
@ -309,8 +306,6 @@ void mp3_fillbuf(struct sound *s, short *buf, int n)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void soundstream_fillbuf(struct soundstream *s, short *buf, int n)
|
void soundstream_fillbuf(struct soundstream *s, short *buf, int n)
|
||||||
{
|
{
|
||||||
int max = s->buf->write - s->buf->read;
|
int max = s->buf->write - s->buf->read;
|
||||||
|
|
|
@ -37,8 +37,17 @@ void mixer_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bus *first_free_bus(struct dsp_filter in) {
|
struct bus *first_free_bus(struct dsp_filter in) {
|
||||||
if (!initted) return NULL;
|
|
||||||
assert(initted);
|
assert(initted);
|
||||||
|
|
||||||
|
for (int i = 0; i < 255; i++)
|
||||||
|
if (!bus[i].on) {
|
||||||
|
bus[i].on = 1;
|
||||||
|
bus[i].in = in;
|
||||||
|
YughInfo("Returning bus %d", i);
|
||||||
|
return &bus[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (first == -1) return NULL;
|
if (first == -1) return NULL;
|
||||||
int ret = first;
|
int ret = first;
|
||||||
|
@ -58,6 +67,10 @@ struct bus *first_free_bus(struct dsp_filter in) {
|
||||||
|
|
||||||
void bus_free(struct bus *b)
|
void bus_free(struct bus *b)
|
||||||
{
|
{
|
||||||
|
YughInfo("Freeing bus %d", b->id);
|
||||||
|
b->on = 0;
|
||||||
|
return;
|
||||||
|
|
||||||
if (first_on == b->id) first_on = b->next;
|
if (first_on == b->id) first_on = b->next;
|
||||||
if (b->next != -1) bus[b->next].prev = b->prev;
|
if (b->next != -1) bus[b->next].prev = b->prev;
|
||||||
if (b->prev != -1) bus[b->prev].next = b->next;
|
if (b->prev != -1) bus[b->prev].next = b->next;
|
||||||
|
@ -69,9 +82,18 @@ void bus_free(struct bus *b)
|
||||||
|
|
||||||
void bus_fill_buffers(short *master, int n) {
|
void bus_fill_buffers(short *master, int n) {
|
||||||
int curbus = first_on;
|
int curbus = first_on;
|
||||||
if (curbus == -1) return;
|
// if (curbus == -1) return;
|
||||||
memset(master, 0, BUF_FRAMES*CHANNELS*sizeof(short));
|
memset(master, 0, BUF_FRAMES*CHANNELS*sizeof(short));
|
||||||
|
|
||||||
|
for (int i = 0; i < 255; i++) {
|
||||||
|
if (!bus[i].on) continue;
|
||||||
|
dsp_run(bus[i].in, bus[i].buf, BUF_FRAMES);
|
||||||
|
for (int j = 0; j < BUF_FRAMES*CHANNELS; j++)
|
||||||
|
master[j] += bus[i].buf[j] * master_volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
while (curbus != -1) {
|
while (curbus != -1) {
|
||||||
int nextbus = bus[curbus].next; /* Save this in case busses get changed during fill */
|
int nextbus = bus[curbus].next; /* Save this in case busses get changed during fill */
|
||||||
dsp_run(bus[curbus].in, bus[curbus].buf, BUF_FRAMES);
|
dsp_run(bus[curbus].in, bus[curbus].buf, BUF_FRAMES);
|
||||||
|
|
|
@ -47,6 +47,7 @@ double updateMS = 1/60.f;
|
||||||
static int ed = 1;
|
static int ed = 1;
|
||||||
static int sim_play = 0;
|
static int sim_play = 0;
|
||||||
static double lastTick;
|
static double lastTick;
|
||||||
|
static int phys_step = 0;
|
||||||
|
|
||||||
static float timescale = 1.f;
|
static float timescale = 1.f;
|
||||||
|
|
||||||
|
@ -174,15 +175,10 @@ int main(int argc, char **args) {
|
||||||
|
|
||||||
window_set_icon("icon.png");
|
window_set_icon("icon.png");
|
||||||
|
|
||||||
if (ed) {
|
script_dofile("game.js");
|
||||||
editor_init(MakeSDLWindow("Editor", 600, 600, 0));
|
|
||||||
} else {
|
|
||||||
script_dofile("game.js");
|
|
||||||
}
|
|
||||||
|
|
||||||
input_init();
|
input_init();
|
||||||
openglInit();
|
openglInit();
|
||||||
sim_stop();
|
|
||||||
while (!want_quit()) {
|
while (!want_quit()) {
|
||||||
double elapsed = glfwGetTime() - lastTick;
|
double elapsed = glfwGetTime() - lastTick;
|
||||||
deltaT = elapsed;
|
deltaT = elapsed;
|
||||||
|
@ -199,12 +195,14 @@ int main(int argc, char **args) {
|
||||||
timer_update(elapsed);
|
timer_update(elapsed);
|
||||||
physlag += elapsed;
|
physlag += elapsed;
|
||||||
call_updates(elapsed * timescale);
|
call_updates(elapsed * timescale);
|
||||||
|
|
||||||
while (physlag >= physMS) {
|
while (physlag >= physMS) {
|
||||||
|
phys_step = 1;
|
||||||
physlag -= physMS;
|
physlag -= physMS;
|
||||||
phys2d_update(physMS * timescale);
|
phys2d_update(physMS * timescale);
|
||||||
call_physics(physMS * timescale);
|
call_physics(physMS * timescale);
|
||||||
|
fire_hits();
|
||||||
if (sim_play == SIM_STEP) sim_pause();
|
if (sim_play == SIM_STEP) sim_pause();
|
||||||
|
phys_step = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +214,6 @@ int main(int argc, char **args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
gameobjects_cleanup();
|
gameobjects_cleanup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -249,6 +246,8 @@ void sim_stop() {
|
||||||
sim_play = SIM_STOP;
|
sim_play = SIM_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int phys_stepping() { return phys_step; }
|
||||||
|
|
||||||
void sim_step() {
|
void sim_step() {
|
||||||
if (sim_paused()) {
|
if (sim_paused()) {
|
||||||
YughInfo("Step");
|
YughInfo("Step");
|
||||||
|
|
|
@ -7,9 +7,10 @@ void sim_start();
|
||||||
void sim_pause();
|
void sim_pause();
|
||||||
void sim_stop();
|
void sim_stop();
|
||||||
void sim_step();
|
void sim_step();
|
||||||
|
int phys_stepping();
|
||||||
void set_timescale(float val);
|
void set_timescale(float val);
|
||||||
|
|
||||||
int frame_fps();
|
int frame_fps();
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,11 +4,12 @@ out vec4 color;
|
||||||
|
|
||||||
uniform sampler2D text;
|
uniform sampler2D text;
|
||||||
uniform vec3 textColor;
|
uniform vec3 textColor;
|
||||||
|
uniform bool invert;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
|
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
|
||||||
color = vec4(textColor, 1.0) * sampled;
|
color = vec4(textColor, 1.0) * sampled;
|
||||||
if (color.a <= 0.1f)
|
if (color.a <= 0.1f)
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue