mark visited and starting states
This commit is contained in:
@ -14,7 +14,6 @@ private:
|
|||||||
|
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
Vector3 target;
|
Vector3 target;
|
||||||
Vector3 target_target;
|
|
||||||
float distance;
|
float distance;
|
||||||
float angle_x;
|
float angle_x;
|
||||||
float angle_y;
|
float angle_y;
|
||||||
@ -28,9 +27,9 @@ private:
|
|||||||
public:
|
public:
|
||||||
OrbitCamera3D()
|
OrbitCamera3D()
|
||||||
: camera({0}), position(Vector3Zero()), target(Vector3Zero()),
|
: camera({0}), position(Vector3Zero()), target(Vector3Zero()),
|
||||||
target_target(Vector3Zero()), distance(CAMERA_DISTANCE), angle_x(0.0),
|
distance(CAMERA_DISTANCE), angle_x(0.0), angle_y(0.0),
|
||||||
angle_y(0.0), last_mouse(Vector2Zero()), rotating(false),
|
last_mouse(Vector2Zero()), rotating(false), panning(false),
|
||||||
panning(false), target_lock(true) {
|
target_lock(true) {
|
||||||
camera.position = Vector3(0, 0, -1.0 * distance);
|
camera.position = Vector3(0, 0, -1.0 * distance);
|
||||||
camera.target = target;
|
camera.target = target;
|
||||||
camera.up = Vector3(0, 1.0, 0);
|
camera.up = Vector3(0, 1.0, 0);
|
||||||
|
|||||||
@ -71,8 +71,9 @@ public:
|
|||||||
auto UpdateTextureSizes() -> void;
|
auto UpdateTextureSizes() -> void;
|
||||||
|
|
||||||
auto DrawMassSprings(const MassSpringSystem &mass_springs,
|
auto DrawMassSprings(const MassSpringSystem &mass_springs,
|
||||||
const State ¤t_state,
|
const State ¤t_state, const State &starting_state,
|
||||||
const std::unordered_set<State> &winning_states) -> void;
|
const std::unordered_set<State> &winning_states,
|
||||||
|
const std::unordered_set<State> &visited_states) -> 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,
|
int sel_y, int block_add_x, int block_add_y,
|
||||||
|
|||||||
@ -19,6 +19,7 @@ public:
|
|||||||
bool edited = false;
|
bool edited = false;
|
||||||
|
|
||||||
std::unordered_set<State> winning_states;
|
std::unordered_set<State> winning_states;
|
||||||
|
std::unordered_set<State> visited_states;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StateManager(MassSpringSystem &mass_springs)
|
StateManager(MassSpringSystem &mass_springs)
|
||||||
@ -52,6 +53,8 @@ public:
|
|||||||
|
|
||||||
auto FindWinningStates() -> void;
|
auto FindWinningStates() -> void;
|
||||||
|
|
||||||
|
auto CurrentGenerator() -> StateGenerator;
|
||||||
|
|
||||||
auto CurrentWinCondition() -> WinCondition;
|
auto CurrentWinCondition() -> WinCondition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "util.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
@ -78,11 +76,10 @@ auto OrbitCamera3D::Update(const Vector3 ¤t_target) -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target_lock) {
|
if (target_lock) {
|
||||||
target_target = current_target;
|
|
||||||
target = Vector3MoveTowards(
|
target = Vector3MoveTowards(
|
||||||
target, target_target,
|
target, current_target,
|
||||||
CAMERA_SMOOTH_SPEED * GetFrameTime() *
|
CAMERA_SMOOTH_SPEED * GetFrameTime() *
|
||||||
Vector3Length(Vector3Subtract(target, target_target)));
|
Vector3Length(Vector3Subtract(target, current_target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
distance = Clamp(distance, MIN_CAMERA_DISTANCE, MAX_CAMERA_DISTANCE);
|
distance = Clamp(distance, MIN_CAMERA_DISTANCE, MAX_CAMERA_DISTANCE);
|
||||||
|
|||||||
@ -23,8 +23,6 @@
|
|||||||
// - Click states to display them in the board
|
// - Click states to display them in the board
|
||||||
// - Find shortest path to any winning state and mark it in the graph
|
// - Find shortest path to any winning state and mark it in the graph
|
||||||
// - Also mark the next move along the path on the board
|
// - Also mark the next move along the path on the board
|
||||||
// TODO: Mark the starting state
|
|
||||||
// TODO: Mark the visited states
|
|
||||||
|
|
||||||
auto main(int argc, char *argv[]) -> int {
|
auto main(int argc, char *argv[]) -> int {
|
||||||
// if (argc < 2) {
|
// if (argc < 2) {
|
||||||
@ -103,7 +101,8 @@ auto main(int argc, char *argv[]) -> int {
|
|||||||
|
|
||||||
renderer.UpdateTextureSizes();
|
renderer.UpdateTextureSizes();
|
||||||
renderer.DrawMassSprings(mass_springs, state.current_state,
|
renderer.DrawMassSprings(mass_springs, state.current_state,
|
||||||
state.winning_states);
|
state.CurrentGenerator()(), state.winning_states,
|
||||||
|
state.visited_states);
|
||||||
|
|
||||||
renderer.DrawKlotski(state.current_state, input.hov_x, input.hov_y,
|
renderer.DrawKlotski(state.current_state, input.hov_x, input.hov_y,
|
||||||
input.sel_x, input.sel_y, input.block_add_x,
|
input.sel_x, input.sel_y, input.block_add_x,
|
||||||
|
|||||||
@ -63,7 +63,9 @@ auto Renderer::ReallocateGraphInstancingIfNecessary(
|
|||||||
|
|
||||||
auto Renderer::DrawMassSprings(const MassSpringSystem &mass_springs,
|
auto Renderer::DrawMassSprings(const MassSpringSystem &mass_springs,
|
||||||
const State ¤t_state,
|
const State ¤t_state,
|
||||||
const std::unordered_set<State> &winning_states)
|
const State &starting_state,
|
||||||
|
const std::unordered_set<State> &winning_states,
|
||||||
|
const std::unordered_set<State> &visited_states)
|
||||||
-> void {
|
-> void {
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
|
|
||||||
@ -124,6 +126,19 @@ auto Renderer::DrawMassSprings(const MassSpringSystem &mass_springs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark visited states
|
||||||
|
for (const auto &state : visited_states) {
|
||||||
|
const Mass &visited_mass = mass_springs.GetMass(state);
|
||||||
|
|
||||||
|
DrawCube(visited_mass.position, VERTEX_SIZE * 1.5, VERTEX_SIZE * 1.5,
|
||||||
|
VERTEX_SIZE * 1.5, PURPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark starting state
|
||||||
|
const Mass &starting_mass = mass_springs.GetMass(starting_state);
|
||||||
|
DrawCube(starting_mass.position, VERTEX_SIZE * 2, VERTEX_SIZE * 2,
|
||||||
|
VERTEX_SIZE * 2, ORANGE);
|
||||||
|
|
||||||
// Mark current state
|
// Mark current state
|
||||||
const Mass ¤t_mass = mass_springs.GetMass(current_state);
|
const Mass ¤t_mass = mass_springs.GetMass(current_state);
|
||||||
DrawCube(current_mass.position, VERTEX_SIZE * 2, VERTEX_SIZE * 2,
|
DrawCube(current_mass.position, VERTEX_SIZE * 2, VERTEX_SIZE * 2,
|
||||||
|
|||||||
@ -64,11 +64,13 @@ auto StateManager::UpdateGraph() -> void {
|
|||||||
if (win_conditions[current_preset](current_state)) {
|
if (win_conditions[current_preset](current_state)) {
|
||||||
winning_states.insert(current_state);
|
winning_states.insert(current_state);
|
||||||
}
|
}
|
||||||
|
visited_states.insert(current_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto StateManager::ClearGraph() -> void {
|
auto StateManager::ClearGraph() -> void {
|
||||||
winning_states.clear();
|
winning_states.clear();
|
||||||
|
visited_states.clear();
|
||||||
mass_springs.Clear();
|
mass_springs.Clear();
|
||||||
mass_springs.AddMass(MASS, false, current_state);
|
mass_springs.AddMass(MASS, false, current_state);
|
||||||
|
|
||||||
@ -88,6 +90,10 @@ auto StateManager::FindWinningStates() -> void {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto StateManager::CurrentGenerator() -> StateGenerator {
|
||||||
|
return generators[current_preset];
|
||||||
|
}
|
||||||
|
|
||||||
auto StateManager::CurrentWinCondition() -> WinCondition {
|
auto StateManager::CurrentWinCondition() -> WinCondition {
|
||||||
return win_conditions[current_preset];
|
return win_conditions[current_preset];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user