diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index b658f77c4..f6c8d4f76 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -124,7 +124,7 @@ void CMapGenerator::initQuestArtsRemaining() } } -std::unique_ptr CMapGenerator::generate(bool empty) +std::unique_ptr CMapGenerator::generate() { Load::Progress::reset(); Load::Progress::stepsTill(5, 30); @@ -132,11 +132,6 @@ std::unique_ptr CMapGenerator::generate(bool empty) { addHeaderInfo(); map->initTiles(*this); - if(empty) - { - Progress::Progress::finish(); - return std::move(map->mapInstance); - } Load::Progress::step(); initPrisonsRemaining(); initQuestArtsRemaining(); diff --git a/lib/rmg/CMapGenerator.h b/lib/rmg/CMapGenerator.h index faf71541c..f32640cf2 100644 --- a/lib/rmg/CMapGenerator.h +++ b/lib/rmg/CMapGenerator.h @@ -57,7 +57,7 @@ public: const CMapGenOptions& getMapGenOptions() const; - std::unique_ptr generate(bool emptyMap = false); + std::unique_ptr generate(); void disableModificator(const std::string & modificator); void findZonesForQuestArts(); diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 39bbaba00..867784657 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -58,8 +58,7 @@ void init() MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow), - controller(this) + ui(new Ui::MainWindow) { ui->setupUi(this); @@ -132,8 +131,6 @@ MainWindow::MainWindow(QWidget *parent) : loadObjectsTree(); show(); - - setStatusMessage("privet"); } MainWindow::~MainWindow() @@ -166,14 +163,11 @@ void MainWindow::initializeMap(bool isNew) filename.clear(); setWindowTitle(filename + "* - VCMI Map Editor"); - - -// reloadMap(); - //if(map->twoLevel) - //reloadMap(1); mapLevel = 0; ui->mapView->setScene(controller.scene(mapLevel)); + + setStatusMessage(QString("Scene objects: %1").arg(ui->mapView->scene()->items().size())); //enable settings ui->actionMapSettings->setEnabled(true); @@ -754,11 +748,13 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item) void MainWindow::on_actionMapSettings_triggered() { auto mapSettingsDialog = new MapSettings(controller, this); + mapSettingsDialog->setModal(true); } void MainWindow::on_actionPlayers_settings_triggered() { auto mapSettingsDialog = new PlayerSettings(*controller.map(), this); + mapSettingsDialog->setModal(true); } diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index 254f60267..b707f1c6b 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -14,16 +14,14 @@ #include "inspector.h" -MapController::MapController(MainWindow * m) : _main(m) +MapController::MapController() { - _scenes[0] = new MapScene(0); - _scenes[1] = new MapScene(1); + _scenes[0].reset(new MapScene(0)); + _scenes[1].reset(new MapScene(1)); } MapController::~MapController() { - delete _scenes[0]; - delete _scenes[1]; } CMap * MapController::map() @@ -38,12 +36,14 @@ MapHandler * MapController::mapHandler() MapScene * MapController::scene(int level) { - return _scenes[level]; + return _scenes[level].get(); } void MapController::setMap(std::unique_ptr cmap) { _map = std::move(cmap); + //_scenes[0].reset(new MapScene(0)); + //_scenes[1].reset(new MapScene(1)); resetMapHandler(); sceneForceUpdate(); } @@ -149,7 +149,8 @@ void MapController::commitObstacleFill(int level) void MapController::commitObjectChange(int level) { resetMapHandler(); - _scenes[level]->updateViews(); + _scenes[level]->objectsView.draw(); + _scenes[level]->selectionObjectsView.draw(); } diff --git a/mapeditor/mapcontroller.h b/mapeditor/mapcontroller.h index f65e405a6..e90c7ac2e 100644 --- a/mapeditor/mapcontroller.h +++ b/mapeditor/mapcontroller.h @@ -10,7 +10,7 @@ class MainWindow; class MapController { public: - MapController(MainWindow *); + MapController(); MapController(const MapController &) = delete; MapController(const MapController &&) = delete; ~MapController(); @@ -38,10 +38,9 @@ public: void createObject(int level, CGObjectInstance * obj) const; private: - MainWindow * _main; std::unique_ptr _map; std::unique_ptr _mapHandler; - mutable std::array _scenes; + mutable std::array, 2> _scenes; }; #endif // MAPCONTROLLER_H diff --git a/mapeditor/playersettings.cpp b/mapeditor/playersettings.cpp index d9d64e294..5e5b119af 100644 --- a/mapeditor/playersettings.cpp +++ b/mapeditor/playersettings.cpp @@ -35,7 +35,7 @@ PlayerSettings::~PlayerSettings() void PlayerSettings::on_playersCount_currentIndexChanged(int index) { - assert(index + 2 != paramWidgets.size()); + assert(index + 2 == paramWidgets.size()); assert(index + 2 < header.players.size()); for(int i = 0; i < index + 2; ++i) diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index 8d7114195..dcd3d5bef 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -45,10 +45,9 @@ void WindowNewMap::on_cancelButton_clicked() void generateRandomMap(CMapGenerator & gen, MainWindow * window) { window->controller.setMap(gen.generate()); - //window->setMapRaw(); } -void generateEmptyMap(CMapGenOptions & options, MainWindow * window) +std::unique_ptr generateEmptyMap(CMapGenOptions & options) { std::unique_ptr map(new CMap); map->version = EMapFormat::VCMI; @@ -61,7 +60,8 @@ void generateEmptyMap(CMapGenOptions & options, MainWindow * window) map->getEditManager()->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), options.getWidth(), options.getHeight())); map->getEditManager()->drawTerrain(Terrain("grass"), &CRandomGenerator::getDefault()); - window->controller.setMap(std::move(map)); + //window->controller.setMap(std::move(map)); + return std::move(map); } void WindowNewMap::on_okButtong_clicked() @@ -87,7 +87,8 @@ void WindowNewMap::on_okButtong_clicked() mapGenOptions.setWaterContent(water); mapGenOptions.setMonsterStrength(monster); - + + std::unique_ptr nmap; if(ui->randomMapCheck->isChecked()) { CMapGenerator generator(mapGenOptions); @@ -97,17 +98,26 @@ void WindowNewMap::on_okButtong_clicked() auto progressBarWnd = new GeneratorProgress(generator, this); progressBarWnd->show(); - { - std::thread generate(&::generateRandomMap, std::ref(generator), static_cast(parent())); - progressBarWnd->update(); - generate.join(); - } + + + //std::thread generate(&::generateRandomMap, std::ref(generator), static_cast(parent())); + //progressBarWnd->update(); + //generate.join(); + + //generateRandomMap(generator, static_cast(parent())); + auto f = std::async(std::launch::async, &CMapGenerator::generate, &generator); + progressBarWnd->update(); + nmap = f.get(); } else { - generateEmptyMap(mapGenOptions, static_cast(parent())); + auto f = std::async(std::launch::async, &::generateEmptyMap, std::ref(mapGenOptions)); + nmap = f.get(); + //nmap = generateEmptyMap(mapGenOptions, static_cast(parent())); } + + static_cast(parent())->controller.setMap(std::move(nmap)); static_cast(parent())->initializeMap(true); close(); }