Compare commits
2 Commits
199646cae9
...
6e5a4acdd0
| Author | SHA1 | Date | |
|---|---|---|---|
|
6e5a4acdd0
|
|||
|
d87df74834
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
|
// #define PRINT_TIMINGS
|
||||||
#define VERLET_UPDATE
|
#define VERLET_UPDATE
|
||||||
// #define WEB
|
// #define WEB
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,8 @@ public:
|
|||||||
const State ¤t) -> void;
|
const State ¤t) -> void;
|
||||||
|
|
||||||
auto DrawKlotski(const State &state, int hov_x, int hov_y, int sel_x,
|
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,
|
auto DrawMenu(const MassSpringSystem &masssprings, int current_preset,
|
||||||
const State ¤t_state) -> void;
|
const State ¤t_state) -> void;
|
||||||
|
|||||||
@ -142,7 +142,16 @@ inline auto state_complex_5r() -> State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline auto state_complex_5r_wc(const State &state) -> bool {
|
inline auto state_complex_5r_wc(const State &state) -> bool {
|
||||||
// R6x6:................................ba......................................
|
return state.GetBlockAt(4, 2) == "ba";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto state_complex_6r() -> State {
|
||||||
|
return State(
|
||||||
|
"R6x6:1231....1213..31........ba..121212..21................1221....."
|
||||||
|
".....21..");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto state_complex_6r_wc(const State &state) -> bool {
|
||||||
return state.GetBlockAt(4, 2) == "ba";
|
return state.GetBlockAt(4, 2) == "ba";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,13 +176,14 @@ inline auto state_klotski_wc(const State &state) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<StateGenerator> generators{
|
std::vector<StateGenerator> generators{
|
||||||
state_simple_1r, state_simple_2r, state_simple_3r,
|
state_simple_1r, state_simple_2r, state_simple_3r, state_complex_1r,
|
||||||
state_complex_1r, state_complex_2r, state_complex_3r,
|
state_complex_2r, state_complex_3r, state_complex_4f, state_complex_5r,
|
||||||
state_complex_4f, state_complex_5r, state_klotski};
|
state_complex_6r, state_klotski};
|
||||||
|
|
||||||
std::vector<WinCondition> win_conditions{
|
std::vector<WinCondition> win_conditions{
|
||||||
state_simple_1r_wc, state_simple_2r_wc, state_simple_3r_wc,
|
state_simple_1r_wc, state_simple_2r_wc, state_simple_3r_wc,
|
||||||
state_complex_1r_wc, state_complex_2r_wc, state_complex_3r_wc,
|
state_complex_1r_wc, state_complex_2r_wc, state_complex_3r_wc,
|
||||||
state_complex_4f_wc, state_complex_5r_wc, state_klotski_wc};
|
state_complex_4f_wc, state_complex_5r_wc, state_complex_6r_wc,
|
||||||
|
state_klotski_wc};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
18
src/main.cpp
18
src/main.cpp
@ -1,6 +1,4 @@
|
|||||||
#include <chrono>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ratio>
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
@ -13,6 +11,10 @@
|
|||||||
#ifndef WEB
|
#ifndef WEB
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PRINT_TIMINGS
|
||||||
|
#include <chrono>
|
||||||
|
#include <ratio>
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: Klotski state file loading
|
// TODO: Klotski state file loading
|
||||||
// - File should contain a single state per line, multiple lines possible
|
// - 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 hov_y = 0;
|
||||||
int sel_x = 0;
|
int sel_x = 0;
|
||||||
int sel_y = 0;
|
int sel_y = 0;
|
||||||
|
#ifdef PRINT_TIMINGS
|
||||||
double last_print_time = GetTime();
|
double last_print_time = GetTime();
|
||||||
std::chrono::duration<double, std::milli> physics_time_accumulator =
|
std::chrono::duration<double, std::milli> physics_time_accumulator =
|
||||||
std::chrono::duration<double, std::milli>(0);
|
std::chrono::duration<double, std::milli>(0);
|
||||||
std::chrono::duration<double, std::milli> render_time_accumulator =
|
std::chrono::duration<double, std::milli> render_time_accumulator =
|
||||||
std::chrono::duration<double, std::milli>(0);
|
std::chrono::duration<double, std::milli>(0);
|
||||||
int time_measure_count = 0;
|
int time_measure_count = 0;
|
||||||
|
#endif
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
frametime = GetFrameTime();
|
frametime = GetFrameTime();
|
||||||
std::string previous_state = current_state.state;
|
std::string previous_state = current_state.state;
|
||||||
@ -286,8 +290,10 @@ auto main(int argc, char *argv[]) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Physics update
|
// Physics update
|
||||||
|
#ifdef PRINT_TIMINGS
|
||||||
std::chrono::high_resolution_clock::time_point ps =
|
std::chrono::high_resolution_clock::time_point ps =
|
||||||
std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::now();
|
||||||
|
#endif
|
||||||
for (int i = 0; i < UPDATES_PER_FRAME; ++i) {
|
for (int i = 0; i < UPDATES_PER_FRAME; ++i) {
|
||||||
masssprings.ClearForces();
|
masssprings.ClearForces();
|
||||||
masssprings.CalculateSpringForces();
|
masssprings.CalculateSpringForces();
|
||||||
@ -298,20 +304,25 @@ auto main(int argc, char *argv[]) -> int {
|
|||||||
mass_springs.EulerUpdate(frametime * SIM_SPEED);
|
mass_springs.EulerUpdate(frametime * SIM_SPEED);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifdef PRINT_TIMINGS
|
||||||
std::chrono::high_resolution_clock::time_point pe =
|
std::chrono::high_resolution_clock::time_point pe =
|
||||||
std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::now();
|
||||||
physics_time_accumulator += pe - ps;
|
physics_time_accumulator += pe - ps;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
|
#ifdef PRINT_TIMINGS
|
||||||
std::chrono::high_resolution_clock::time_point rs =
|
std::chrono::high_resolution_clock::time_point rs =
|
||||||
std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::now();
|
||||||
|
#endif
|
||||||
renderer.UpdateCamera(masssprings, current_state);
|
renderer.UpdateCamera(masssprings, current_state);
|
||||||
renderer.UpdateTextureSizes();
|
renderer.UpdateTextureSizes();
|
||||||
renderer.DrawMassSprings(masssprings, current_state);
|
renderer.DrawMassSprings(masssprings, current_state);
|
||||||
renderer.DrawKlotski(current_state, hov_x, hov_y, sel_x, sel_y, block_add_x,
|
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.DrawMenu(masssprings, current_preset, current_state);
|
||||||
renderer.DrawTextures();
|
renderer.DrawTextures();
|
||||||
|
#ifdef PRINT_TIMINGS
|
||||||
std::chrono::high_resolution_clock::time_point re =
|
std::chrono::high_resolution_clock::time_point re =
|
||||||
std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::now();
|
||||||
render_time_accumulator += re - rs;
|
render_time_accumulator += re - rs;
|
||||||
@ -329,6 +340,7 @@ auto main(int argc, char *argv[]) -> int {
|
|||||||
render_time_accumulator = std::chrono::duration<double, std::milli>(0);
|
render_time_accumulator = std::chrono::duration<double, std::milli>(0);
|
||||||
time_measure_count = 0;
|
time_measure_count = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|||||||
@ -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,
|
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)
|
int sel_y, int block_add_x, int block_add_y,
|
||||||
-> void {
|
const WinCondition win_condition) -> void {
|
||||||
BeginTextureMode(klotski_target);
|
BeginTextureMode(klotski_target);
|
||||||
ClearBackground(RAYWHITE);
|
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,
|
DrawRectangle(0, 0, GetScreenWidth() / 2, GetScreenHeight() - MENU_HEIGHT,
|
||||||
RAYWHITE);
|
RAYWHITE);
|
||||||
DrawRectangle(x_offset, y_offset,
|
DrawRectangle(
|
||||||
board_width - 2 * x_offset + 2 * BOARD_PADDING,
|
x_offset, y_offset, board_width - 2 * x_offset + 2 * BOARD_PADDING,
|
||||||
board_height - 2 * y_offset + 2 * BOARD_PADDING,
|
board_height - 2 * y_offset + 2 * BOARD_PADDING,
|
||||||
state.restricted ? DARKGRAY : LIGHTGRAY);
|
win_condition(state) ? GREEN : (state.restricted ? DARKGRAY : LIGHTGRAY));
|
||||||
for (int x = 0; x < state.width; ++x) {
|
for (int x = 0; x < state.width; ++x) {
|
||||||
for (int y = 0; y < state.height; ++y) {
|
for (int y = 0; y < state.height; ++y) {
|
||||||
DrawRectangle(x_offset + BOARD_PADDING + x * BLOCK_PADDING * 2 +
|
DrawRectangle(x_offset + BOARD_PADDING + x * BLOCK_PADDING * 2 +
|
||||||
|
|||||||
Reference in New Issue
Block a user