From ec43ed7c52d43e363fbf26cc4084d0a452c3eebb Mon Sep 17 00:00:00 2001 From: dm1sh Date: Tue, 31 May 2022 09:03:38 +0300 Subject: [PATCH] Added debug check macro and some formats --- Controller.cpp | 18 ++++++++++++++---- Drawer.cpp | 5 ++--- utils.h | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Controller.cpp b/Controller.cpp index d538d7d..f24c845 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -45,7 +45,9 @@ void Controller::fillSolveableTable() { auto next_ptr = positions.begin(); - while (!positions.empty() || (not_end && !(positions.insert(getRandLowest()), positions.empty()))) { + while ( + !positions.empty() || + (not_end && !(positions.insert(getRandLowest()), positions.empty()))) { int id = genRandId(); if (id < 34) { @@ -74,21 +76,27 @@ wxPoint Controller::getRandLowest() { return {x, y}; } +#ifdef WXDEBUG + #include void print_list(const std::set& positions) { wxFile f("tmp.txt", wxFile::write_append); - + for (const auto& el : positions) f.Write(itowxS(el.z) + " " + itowxS(el.x) + " " + itowxS(el.y) + "\n"); - + f.Write("_ size: " + itowxS(positions.size()) + "\n"); } +#endif + void Controller::emplace_rand(int id, std::set& positions, std::set::iterator& next_ptr, bool canBeUp) { +#ifdef WXDEBUG print_list(positions); +#endif table[next_ptr->z][next_ptr->x][next_ptr->y] = id; @@ -99,7 +107,7 @@ void Controller::emplace_rand(int id, std::set& positions, do { next_ptr++; - + if (next_ptr == positions.end()) next_ptr = positions.begin(); } while (!canBeUp && !wouldBeUpFree(prev, *next_ptr)); @@ -121,6 +129,7 @@ void Controller::push_available(std::set& positions, const ThreePoint& pos) { int z = pos.z, x = pos.x, y = pos.y; + // clang-format off if (x >= 2 && table[z][x-2][y] == FREE) // left positions.emplace(z, x-2, y); if (x + 2 < gridSize.x && table[z][x+2][y] == FREE) // right @@ -176,6 +185,7 @@ void Controller::push_available(std::set& positions, positions.emplace(z+1, x+1, y+1); } } + // clang-format on } void Controller::free_table() { diff --git a/Drawer.cpp b/Drawer.cpp index e203ee5..17c490a 100644 --- a/Drawer.cpp +++ b/Drawer.cpp @@ -140,9 +140,8 @@ bool Drawer::resizeBoard(const TLVec& layout, const Dimensions& gridSize) { tilePixelSize.Set(gridPoint * TILE_WIDTH, gridPoint * TILE_HEIGHT); } - tablePixelRect.SetPosition( - {(resolution.x - tablePixelRect.width) / 2, - (resolution.y - tablePixelRect.height) / 2}); + tablePixelRect.SetPosition({(resolution.x - tablePixelRect.width) / 2, + (resolution.y - tablePixelRect.height) / 2}); if (gridPoint != prevGridPoint) { composeBoard(layout, gridSize); diff --git a/utils.h b/utils.h index 650602a..cc5cb5e 100644 --- a/utils.h +++ b/utils.h @@ -31,7 +31,7 @@ public: ThreePoint() : x(0), y(0), z(0){}; bool operator<(const ThreePoint& b) const { - return z*144*144+x*144+y < b.z*144*144+b.x*144+b.y; + return z * 144 * 144 + x * 144 + y < b.z * 144 * 144 + b.x * 144 + b.y; } bool operator==(const ThreePoint& b) {