diff --git a/doomsday/apps/gloom/src/gloomapp.cpp b/doomsday/apps/gloom/src/gloomapp.cpp index 53a082376a..a723b05f4e 100644 --- a/doomsday/apps/gloom/src/gloomapp.cpp +++ b/doomsday/apps/gloom/src/gloomapp.cpp @@ -22,10 +22,12 @@ #include #include +#include #include #include +#include #include #include #include @@ -47,6 +49,7 @@ DE_PIMPL(GloomApp) std::unique_ptr winSys; std::unique_ptr audioSys; std::unique_ptr world; + String currentMap; Impl(Public *i) : Base(i) { @@ -92,9 +95,10 @@ DE_PIMPL(GloomApp) static void receivedRemoteCommand(iAny *, iDatagram *socket) { - while (String msgData = Block::take(receive_Datagram(socket, nullptr))) + auto *d = reinterpret_cast(userData_Object(socket)); + while (auto msgData = Block::take(receive_Datagram(socket, nullptr))) { - Loop::mainCall([msgData]() { + Loop::mainCall([d, msgData]() { const Info msg(msgData); for (const auto *elem : msg.root().contentsInOrder()) { @@ -105,7 +109,7 @@ DE_PIMPL(GloomApp) { if (block.name() == "loadmap") { - debug("load map: '%s'", block["package"].c_str()); + d->loadMapPackage(block["map"], block["package"], block["nativePath"]); } } } @@ -125,6 +129,39 @@ DE_PIMPL(GloomApp) self().shaders().addFromInfo(**i); } } + + void loadMapPackage(const String &mapId, const String &packageId, const NativePath &location) + { + debug("load map '%s' from package '%s' in '%s'", + mapId.c_str(), + packageId.c_str(), + location.c_str()); + + if (!mapId || !packageId || location.isEmpty() || !location.exists()) return; + + auto &pld = PackageLoader::get(); + + if (currentMap) + { + pld.unload(currentMap); + pld.refresh(); + currentMap.clear(); + } + + FS::get().makeFolderWithFeed("/remote/gloom", new DirectoryFeed(location)); + + pld.load(packageId); + pld.refresh(); + currentMap = packageId; + + // Load the map. + gloom::Map loadedMap; + { + const auto &asset = App::asset(DE_STR("map.") + mapId); + loadedMap.deserialize(FS::locate(asset.absolutePath("path"))); + } + world->setMap(loadedMap); + } }; GloomApp::GloomApp(const StringList &args) diff --git a/doomsday/apps/gloomed/src/editor.cpp b/doomsday/apps/gloomed/src/editor.cpp index 8ea2ace94c..17ecba767e 100644 --- a/doomsday/apps/gloomed/src/editor.cpp +++ b/doomsday/apps/gloomed/src/editor.cpp @@ -1184,7 +1184,7 @@ DE_PIMPL(Editor) { if (!mapId) { - mapId = convert(QInputDialog::getText(nullptr, "Export Package", "Map ID:")); + mapId = convert(QInputDialog::getText(nullptr, "Export Package", "Map ID:")).lower(); if (!mapId) return; } if (!packageName) @@ -1209,12 +1209,33 @@ DE_PIMPL(Editor) } // Check that the maps.dei includes this map. - if (const auto *mapsInfoFile = root.tryLocate("maps.dei")) { - Info mapsInfo(*mapsInfoFile); - if (mapsInfo.root().contains(mapId)) + const auto *mapsInfoFile = root.tryLocate("maps.dei"); + if (!mapsInfoFile) { + mapsInfoFile = &root.createFile("maps.dei"); + } + Info mapsInfo(*mapsInfoFile); + if (!mapsInfo.root().contains(DE_STR("map.") + mapId)) + { + const auto mpu = map.metersPerUnit(); + + // Append a new map asset. + String maps; + *mapsInfoFile >> maps; + maps += Stringf("asset map.%s {\n" + " path = \"maps/%s.gloommap\"\n" + " metersPerUnit <%.16f, %.16f, %.16f>\n" + "}\n", + mapId.c_str(), + mapId.c_str(), + mpu.x, + mpu.y, + mpu.z); + File &updated = root.replaceFile("maps.dei"); + updated << maps; + updated.flush(); } } } diff --git a/doomsday/apps/gloomed/src/main.cpp b/doomsday/apps/gloomed/src/main.cpp index a98dbcfa2c..b8329ecc72 100644 --- a/doomsday/apps/gloomed/src/main.cpp +++ b/doomsday/apps/gloomed/src/main.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -191,7 +192,10 @@ int main(int argc, char **argv) async( [&editor]() { gloomCommander->sendCommand( - Stringf("command loadmap{package=\"%s\"}", editor.packageName().c_str())); + Stringf("command loadmap{map:%s\npackage:%s\nnativePath:%s\n}", + editor.mapId().c_str(), + editor.packageName().c_str(), + FS::locate("/home").correspondingNativePath().c_str())); return 0; }, [](int) { diff --git a/doomsday/libs/gloom/src/world/mapimport.cpp b/doomsday/libs/gloom/src/world/mapimport.cpp index efcaac785d..5c04fac0e7 100644 --- a/doomsday/libs/gloom/src/world/mapimport.cpp +++ b/doomsday/libs/gloom/src/world/mapimport.cpp @@ -378,7 +378,7 @@ Map &MapImport::map() String MapImport::mapId() const { - return "map." + d->mapId; + return d->mapId; } StringList MapImport::materials() const @@ -438,7 +438,7 @@ void MapImport::exportPackage(const String &packageRootPath) const // Maps included in the pacakge. { File & f = root.replaceFile("maps.dei"); - String dei = "asset " + mapId() + " {\n" + String dei = "asset map." + mapId() + " {\n" " path = \"maps/" + d->mapId + ".gloommap\"\n" " metersPerUnit " + Stringf(