fix bug where starting index was set incorrectly when populating graph
This commit is contained in:
@ -41,4 +41,4 @@ F451311bb..1112....12..12....11....1121..21..
|
|||||||
F451312111111..12bb..12........21..11....21..
|
F451312111111..12bb..12........21..11....21..
|
||||||
|
|
||||||
# Supercompo
|
# Supercompo
|
||||||
F4513..bb....11....111221..12..21....1121..11
|
F4513..bb....11....111221..12..21....1121..11
|
||||||
@ -51,11 +51,11 @@ public:
|
|||||||
instancing_shader.locs[SHADER_LOC_VECTOR_VIEW] =
|
instancing_shader.locs[SHADER_LOC_VECTOR_VIEW] =
|
||||||
GetShaderLocation(instancing_shader, "viewPos");
|
GetShaderLocation(instancing_shader, "viewPos");
|
||||||
|
|
||||||
infoln("LOC vertexPosition: {}",
|
// infoln("LOC vertexPosition: {}",
|
||||||
rlGetLocationAttrib(instancing_shader.id, "vertexPosition"));
|
// rlGetLocationAttrib(instancing_shader.id, "vertexPosition"));
|
||||||
infoln("LOC instanceTransform: {}",
|
// infoln("LOC instanceTransform: {}",
|
||||||
rlGetLocationAttrib(instancing_shader.id, "instanceTransform"));
|
// rlGetLocationAttrib(instancing_shader.id, "instanceTransform"));
|
||||||
infoln("LOC instanceColor: {}", rlGetLocationAttrib(instancing_shader.id, "instanceColor"));
|
// infoln("LOC instanceColor: {}", rlGetLocationAttrib(instancing_shader.id, "instanceColor"));
|
||||||
|
|
||||||
// vertex_mat.maps[MATERIAL_MAP_DIFFUSE].color = VERTEX_COLOR;
|
// vertex_mat.maps[MATERIAL_MAP_DIFFUSE].color = VERTEX_COLOR;
|
||||||
vertex_mat.shader = instancing_shader;
|
vertex_mat.shader = instancing_shader;
|
||||||
|
|||||||
@ -34,7 +34,7 @@ private:
|
|||||||
std::unordered_set<size_t>
|
std::unordered_set<size_t>
|
||||||
path_indices; // For faster lookup if a vertex is part of the path in renderer
|
path_indices; // For faster lookup if a vertex is part of the path in renderer
|
||||||
|
|
||||||
std::stack<size_t> move_history; // Moves between the starting state and the current state
|
std::vector<size_t> move_history; // Moves between the starting state and the current state
|
||||||
std::unordered_map<size_t, int> visit_counts; // How often each state was visited
|
std::unordered_map<size_t, int> visit_counts; // How often each state was visited
|
||||||
|
|
||||||
size_t starting_state_index = 0;
|
size_t starting_state_index = 0;
|
||||||
@ -42,6 +42,7 @@ private:
|
|||||||
size_t previous_state_index = 0;
|
size_t previous_state_index = 0;
|
||||||
|
|
||||||
int total_moves = 0;
|
int total_moves = 0;
|
||||||
|
bool edited = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
state_manager(threaded_physics& _physics, const std::string& _preset_file) : physics(_physics)
|
state_manager(threaded_physics& _physics, const std::string& _preset_file) : physics(_physics)
|
||||||
|
|||||||
@ -498,7 +498,7 @@ auto puzzle::explore_state_space() const
|
|||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
infoln("Exploring state space, this might take a while...");
|
// infoln("Exploring state space, this might take a while...");
|
||||||
|
|
||||||
std::vector<puzzle> state_pool;
|
std::vector<puzzle> state_pool;
|
||||||
std::unordered_map<puzzle, std::size_t> state_indices; // Helper to construct the links vector
|
std::unordered_map<puzzle, std::size_t> state_indices; // Helper to construct the links vector
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include <ios>
|
#include <ios>
|
||||||
|
|
||||||
#ifdef TRACY
|
#ifdef TRACY
|
||||||
#include <tracy/Tracy.hpp>
|
#include <tracy/Tracy.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto state_manager::synced_try_insert_state(const puzzle& state) -> size_t
|
auto state_manager::synced_try_insert_state(const puzzle& state) -> size_t
|
||||||
@ -35,8 +35,7 @@ auto state_manager::synced_insert_link(size_t first_index, size_t second_index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto state_manager::synced_insert_statespace(const std::vector<puzzle>& states,
|
auto state_manager::synced_insert_statespace(const std::vector<puzzle>& states,
|
||||||
const std::vector<std::pair<size_t, size_t>>& _links)
|
const std::vector<std::pair<size_t, size_t>>& _links) -> void
|
||||||
-> void
|
|
||||||
{
|
{
|
||||||
if (!state_pool.empty() || !state_indices.empty() || !links.empty()) {
|
if (!state_pool.empty() || !state_indices.empty() || !links.empty()) {
|
||||||
warnln("Inserting statespace but collections haven't been cleared");
|
warnln("Inserting statespace but collections haven't been cleared");
|
||||||
@ -71,7 +70,7 @@ auto state_manager::synced_clear_statespace() -> void
|
|||||||
winning_path.clear();
|
winning_path.clear();
|
||||||
path_indices.clear();
|
path_indices.clear();
|
||||||
|
|
||||||
move_history = std::stack<size_t>();
|
move_history.clear();
|
||||||
visit_counts.clear();
|
visit_counts.clear();
|
||||||
|
|
||||||
// Queue an update to the physics engine state to keep in sync
|
// Queue an update to the physics engine state to keep in sync
|
||||||
@ -150,6 +149,7 @@ auto state_manager::load_preset(const size_t preset) -> void
|
|||||||
{
|
{
|
||||||
clear_graph_and_add_current(preset_states.at(preset));
|
clear_graph_and_add_current(preset_states.at(preset));
|
||||||
current_preset = preset;
|
current_preset = preset;
|
||||||
|
edited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto state_manager::load_previous_preset() -> void
|
auto state_manager::load_previous_preset() -> void
|
||||||
@ -186,7 +186,7 @@ auto state_manager::update_current_state(const puzzle& p) -> void
|
|||||||
current_state_index = index;
|
current_state_index = index;
|
||||||
|
|
||||||
if (current_state_index != previous_state_index) {
|
if (current_state_index != previous_state_index) {
|
||||||
move_history.push(previous_state_index);
|
move_history.emplace_back(previous_state_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.won()) {
|
if (p.won()) {
|
||||||
@ -208,12 +208,14 @@ auto state_manager::edit_starting_state(const puzzle& p) -> void
|
|||||||
{
|
{
|
||||||
clear_graph_and_add_current(p);
|
clear_graph_and_add_current(p);
|
||||||
|
|
||||||
move_history = std::stack<size_t>();
|
move_history.clear();
|
||||||
total_moves = 0;
|
total_moves = 0;
|
||||||
for (int& visits : visit_counts | std::views::values) {
|
for (int& visits : visit_counts | std::views::values) {
|
||||||
visits = 0;
|
visits = 0;
|
||||||
}
|
}
|
||||||
visit_counts[current_state_index]++;
|
visit_counts[current_state_index]++;
|
||||||
|
|
||||||
|
edited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto state_manager::goto_starting_state() -> void
|
auto state_manager::goto_starting_state() -> void
|
||||||
@ -226,7 +228,7 @@ auto state_manager::goto_starting_state() -> void
|
|||||||
visits = 0;
|
visits = 0;
|
||||||
}
|
}
|
||||||
visit_counts[current_state_index]++;
|
visit_counts[current_state_index]++;
|
||||||
move_history = std::stack<size_t>();
|
move_history.clear();
|
||||||
total_moves = 0;
|
total_moves = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,11 +253,11 @@ auto state_manager::goto_previous_state() -> void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_current_state(get_state(move_history.top()));
|
update_current_state(get_state(move_history.back()));
|
||||||
|
|
||||||
// Pop twice because update_current_state adds the state again...
|
// Pop twice because update_current_state adds the state again...
|
||||||
move_history.pop();
|
move_history.pop_back();
|
||||||
move_history.pop();
|
move_history.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto state_manager::goto_most_distant_state() -> void
|
auto state_manager::goto_most_distant_state() -> void
|
||||||
@ -287,23 +289,24 @@ auto state_manager::goto_closest_target_state() -> void
|
|||||||
|
|
||||||
auto state_manager::populate_graph() -> void
|
auto state_manager::populate_graph() -> void
|
||||||
{
|
{
|
||||||
#ifdef TRACY
|
#ifdef TRACY
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Need to make a copy before clearing the state_pool
|
// Need to make a copy before clearing the state_pool
|
||||||
|
const puzzle s = get_starting_state();
|
||||||
const puzzle p = get_current_state();
|
const puzzle p = get_current_state();
|
||||||
|
|
||||||
// Clear the graph first so we don't add duplicates somehow
|
// Clear the graph first so we don't add duplicates somehow
|
||||||
synced_clear_statespace();
|
synced_clear_statespace();
|
||||||
|
|
||||||
// Explore the entire statespace starting from the current state
|
// Explore the entire statespace starting from the current state
|
||||||
const auto& [states, _links] = p.explore_state_space();
|
const auto& [states, _links] = s.explore_state_space();
|
||||||
synced_insert_statespace(states, _links);
|
synced_insert_statespace(states, _links);
|
||||||
|
|
||||||
current_state_index = state_indices.at(p);
|
current_state_index = state_indices.at(p);
|
||||||
previous_state_index = current_state_index;
|
previous_state_index = current_state_index;
|
||||||
starting_state_index = current_state_index;
|
starting_state_index = state_indices.at(s);
|
||||||
|
|
||||||
// Search for cool stuff
|
// Search for cool stuff
|
||||||
populate_winning_indices();
|
populate_winning_indices();
|
||||||
@ -313,7 +316,7 @@ auto state_manager::populate_graph() -> void
|
|||||||
|
|
||||||
auto state_manager::clear_graph_and_add_current(const puzzle& p) -> void
|
auto state_manager::clear_graph_and_add_current(const puzzle& p) -> void
|
||||||
{
|
{
|
||||||
// Do we need to make a copy before clearing the state_pool?
|
// We need to make a copy before clearing the state_pool
|
||||||
const puzzle _p = p; // NOLINT(*-unnecessary-copy-initialization)
|
const puzzle _p = p; // NOLINT(*-unnecessary-copy-initialization)
|
||||||
|
|
||||||
synced_clear_statespace();
|
synced_clear_statespace();
|
||||||
@ -345,9 +348,9 @@ auto state_manager::populate_winning_indices() -> void
|
|||||||
|
|
||||||
auto state_manager::populate_node_target_distances() -> void
|
auto state_manager::populate_node_target_distances() -> void
|
||||||
{
|
{
|
||||||
#ifdef TRACY
|
#ifdef TRACY
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (links.empty() || winning_indices.empty()) {
|
if (links.empty() || winning_indices.empty()) {
|
||||||
return;
|
return;
|
||||||
@ -483,5 +486,5 @@ auto state_manager::get_total_moves() const -> size_t
|
|||||||
|
|
||||||
auto state_manager::was_edited() const -> bool
|
auto state_manager::was_edited() const -> bool
|
||||||
{
|
{
|
||||||
return preset_states.at(current_preset) != get_state(starting_state_index);
|
return edited;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user