From: Seth Long Date: Mon, 4 Nov 2024 22:12:34 +0000 (-0800) Subject: HUD visible switch, some instrumentation X-Git-Url: https://isoptera.lcsc.edu/gitweb/?a=commitdiff_plain;h=9b2f3c1707e5332d0361cb9c1aca63c7c6058914;p=example_engine%2F.git HUD visible switch, some instrumentation --- diff --git a/game.h b/game.h index bf4158c..e847636 100644 --- a/game.h +++ b/game.h @@ -38,6 +38,7 @@ class gameobject { public: std::mutex data_mutex; unsigned int mvp_uniform, v_attrib, t_attrib, program, vbuf, cbuf, ebuf, tex, models_buffer; + bool visible = true; bool collision_check = false; // Consider separating out player from projectile collision here std::vector locations; glm::vec3 size; // What about non-square objects? diff --git a/hud_fragment_shader.glsl b/hud_fragment_shader.glsl index 29ab238..e2c93a7 100644 --- a/hud_fragment_shader.glsl +++ b/hud_fragment_shader.glsl @@ -6,5 +6,6 @@ uniform sampler2D tex; void main(void) { outcolor = texture(tex, vec2(frag_texcoord.x, -frag_texcoord.y)); -// outcolor = vec4(frag_texcoord.xy, 0, 1); + if(outcolor.r < 0.1) + discard; } diff --git a/main.cpp b/main.cpp index dbf9d15..81e8ad8 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ float width = 2550; /* Global section */ int time_resolution = 10; int framecount = 0; +int loopcount = 0; std::vector objects; projectile ice_balls; @@ -87,6 +88,8 @@ void mouse_click_callback(GLFWwindow* window, int button, int action, int mods){ } void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){ + if(GLFW_KEY_F3 == key && 1 == action) + main_hud.visible = !main_hud.visible; if(GLFW_KEY_W == key && 1 == action){ player_key_status.forward = 1; } @@ -204,7 +207,7 @@ void object_movement(){ int cpu_time = std::chrono::duration_cast(end_time - start_time).count(); last_call = start_time; int sleep_time = 1000 - cpu_time; - // printf("Loop time: %d Sleep time: %d CPU time: %d\n", loop_time, sleep_time, cpu_time); + loopcount++; if(sleep_time > 100 ) std::this_thread::sleep_for(std::chrono::microseconds(sleep_time)); } @@ -402,6 +405,16 @@ int main(int argc, char** argv) { std::thread object_movement_thread(object_movement); std::thread animation_thread(animation); std::thread collision_detection_thread(collision_detection); + std::thread display_fps([](){ + while(!shutdown_engine){ + double loop_time = 1000.0 / loopcount; + main_hud.lprintf(1, "FPS: %4d Move: %lf", framecount, loop_time); + framecount = 0; + loopcount = 0; + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + }); + glEnable(GL_DEPTH_TEST); while (!glfwWindowShouldClose(window)) { @@ -425,7 +438,8 @@ int main(int argc, char** argv) { glm::mat4 vp = projection * view; for(gameobject* o : objects) - o->draw(vp); + if(o->visible) + o->draw(vp); // grand_mutex.unlock(); glfwSwapBuffers(window);