From 229e86a56a19cb609000b62dfbfa8bea6f417e4f Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sat, 4 Feb 2023 04:18:19 +0000 Subject: [PATCH] lll --- source/engine/ffi.c | 3 +-- source/engine/font.c | 13 ++++++------- source/engine/gameobject.c | 2 -- source/engine/yugine.c | 35 ++++++++++++++++++++++++++++++----- source/shaders/textfrag.glsl | 6 +++--- source/shaders/textvert.glsl | 2 +- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/source/engine/ffi.c b/source/engine/ffi.c index 7e0acb4..cdc8c63 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -153,11 +153,10 @@ void duk_dump_stack(duk_context *duk) duk_ret_t duk_gui_text(duk_context *duk) { const char *s = duk_to_string(duk, 0); cpVect pos = duk2vec2(duk, 1); - float fpos[2] = {pos.x, pos.y}; float size = duk_to_number(duk, 2); const float white[3] = {1.f, 1.f, 1.f}; - renderText(s, fpos, size, white, 1800); + renderText(s, &pos, size, white, 500); return 0; } diff --git a/source/engine/font.c b/source/engine/font.c index d670c25..a3640d7 100644 --- a/source/engine/font.c +++ b/source/engine/font.c @@ -132,7 +132,6 @@ struct sFont *MakeFont(const char *fontfile, int height) glBindTexture(GL_TEXTURE_2D, newfont->texID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, packsize, packsize, 0, GL_RED, GL_UNSIGNED_BYTE, bitmap); - //glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -179,13 +178,15 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct xpos, ypos + h, c.rect.s0, c.rect.t0, xpos + w, ypos + h, c.rect.s1, c.rect.t0 }; - + /* 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; - glBufferSubData(GL_ARRAY_BUFFER, curchar*sizeof(verts), sizeof(verts), verts); - +// glBufferSubData(GL_ARRAY_BUFFER, curchar*sizeof(verts), sizeof(verts), verts); + + glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); curchar++; } @@ -211,8 +212,6 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3 glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, len*16*sizeof(float), NULL, GL_STREAM_DRAW); - - const unsigned char *line, *wordstart; line = (unsigned char*)text; @@ -254,5 +253,5 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3 } } - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4*curchar); +// glDrawArrays(GL_TRIANGLE_STRIP, 0, 4*2); } diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 4d460ab..1c481a3 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -32,8 +32,6 @@ struct gameobject *id2go(int id) { return &gameobjects[id]; } - - int pos2gameobject(cpVect pos) { cpShape *hit = phys2d_query_pos(pos); diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 723c587..232ac7f 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -187,7 +187,8 @@ int main(int argc, char **args) { window_all_handle_events(); framems[framei++] = elapsed; - if (framei == FPSBUF) framei = 0; + + if (framei == FPSBUF) framei = 0; if (sim_play) { timer_update(elapsed); @@ -202,7 +203,31 @@ int main(int argc, char **args) { } } + renderlag += elapsed; + + if (renderlag >= renderMS) { + renderlag -= renderMS; + window_renderall(); + } + + gameobjects_cleanup(); + + } + + renderlag += elapsed; + + if (renderlag >= renderMS) { + renderlag -= renderMS; + window_renderall(); + } + + gameobjects_cleanup(); + + } + + renderlag += elapsed; + if (renderlag >= renderMS) { renderlag -= renderMS; window_renderall(); @@ -218,11 +243,11 @@ int main(int argc, char **args) { int frame_fps() { double fpsms = 0; - for (int i = 0; i < FPSBUF; i++) { - fpsms += framems[i]; - } + for (int i = 0; i < FPSBUF; i++) { + fpsms += framems[i]; + } - return floor((float)FPSBUF / fpsms); + return FPSBUF / fpsms; } int sim_playing() { return sim_play; } diff --git a/source/shaders/textfrag.glsl b/source/shaders/textfrag.glsl index 3c93e00..c7e35c0 100644 --- a/source/shaders/textfrag.glsl +++ b/source/shaders/textfrag.glsl @@ -10,6 +10,6 @@ void main() //vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r); //color = vec4(textColor, 1.0) * sampled; color = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r); - //if (color.a <= 0.1f) - //discard; -} \ No newline at end of file +/* if (color.a <= 0.1f) + discard;*/ +} diff --git a/source/shaders/textvert.glsl b/source/shaders/textvert.glsl index 5593ff5..e32ffff 100644 --- a/source/shaders/textvert.glsl +++ b/source/shaders/textvert.glsl @@ -11,4 +11,4 @@ void main() { gl_Position = projection * vec4(vertex.xy, 0.0, 1.0); TexCoords = vertex.zw; -} \ No newline at end of file +}