1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Refactor mapController to use precalculated obstacle set.

This commit is contained in:
Tomasz Zieliński 2023-05-20 10:57:05 +02:00
parent cf0515dcd3
commit ccaece9d71
2 changed files with 24 additions and 9 deletions

View File

@ -16,7 +16,6 @@
#include "../lib/mapping/CMapEditManager.h"
#include "../lib/TerrainHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/rmg/modificators/ObstaclePlacer.h"
#include "../lib/CSkillHandler.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CHeroHandler.h"
@ -26,7 +25,7 @@
#include "maphandler.h"
#include "mainwindow.h"
#include "inspector/inspector.h"
#include "VCMI_Lib.h"
MapController::MapController(MainWindow * m): main(m)
{
@ -217,6 +216,18 @@ void MapController::setMap(std::unique_ptr<CMap> cmap)
}
);
_map->getEditManager()->getUndoManager().clearAll();
initObstaclePainters(_map.get());
}
void MapController::initObstaclePainters(CMap * map)
{
for (auto terrain : VLC->terrainTypeHandler->objects)
{
auto terrainId = terrain->getId();
_obstaclePainters[terrainId] = std::make_unique<EditorObstaclePlacer>(map);
_obstaclePainters[terrainId]->collectPossibleObstacles(terrainId);
}
}
void MapController::sceneForceUpdate()
@ -397,8 +408,11 @@ void MapController::commitObstacleFill(int level)
return;
//split by zones
std::map<TerrainId, std::unique_ptr<EditorObstaclePlacer>> terrainSelected;
for (auto & painter : _obstaclePainters)
{
painter.second->clearBlockedArea();
}
for(auto & t : selection)
{
auto tl = _map->getTile(t);
@ -406,14 +420,11 @@ void MapController::commitObstacleFill(int level)
continue;
auto terrain = tl.terType->getId();
//FIXME: This map can be populated once at launch, not need to collect objects every time
terrainSelected[terrain] = std::make_unique<EditorObstaclePlacer>(_map.get());
terrainSelected[terrain]->addBlockedTile(t);
_obstaclePainters[terrain]->addBlockedTile(t);
}
for(auto & sel : terrainSelected)
for(auto & sel : _obstaclePainters)
{
sel.second->collectPossibleObstacles(sel.first);
sel.second->placeObstacles(CRandomGenerator::getDefault());
}

View File

@ -13,6 +13,7 @@
#include "maphandler.h"
#include "mapview.h"
#include "../lib/mapping/CMap.h"
#include "../lib/rmg/modificators/ObstaclePlacer.h"
class MainWindow;
class MapController
@ -24,6 +25,7 @@ public:
~MapController();
void setMap(std::unique_ptr<CMap>);
void initObstaclePainters(CMap* map);
void repairMap();
@ -72,5 +74,7 @@ private:
std::vector<std::unique_ptr<CGObjectInstance>> _clipboard;
int _clipboardShiftIndex = 0;
std::map<TerrainId, std::unique_ptr<EditorObstaclePlacer>> _obstaclePainters;
void connectScenes();
};