]> isoptera.lcsc.edu Git - example_engine/.git/commitdiff
HUD visible switch, some instrumentation
authorSeth Long <sslong@lcsc.edu>
Mon, 4 Nov 2024 22:12:34 +0000 (14:12 -0800)
committerSeth Long <sslong@lcsc.edu>
Mon, 4 Nov 2024 22:12:34 +0000 (14:12 -0800)
game.h
hud_fragment_shader.glsl
main.cpp

diff --git a/game.h b/game.h
index bf4158ce77386c111ef12a203ba28aeb41004c20..e8476362359afc40e43b7833960841aa9aab3fb4 100644 (file)
--- 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<glm::vec3> locations;
                glm::vec3 size; // What about non-square objects?
index 29ab2380a740a5587b77cb6842bfa31b4ac01554..e2c93a7654965e2fe886c679bcec402df84ac144 100644 (file)
@@ -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;
 }
index dbf9d152a543d89fc6fe51a80cd8f22c4b118d6e..81e8ad8c3fa68e03bbdc1edb0f135c8f9b7a1a67 100644 (file)
--- 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<gameobject*> 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<std::chrono::microseconds>(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);