diff --git a/include/config.hpp b/include/config.hpp index bfbaf79..29be0d8 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -3,6 +3,7 @@ #include +// #define PRINT_TIMINGS #define VERLET_UPDATE // #define WEB diff --git a/include/renderer.hpp b/include/renderer.hpp index 5531652..aee53c5 100644 --- a/include/renderer.hpp +++ b/include/renderer.hpp @@ -92,7 +92,8 @@ public: const State ¤t) -> void; auto DrawKlotski(const State &state, int hov_x, int hov_y, int sel_x, - int sel_y, int block_add_x, int block_add_y) -> void; + int sel_y, int block_add_x, int block_add_y, + const WinCondition win_condition) -> void; auto DrawMenu(const MassSpringSystem &masssprings, int current_preset, const State ¤t_state) -> void; diff --git a/src/main.cpp b/src/main.cpp index e137731..7756190 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,4 @@ -#include #include -#include #include #include @@ -13,6 +11,10 @@ #ifndef WEB #include #endif +#ifdef PRINT_TIMINGS +#include +#include +#endif // TODO: Klotski state file loading // - File should contain a single state per line, multiple lines possible @@ -110,12 +112,14 @@ auto main(int argc, char *argv[]) -> int { int hov_y = 0; int sel_x = 0; int sel_y = 0; +#ifdef PRINT_TIMINGS double last_print_time = GetTime(); std::chrono::duration physics_time_accumulator = std::chrono::duration(0); std::chrono::duration render_time_accumulator = std::chrono::duration(0); int time_measure_count = 0; +#endif while (!WindowShouldClose()) { frametime = GetFrameTime(); std::string previous_state = current_state.state; @@ -286,8 +290,10 @@ auto main(int argc, char *argv[]) -> int { } // Physics update +#ifdef PRINT_TIMINGS std::chrono::high_resolution_clock::time_point ps = std::chrono::high_resolution_clock::now(); +#endif for (int i = 0; i < UPDATES_PER_FRAME; ++i) { masssprings.ClearForces(); masssprings.CalculateSpringForces(); @@ -298,20 +304,25 @@ auto main(int argc, char *argv[]) -> int { mass_springs.EulerUpdate(frametime * SIM_SPEED); #endif } +#ifdef PRINT_TIMINGS std::chrono::high_resolution_clock::time_point pe = std::chrono::high_resolution_clock::now(); physics_time_accumulator += pe - ps; +#endif // Rendering +#ifdef PRINT_TIMINGS std::chrono::high_resolution_clock::time_point rs = std::chrono::high_resolution_clock::now(); +#endif renderer.UpdateCamera(masssprings, current_state); renderer.UpdateTextureSizes(); renderer.DrawMassSprings(masssprings, current_state); renderer.DrawKlotski(current_state, hov_x, hov_y, sel_x, sel_y, block_add_x, - block_add_y); + block_add_y, win_conditions[current_preset]); renderer.DrawMenu(masssprings, current_preset, current_state); renderer.DrawTextures(); +#ifdef PRINT_TIMINGS std::chrono::high_resolution_clock::time_point re = std::chrono::high_resolution_clock::now(); render_time_accumulator += re - rs; @@ -329,6 +340,7 @@ auto main(int argc, char *argv[]) -> int { render_time_accumulator = std::chrono::duration(0); time_measure_count = 0; } +#endif } CloseWindow(); diff --git a/src/renderer.cpp b/src/renderer.cpp index 88d4f20..eb5eb19 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -176,8 +176,8 @@ auto Renderer::DrawMassSprings(const MassSpringSystem &masssprings, } auto Renderer::DrawKlotski(const State &state, int hov_x, int hov_y, int sel_x, - int sel_y, int block_add_x, int block_add_y) - -> void { + int sel_y, int block_add_x, int block_add_y, + const WinCondition win_condition) -> void { BeginTextureMode(klotski_target); ClearBackground(RAYWHITE); @@ -194,10 +194,10 @@ auto Renderer::DrawKlotski(const State &state, int hov_x, int hov_y, int sel_x, DrawRectangle(0, 0, GetScreenWidth() / 2, GetScreenHeight() - MENU_HEIGHT, RAYWHITE); - DrawRectangle(x_offset, y_offset, - board_width - 2 * x_offset + 2 * BOARD_PADDING, - board_height - 2 * y_offset + 2 * BOARD_PADDING, - state.restricted ? DARKGRAY : LIGHTGRAY); + DrawRectangle( + x_offset, y_offset, board_width - 2 * x_offset + 2 * BOARD_PADDING, + board_height - 2 * y_offset + 2 * BOARD_PADDING, + win_condition(state) ? GREEN : (state.restricted ? DARKGRAY : LIGHTGRAY)); for (int x = 0; x < state.width; ++x) { for (int y = 0; y < state.height; ++y) { DrawRectangle(x_offset + BOARD_PADDING + x * BLOCK_PADDING * 2 +