From d4b8c18708716d925621178bede16f9450560ae9 Mon Sep 17 00:00:00 2001 From: onezplpl Date: Sun, 14 Jul 2024 12:01:38 -0400 Subject: [PATCH] port back oldpos logic --- main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index bb53389..1787676 100644 --- a/main.c +++ b/main.c @@ -175,6 +175,7 @@ int main(void) { while (!glfwWindowShouldClose(window)) { + vec3 oldPos = {pos[0], pos[1], pos[2]}; glfwGetFramebufferSize(window, &width, &height); const float ratio = width / (float)height; @@ -216,8 +217,12 @@ int main(void) { mat4x4_mul(mvp, mvp, m); glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat *)&mvp); + + int ax = (int)(oldPos[0] / CHUNK_LENGTH) - (int)(pos[0] / CHUNK_LENGTH); + int ay = (int)(oldPos[1] / CHUNK_LENGTH) - (int)(pos[1] / CHUNK_LENGTH); + int az = (int)(oldPos[2] / CHUNK_LENGTH) - (int)(pos[2] / CHUNK_LENGTH); - if (frames >= 8) { + if ((ax != 0 || ay != 0 || az != 0) && frames > 4.0) { struct args args; args.cube_count = &cube_count; @@ -229,6 +234,9 @@ int main(void) { args.vertex_buffer = vertex_buffer; args.is_render = &is_render; + if (thread_id != 0) + pthread_join(thread_id, NULL); + pthread_create(&(thread_id), NULL, render_chunks, (void *)&(args)); frames = 0; @@ -236,7 +244,7 @@ int main(void) { } frames = glfwGetTime(); - //printf("%f\n", frames); + //Sprintf("%f\n", frames); glfwSwapBuffers(window); glfwPollEvents();