From b901876dc3721fdf11078b4d694683d86b8dcf55 Mon Sep 17 00:00:00 2001 From: Alexey Nabrodov Date: Sun, 10 Sep 2017 22:32:16 +0300 Subject: [PATCH] fix damaged cells --- src/MapGenerator.cpp | 14 +++++++++++++- src/application.cpp | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/MapGenerator.cpp b/src/MapGenerator.cpp index 7d20e02..5e7706d 100644 --- a/src/MapGenerator.cpp +++ b/src/MapGenerator.cpp @@ -635,6 +635,12 @@ int MapGenerator::getRelax() { return _relax; } +bool damagedCell(Cell* c) +{ + // return c->discarded; + return c->pointIntersection(c->site.p.x, c->site.p.y) == -1; +} + void MapGenerator::regenDiagram() { currentOperation = "Making nothing..."; _bbox = sf::Rect(0,0,_w, _h); @@ -645,9 +651,15 @@ void MapGenerator::regenDiagram() { currentOperation = "Relaxing..."; makeRelax(); } + + while (std::count_if(_diagram->cells.begin(), _diagram->cells.end(), damagedCell) != 0) { + _relax++; + makeRelax(); + } delete _sites; + std::sort(_diagram->cells.begin(), _diagram->cells.end(), cellsOrdered); - std::cout << "Diagram generation finished: " << _pointsCount << "\n" << std::flush; + std::cout << "Diagram generation finished: " << _diagram->cells.size() << "\n" << std::flush; } void MapGenerator::genRandomSites(std::vector>& sites, sf::Rect& bbox, unsigned int dx, unsigned int dy, unsigned int numSites) { diff --git a/src/application.cpp b/src/application.cpp index 840c87e..3ef45ad 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -291,6 +291,9 @@ class Application { void drawInfo() { sf::Vector2 pos = window->mapPixelToCoords(sf::Mouse::getPosition(*window)); Region* currentRegion = mapgen->getRegion(pos); + if (currentRegion == nullptr) { + return; + } // char p[100]; // sprintf(p,"%p\n",currentRegion); // std::cout<