1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Fix coefficients to make dead code actually be used sometimes.

This commit is contained in:
Tomasz Zieliński
2023-04-20 12:44:32 +02:00
parent 00d7901e59
commit 55d7d7b9b5
2 changed files with 9 additions and 13 deletions

View File

@@ -30,6 +30,8 @@ CZonePlacer::CZonePlacer(RmgMap & map)
stiffnessConstant(3e-3f), stiffnessConstant(3e-3f),
stifness(0), stifness(0),
stiffnessIncreaseFactor(1.05f), stiffnessIncreaseFactor(1.05f),
bestTotalDistance(1e10),
bestTotalOverlap(1e10),
map(map) map(map)
{ {
} }
@@ -321,10 +323,6 @@ void CZonePlacer::placeZones(CRandomGenerator * rand)
//0. set zone sizes and surface / underground level //0. set zone sizes and surface / underground level
prepareZones(zones, zonesVector, underground, rand); prepareZones(zones, zonesVector, underground, rand);
//remember best solution
float bestTotalDistance = 1e10;
float bestTotalOverlap = 1e10;
std::map<std::shared_ptr<Zone>, float3> bestSolution; std::map<std::shared_ptr<Zone>, float3> bestSolution;
TForceVector forces; TForceVector forces;
@@ -673,7 +671,7 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
auto misplacedZone = misplacedZones.front().second; auto misplacedZone = misplacedZones.front().second;
float3 ourCenter = misplacedZone->getCenter(); float3 ourCenter = misplacedZone->getCenter();
if (totalDistance > totalOverlap) if ((totalDistance / (bestTotalDistance + 1)) > (totalOverlap / (bestTotalOverlap + 1)))
{ {
//Move one zone towards most distant zone to reduce distance //Move one zone towards most distant zone to reduce distance
@@ -688,7 +686,7 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
targetZone = otherZone; targetZone = otherZone;
} }
} }
if (targetZone) //TODO: consider refactoring duplicated code if (targetZone)
{ {
float3 vec = targetZone->getCenter() - ourCenter; float3 vec = targetZone->getCenter() - ourCenter;
float newDistanceBetweenZones = (std::max(misplacedZone->getSize(), targetZone->getSize())) / mapSize; float newDistanceBetweenZones = (std::max(misplacedZone->getSize(), targetZone->getSize())) / mapSize;
@@ -696,13 +694,11 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
logGlobal->trace("direction is %s", vec.toString()); logGlobal->trace("direction is %s", vec.toString());
misplacedZone->setCenter(targetZone->getCenter() - vec.unitVector() * newDistanceBetweenZones); //zones should now overlap by half size misplacedZone->setCenter(targetZone->getCenter() - vec.unitVector() * newDistanceBetweenZones); //zones should now overlap by half size
logGlobal->trace("New distance %f", targetZone->getCenter().dist2d(misplacedZone->getCenter()));
} }
} }
else else
{ {
//Move misplaced zone away from overlapping zone //Move misplaced zone away from overlapping zone
//FIXME: Does that ever happend? Check the number ranges and rescale if needed
float maxOverlap = 0; float maxOverlap = 0;
for(const auto & otherZone : zones) for(const auto & otherZone : zones)
@@ -727,7 +723,6 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
logGlobal->trace("direction is %s", vec.toString()); logGlobal->trace("direction is %s", vec.toString());
misplacedZone->setCenter(targetZone->getCenter() + vec.unitVector() * newDistanceBetweenZones); //zones should now be just separated misplacedZone->setCenter(targetZone->getCenter() + vec.unitVector() * newDistanceBetweenZones); //zones should now be just separated
logGlobal->trace("New distance %f", targetZone->getCenter().dist2d(misplacedZone->getCenter()));
} }
} }
//Don't swap that zone in next iteration //Don't swap that zone in next iteration

View File

@@ -50,7 +50,7 @@ private:
private: private:
int width; int width;
int height; int height;
//metric coefiicients //metric coeficients
float scaleX; float scaleX;
float scaleY; float scaleY;
float mapSize; float mapSize;
@@ -59,9 +59,10 @@ private:
float stiffnessConstant; float stiffnessConstant;
float stifness; float stifness;
float stiffnessIncreaseFactor; float stiffnessIncreaseFactor;
//float a1, b1, c1, a2, b2, c2;
//CMap * map; //remember best solution
//std::unique_ptr<CZoneGraph> graph; float bestTotalDistance;
float bestTotalOverlap;
//distance [a][b] = number of zone connections required to travel between the zones //distance [a][b] = number of zone connections required to travel between the zones
std::map<int, std::map<int, size_t>> distancesBetweenZones; std::map<int, std::map<int, size_t>> distancesBetweenZones;