Many fixes

This commit is contained in:
John Alanbrook 2023-03-10 19:13:48 +00:00
parent 0826197b91
commit 3018a1a188
20 changed files with 243 additions and 105 deletions

View file

@ -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 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)
{
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)
{
if (enabled)
cpShapeSetFilter(shape->shape, CP_SHAPE_FILTER_ALL);
cpShapeSetFilter(shape->data, CP_SHAPE_FILTER_ALL);
else
cpShapeSetFilter(shape->shape, CP_SHAPE_FILTER_NONE);
cpShapeSetFilter(shape->data, CP_SHAPE_FILTER_NONE);
}
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)
{
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_put_prop_literal(duk, obj, "hit");
/* vect2duk(cpArbiterGetSurfaceVelocity(arb));
duk_put_prop_literal(duk, obj, "velocity");
*/
duk_call_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);
}
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)
{
cpBody *body1;
cpBody *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 *go2 = id2go(g2);
struct phys2d_shape *pshape1 = cpShapeGetUserData(shape1);
struct phys2d_shape *pshape2 = cpShapeGetUserData(shape2);
cpVect norm1 = cpArbiterGetNormal(arb);
cpVect vel1 = cpArbiterGetSurfaceVelocity(arb);
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);
if (go->cbs.begin.obj)
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;
}
@ -673,14 +704,16 @@ void phys2d_rm_go_handlers(int go)
handler->separateFunc = NULL;
}
void phys2d_add_handler_type(int cmd, int go, struct callee c) {
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) {
switch (cmd) {
case 0:
handler->beginFunc = script_phys_cb_begin;
id2go(go)->cbs.begin = c;
break;

View file

@ -112,10 +112,12 @@ struct phys_cbs {
};
struct shape_cb {
cpShape *shape;
struct phys2d_shape *shape;
struct phys_cbs cbs;
};
void fire_hits();
void phys2d_add_handler_type(int cmd, int go, struct callee c);
void register_collide(void *sym);
void phys2d_rm_go_handlers(int go);
@ -136,9 +138,12 @@ void color2float(struct color, float *fcolor);
struct color float2color(float *fcolor);
void shape_gui(struct phys2d_shape *shape);
void phys2d_setup_handlers(int go);
void phys2d_reindex_body(cpBody *body);
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);
#endif

View file

@ -255,24 +255,13 @@ void draw_grid(int width, int span)
void draw_point(int x, int y, float r, float *color)
{
shader_use(circleShader);
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);
draw_circle(x,y,r,r,color,1);
}
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};
draw_point(point.x, point.y, r, white);
float col[3] = {(float)color.r/255, (float)color.g/255, (float)color.b/255};
draw_point(point.x, point.y, r, col);
}
void draw_points(struct cpVect *points, int n, float size, float *color)

View file

@ -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_box(struct cpVect c, struct cpVect wh, struct color 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);

View file

@ -3,7 +3,7 @@
#include <stdio.h>
#define ERROR_BUFFER 2048
#define ERROR_BUFFER 1024*1024
#define LOG_INFO 0
#define LOG_WARN 1

View file

@ -105,16 +105,13 @@ cpBitmask duk2bitmask(duk_context *duk, int p)
for (int i = 0; i < len; 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);
if (!val) continue;
if (val > 10) continue;
mask |= 1<<val;
mask |= 1<<i;
}
YughInfo(BYTE_TO_BINARY_PATTERN,BYTE_TO_BINARY(mask));
return mask;
}
@ -199,7 +196,7 @@ duk_ret_t duk_gui_text(duk_context *duk) {
float size = duk_to_number(duk, 2);
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;
}
@ -211,9 +208,21 @@ duk_ret_t duk_ui_text(duk_context *duk)
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};
renderText(s, &pos, size, col, 500);
renderText(s, &pos, size, col, 500,-1);
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) {
@ -308,6 +317,10 @@ duk_ret_t duk_nuke(duk_context *duk)
case 12:
nuke_tree_pop();
return 0;
case 13:
nuke_row(duk_to_int(duk,1));
break;
}
return 0;
@ -706,7 +719,7 @@ duk_ret_t duk_cmd(duk_context *duk) {
return 1;
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;
case 52:
@ -801,6 +814,26 @@ duk_ret_t duk_cmd(duk_context *duk) {
case 74:
duk_push_number(duk, cpSpaceGetDamping(space));
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;
@ -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)
{
struct shape_cb shapecb;
shapecb.shape = shape->shape;
shapecb.shape = shape;
shapecb.cbs.begin = c;
arrpush(id2go(go)->shape_cbs, shapecb);
}
@ -860,11 +893,12 @@ duk_ret_t duk_register_collide(duk_context *duk) {
switch(cmd) {
case 0:
phys2d_add_handler_type(cmd, go, c);
id2go(go)->cbs.begin = c;
break;
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:
@ -1045,6 +1079,10 @@ duk_ret_t duk_q_body(duk_context *duk) {
case 5:
duk_push_number(duk, cpBodyGetMass(go->body));
return 1;
case 6:
duk_push_number(duk, cpBodyGetMoment(go->body));
return 1;
}
return 0;
@ -1322,9 +1360,8 @@ void ffi_load()
DUK_FUNC(gui_text, DUK_VARARGS);
DUK_FUNC(ui_text, 4);
DUK_FUNC(cursor_text,5);
DUK_FUNC(gui_img, 2);
DUK_FUNC(anim, 2);
}

View file

@ -164,6 +164,20 @@ struct sFont *MakeFont(const char *fontfile, int height)
static int curchar = 0;
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)
{
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);
}
static int drawcaret = 0;
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};
@ -191,11 +207,24 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
float offset[2] = {-1, 1};
fill_charverts(verts, cursor, scale, c, offset);
curchar++;
/* 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)
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);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
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);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
curchar++;
}
void text_settype(struct sFont *mfont)
@ -232,42 +261,53 @@ void text_settype(struct sFont *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);
drawcaret = caret;
mfloat_t cursor[2] = { 0.f };
cursor[0] = pos[0];
cursor[1] = pos[1];
shader_use(shader);
shader_setvec3(shader, "textColor", color);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, font->texID);
glBindVertexArray(VAO);
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 */
const unsigned char *line, *wordstart;
line = (unsigned char*)text;
const unsigned char *line, *wordstart, *drawstart;
line = drawstart = (unsigned char*)text;
curchar = 0;
float *usecolor = color;
float caretcolor[3] = {0.4,0.98,0.75};
while (*line != '\0') {
switch (*line) {
case '\n':
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
cursor[1] -= scale * font->height;
cursor[0] = pos[0];
line++;
break;
case ' ':
sdrawCharacter(font->Characters[*line], cursor, scale, shader, color);
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
cursor[0] += font->Characters[*line].Advance * scale;
line++;
break;
case '\t':
sdrawCharacter(font->Characters[*line], cursor, scale, shader, usecolor);
cursor[0] += font->Characters[*line].Advance * scale;
line++;
break;
default:
wordstart = line;
int wordWidth = 0;
@ -283,7 +323,7 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
}
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;
wordstart++;
}

View file

@ -13,6 +13,7 @@ struct Character {
mfloat_t Bearing[2]; // Offset from baseline to left/top of glyph
unsigned int Advance; // Horizontal offset to advance to next glyph
struct glrect rect;
};
struct sFont {
@ -27,7 +28,7 @@ void font_frame(struct window *w);
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 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);
char *slurp_text(const char *filename);

View file

@ -95,11 +95,13 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
{
cpShapeSetFriction(shape, go->f);
cpShapeSetElasticity(shape, go->e);
// cpShapeSetSensor(shape, go->sensor);
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)
@ -170,10 +172,8 @@ int MakeGameobject()
*id2go(retid) = go;
}
go.filter.group = retid;
go.filter.mask = CP_ALL_CATEGORIES;
go.filter.categories = CP_ALL_CATEGORIES;
cpBodySetUserData(go.body, (int)retid);
phys2d_setup_handlers(retid);
return retid;
}
@ -205,26 +205,21 @@ void gameobject_delete(int id)
id2go(id)->next = first;
first = id;
if (cpSpaceIsLocked(space)) {
YughInfo("Space is simulating; adding %d to queue ...", id);
if (cpSpaceIsLocked(space))
arrpush(go_toclean, id);
}
else
gameobject_clean(id);
}
void gameobjects_cleanup() {
for (int i = 0; i < arrlen(go_toclean); i++) {
YughInfo("Cleaning object %d", go_toclean[i]);
for (int i = 0; i < arrlen(go_toclean); i++)
gameobject_clean(go_toclean[i]);
}
arrsetlen(go_toclean, 0);
return;
int clean = first;
YughInfo("Initiating a clean");
while (clean >= 0 && id2go(clean)->body) {
gameobject_clean(clean);

View file

@ -22,6 +22,7 @@ struct gameobject {
int flipx; /* 1 or -1 */
int flipy;
int sensor;
unsigned int layer;
cpShapeFilter filter;
cpBody *body; /* NULL if this object is dead */
int id;

View file

@ -128,11 +128,23 @@ void char_cb(GLFWwindow *w, unsigned int codepoint)
}
}
static GLFWcharfun nukechar;
void input_init()
{
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
glfwSetScrollCallback(mainwin->window, scroll_cb);
glfwSetMouseButtonCallback(mainwin->window, mb_cb);
nukechar = glfwSetCharCallback(mainwin->window, char_cb);
}
void input_to_nuke()
{
glfwSetCharCallback(mainwin->window, nukechar);
}
void input_to_game()
{
glfwSetCharCallback(mainwin->window, char_cb);
}
@ -309,7 +321,6 @@ void input_poll(double wait)
glfwWaitEventsTimeout(wait);
//editor_input(&e);
for (int i = 0; i < arrlen(downkeys); i++)
call_input_down(&downkeys[i]);
}

View file

@ -38,4 +38,7 @@ struct inputaction
void set_pawn(void *pawn);
void remove_pawn(void *pawn);
void input_to_nuke();
void input_to_game();
#endif

View file

@ -31,7 +31,6 @@ void nuke_init(struct window *win) {
ctx = nk_glfw3_init(&nkglfw, win->window, NK_GLFW3_INSTALL_CALLBACKS);
struct nk_font_atlas *atlas;
nk_glfw3_font_stash_begin(&nkglfw, &atlas);
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);
}
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) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, label, NK_TEXT_LEFT);

View file

@ -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_checkbox(const char *lbl, int *val);
void nuke_nel(int cols);
void nuke_row(int height);
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_edit_str(char *str);

View file

@ -139,7 +139,6 @@ void print_devices()
void sound_init()
{
return;
mixer_init();
PaError err = Pa_Initialize();
check_pa_err(err);
@ -149,7 +148,6 @@ void sound_init()
err = Pa_StartStream(stream_def);
check_pa_err(err);
}
struct wav *make_sound(const char *wav)
@ -160,10 +158,9 @@ struct wav *make_sound(const char *wav)
struct wav mwav;
mwav.data = drwav_open_file_and_read_pcm_frames_s16(wav, &mwav.ch, &mwav.samplerate, &mwav.frames, NULL);
if (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) {
@ -209,6 +206,8 @@ 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;
@ -224,7 +223,6 @@ struct sound *play_sound(struct wav *wav)
new->playing = 1;
return new;
}
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;
for (int i = 0; i < n; i++) {
for (int j = 0; j < CHANNELS; j++) buf[i*CHANNELS+j] = in[s->frame+j] * gainmult;
s->frame++;
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)
{
int max = s->buf->write - s->buf->read;

View file

@ -37,9 +37,18 @@ void mixer_init() {
}
struct bus *first_free_bus(struct dsp_filter in) {
if (!initted) return NULL;
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;
int ret = first;
first = bus[ret].next;
@ -58,6 +67,10 @@ 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;
if (first_on == b->id) first_on = b->next;
if (b->next != -1) bus[b->next].prev = b->prev;
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) {
int curbus = first_on;
if (curbus == -1) return;
// if (curbus == -1) return;
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) {
int nextbus = bus[curbus].next; /* Save this in case busses get changed during fill */
dsp_run(bus[curbus].in, bus[curbus].buf, BUF_FRAMES);

View file

@ -47,6 +47,7 @@ double updateMS = 1/60.f;
static int ed = 1;
static int sim_play = 0;
static double lastTick;
static int phys_step = 0;
static float timescale = 1.f;
@ -174,15 +175,10 @@ int main(int argc, char **args) {
window_set_icon("icon.png");
if (ed) {
editor_init(MakeSDLWindow("Editor", 600, 600, 0));
} else {
script_dofile("game.js");
}
input_init();
openglInit();
sim_stop();
while (!want_quit()) {
double elapsed = glfwGetTime() - lastTick;
deltaT = elapsed;
@ -199,12 +195,14 @@ int main(int argc, char **args) {
timer_update(elapsed);
physlag += elapsed;
call_updates(elapsed * timescale);
while (physlag >= physMS) {
phys_step = 1;
physlag -= physMS;
phys2d_update(physMS * timescale);
call_physics(physMS * timescale);
fire_hits();
if (sim_play == SIM_STEP) sim_pause();
phys_step = 0;
}
}
@ -216,7 +214,6 @@ int main(int argc, char **args) {
}
gameobjects_cleanup();
}
return 0;
@ -249,6 +246,8 @@ void sim_stop() {
sim_play = SIM_STOP;
}
int phys_stepping() { return phys_step; }
void sim_step() {
if (sim_paused()) {
YughInfo("Step");

View file

@ -7,6 +7,7 @@ void sim_start();
void sim_pause();
void sim_stop();
void sim_step();
int phys_stepping();
void set_timescale(float val);
int frame_fps();

View file

@ -4,6 +4,7 @@ out vec4 color;
uniform sampler2D text;
uniform vec3 textColor;
uniform bool invert;
void main()
{