Skip to content

Commit

Permalink
Warning pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-dejoue committed Jul 25, 2023
1 parent d947e83 commit efb59ca
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ if (PICROSS_GUI_IMGUI_DEMO)
)
endif()

set_target_warnings(picross_solver ON)

target_link_libraries(picross_solver
PRIVATE
stdutils
Expand Down
6 changes: 3 additions & 3 deletions src/gui/src/draw_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ void draw_grid(ImDrawList* draw_list, ImVec2 tl_corner, size_t tile_size, const
assert(draw_list);
const size_t width = grid.width();
const size_t height = grid.height();
for (size_t i = 0u; i < width; ++i)
for (picross::Line::Index i = 0u; i < width; ++i)
{
for (size_t j = 0u; j < height; ++j)
for (picross::Line::Index j = 0u; j < height; ++j)
{
const auto tile = grid.get_tile(i, j);
if (tile == picross::Tile::UNKNOWN)
continue;
const auto depth = grid.get_depth(i, j);
const auto color_depth = color_by_depth ? depth : 0;
const bool filled = (tile == picross::Tile::FILLED);
const bool hidden = tile_settings.hide_depth_greater ? (depth >= tile_settings.hide_depth_value) : false;
const bool hidden = tile_settings.hide_depth_greater ? (static_cast<int>(depth) >= tile_settings.hide_depth_value) : false;
draw_tile(draw_list, tl_corner, tile_size, i, j, filled, hidden, color_depth, tile_settings.size_ratio, tile_settings.rounding_ratio);
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/gui/src/grid_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ void GridWindow::visit(bool& can_be_erased, Settings& settings)
reset_solutions();
if (info) { info->update_solver_status(0u, 0u, 0.f); }
solver_thread_completed = false;
std::swap(solver_thread, std::thread(&GridWindow::solve_picross_grid, this));
std::thread new_thread(&GridWindow::solve_picross_grid, this);
std::swap(solver_thread, new_thread);
solver_thread_start = false;
}
// If solver thread is active
Expand All @@ -131,7 +132,8 @@ void GridWindow::visit(bool& can_be_erased, Settings& settings)
{
// The solver thread being over does not mean that all observer events have been processed
solver_thread.join();
std::swap(solver_thread, std::thread());
std::thread null_thread;
std::swap(solver_thread, null_thread);
assert(!solver_thread.joinable());
std::cerr << "End of solver thread for grid " << grid.name() << std::endl;
if (info) { info->solver_completed(solver_thread_stats); }
Expand Down Expand Up @@ -213,9 +215,9 @@ void GridWindow::visit(bool& can_be_erased, Settings& settings)
// Visit info window
if (info)
{
bool can_be_erased = false;
info->visit(can_be_erased);
if (can_be_erased)
bool info_can_be_erased = false;
info->visit(info_can_be_erased);
if (info_can_be_erased)
info.reset();
}

Expand All @@ -232,9 +234,9 @@ void GridWindow::visit(bool& can_be_erased, Settings& settings)
// Visit goal window
if (goal_win)
{
bool can_be_erased = false;
goal_win->visit(can_be_erased, settings);
if (can_be_erased)
bool goal_can_be_erased = false;
goal_win->visit(goal_can_be_erased, settings);
if (goal_can_be_erased)
goal_win.reset();
}

Expand Down Expand Up @@ -304,13 +306,11 @@ void GridWindow::reset_solutions()
solver_progress = 0.f;

// Clear text buffer and print out the grid size
const size_t width = grid.width();
const size_t height = grid.height();
text_buffer->buffer.clear();
text_buffer->buffer.appendf("Grid %s\n", picross::str_input_grid_size(grid).c_str());
}

void GridWindow::observer_callback(picross::ObserverEvent event, const picross::Line* line, unsigned int, unsigned int misc, const ObserverGrid& grid)
void GridWindow::observer_callback(picross::ObserverEvent event, const picross::Line* line, unsigned int, unsigned int misc, const ObserverGrid& l_grid)
{
// Filter out events useless to the GUI
if (event != picross::ObserverEvent::DELTA_LINE && event != picross::ObserverEvent::SOLVED_GRID && event != picross::ObserverEvent::PROGRESS)
Expand All @@ -329,7 +329,7 @@ void GridWindow::observer_callback(picross::ObserverEvent event, const picross::
|| this->abort_solver_thread();
});
}
line_events.emplace_back(event, line, misc, grid);
line_events.emplace_back(event, line, misc, l_grid);
}

unsigned int GridWindow::process_line_events(std::vector<LineEvent>& events)
Expand Down Expand Up @@ -383,7 +383,6 @@ void GridWindow::solve_picross_grid()
solver_thread_stats = picross::GridStats();

const auto solver = picross::get_ref_solver();
unsigned count_grids = 0u;

// Sanity check of the input data
const auto [check, check_msg] = picross::check_input_grid(grid);
Expand Down
4 changes: 4 additions & 0 deletions src/gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "settings.h"

#include <picross/picross.h>
#include <stdutils/macros.h>

#include <portable-file-dialogs.h> // Include before glfw3.h
#include <GLFW/glfw3.h>
Expand Down Expand Up @@ -57,6 +58,9 @@ void imgui_set_style(bool dark_mode)

int main(int argc, char *argv[])
{
UNUSED(argc);
UNUSED(argv);

// Versions
std::stringstream picross_title;
picross_title << "Picross Solver " << picross::get_version_string();
Expand Down
19 changes: 19 additions & 0 deletions src/gui/src/parameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <algorithm>


struct Parameter
{
template <typename T>
struct Limits
{
T def;
T min;
T max;

void clamp(T& v) const { v = std::max(min, std::min(v, max)); }
};
static constexpr Limits<bool> limits_true { true, false, true };
static constexpr Limits<bool> limits_false { false, false, true };
};
44 changes: 22 additions & 22 deletions src/gui/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ namespace
{
Settings::TileLimits result;

result.size_enum.default = 2;
result.size_enum.def = 2;
result.size_enum.min = 0;
result.size_enum.max = 4;

result.rounding_ratio.default = 0.f;
result.rounding_ratio.def = 0.f;
result.rounding_ratio.min = 0.f;
result.rounding_ratio.max = 1.f;

result.size_ratio.default = 1.f;
result.size_ratio.def = 1.f;
result.size_ratio.min = 0.001f;
result.size_ratio.max = 1.f;

result.five_tile_border = Settings::limits_false;
result.five_tile_border = Parameter::limits_false;

result.hide_depth_greater = Settings::limits_false;
result.hide_depth_greater = Parameter::limits_false;

result.hide_depth_value.default = 2;
result.hide_depth_value.def = 2;
result.hide_depth_value.min = 1;
result.hide_depth_value.max = 1000;

Expand All @@ -37,9 +37,9 @@ namespace
{
Settings::SolverLimits result;

result.limit_solutions = Settings::limits_true;
result.limit_solutions = Parameter::limits_true;

result.max_nb_solutions.default = 2;
result.max_nb_solutions.def = 2;
result.max_nb_solutions.min = 1;
result.max_nb_solutions.max = std::numeric_limits<int>::max();

Expand All @@ -50,11 +50,11 @@ namespace
{
Settings::AnimationLimits result;

result.show_branching = Settings::limits_true;
result.show_branching = Parameter::limits_true;

result.ftl = Settings::limits_false;
result.ftl = Parameter::limits_false;

result.speed.default = 20;
result.speed.def = 20;
result.speed.min = 0;
result.speed.max = 40;

Expand All @@ -81,12 +81,12 @@ const Settings::Tile& Settings::read_tile_settings()
if (!tile_settings)
{
tile_settings = std::make_unique<Tile>();
tile_settings->size_enum = read_tile_settings_limits().size_enum.default;
tile_settings->rounding_ratio = read_tile_settings_limits().rounding_ratio.default;
tile_settings->size_ratio = read_tile_settings_limits().size_ratio.default;
tile_settings->five_tile_border = read_tile_settings_limits().five_tile_border.default;
tile_settings->hide_depth_greater = read_tile_settings_limits().hide_depth_greater.default;
tile_settings->hide_depth_value = read_tile_settings_limits().hide_depth_value.default;
tile_settings->size_enum = read_tile_settings_limits().size_enum.def;
tile_settings->rounding_ratio = read_tile_settings_limits().rounding_ratio.def;
tile_settings->size_ratio = read_tile_settings_limits().size_ratio.def;
tile_settings->five_tile_border = read_tile_settings_limits().five_tile_border.def;
tile_settings->hide_depth_greater = read_tile_settings_limits().hide_depth_greater.def;
tile_settings->hide_depth_value = read_tile_settings_limits().hide_depth_value.def;
}
assert(tile_settings);
return *tile_settings;
Expand All @@ -109,8 +109,8 @@ const Settings::Solver& Settings::read_solver_settings()
if (!solver_settings)
{
solver_settings = std::make_unique<Solver>();
solver_settings->limit_solutions = read_solver_settings_limits().limit_solutions.default;
solver_settings->max_nb_solutions = read_solver_settings_limits().max_nb_solutions.default;
solver_settings->limit_solutions = read_solver_settings_limits().limit_solutions.def;
solver_settings->max_nb_solutions = read_solver_settings_limits().max_nb_solutions.def;
}
assert(solver_settings);
return *solver_settings;
Expand All @@ -133,9 +133,9 @@ const Settings::Animation& Settings::read_animation_settings()
if (!animation_settings)
{
animation_settings = std::make_unique<Animation>();
animation_settings->show_branching = read_animation_settings_limits().show_branching.default;
animation_settings->ftl = read_animation_settings_limits().ftl.default;
animation_settings->speed = read_animation_settings_limits().speed.default;
animation_settings->show_branching = read_animation_settings_limits().show_branching.def;
animation_settings->ftl = read_animation_settings_limits().ftl.def;
animation_settings->speed = read_animation_settings_limits().speed.def;
}
assert(animation_settings);
return *animation_settings;
Expand Down
34 changes: 12 additions & 22 deletions src/gui/src/settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "parameter.h"
#include "settings_window.h"

#include <algorithm>
Expand All @@ -8,25 +9,14 @@
class Settings
{
public:
template<typename T>
struct Limits
{
T default;
T min;
T max;

void clamp(T& v) const { v = std::max(min, std::min(v, max)); }
};
static constexpr Limits<bool> limits_true{ true, false, true };
static constexpr Limits<bool> limits_false{ false, false, true };
struct TileLimits
{
Limits<int> size_enum;
Limits<float> rounding_ratio;
Limits<float> size_ratio;
Limits<bool> five_tile_border;
Limits<bool> hide_depth_greater;
Limits<int> hide_depth_value;
Parameter::Limits<int> size_enum;
Parameter::Limits<float> rounding_ratio;
Parameter::Limits<float> size_ratio;
Parameter::Limits<bool> five_tile_border;
Parameter::Limits<bool> hide_depth_greater;
Parameter::Limits<int> hide_depth_value;
};
struct Tile
{
Expand All @@ -39,8 +29,8 @@ class Settings
};
struct SolverLimits
{
Limits<bool> limit_solutions;
Limits<int> max_nb_solutions;
Parameter::Limits<bool> limit_solutions;
Parameter::Limits<int> max_nb_solutions;
};
struct Solver
{
Expand All @@ -49,9 +39,9 @@ class Settings
};
struct AnimationLimits
{
Limits<bool> show_branching;
Limits<bool> ftl;
Limits<int> speed;
Parameter::Limits<bool> show_branching;
Parameter::Limits<bool> ftl;
Parameter::Limits<int> speed;
};
struct Animation
{
Expand Down

0 comments on commit efb59ca

Please sign in to comment.