Skip to content

Commit

Permalink
Gloom|GloomEd: Update map package contents; load in Gloom app
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent dfdec16 commit 28fd8e3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
43 changes: 40 additions & 3 deletions doomsday/apps/gloom/src/gloomapp.cpp
Expand Up @@ -22,10 +22,12 @@

#include <gloom/gloomworld.h>
#include <gloom/world/user.h>
#include <gloom/world/map.h>

#include <doomsday/DataBundle>

#include <de/Beacon>
#include <de/DirectoryFeed>
#include <de/DisplayMode>
#include <de/FileSystem>
#include <de/Info>
Expand All @@ -47,6 +49,7 @@ DE_PIMPL(GloomApp)
std::unique_ptr<AppWindowSystem> winSys;
std::unique_ptr<AudioSystem> audioSys;
std::unique_ptr<GloomWorld> world;
String currentMap;

Impl(Public *i) : Base(i)
{
Expand Down Expand Up @@ -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<Impl *>(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())
{
Expand All @@ -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"]);
}
}
}
Expand All @@ -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<const File>(asset.absolutePath("path")));
}
world->setMap(loadedMap);
}
};

GloomApp::GloomApp(const StringList &args)
Expand Down
29 changes: 25 additions & 4 deletions doomsday/apps/gloomed/src/editor.cpp
Expand Up @@ -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)
Expand All @@ -1209,12 +1209,33 @@ DE_PIMPL(Editor)
}

// Check that the maps.dei includes this map.
if (const auto *mapsInfoFile = root.tryLocate<const File>("maps.dei"))
{
Info mapsInfo(*mapsInfoFile);
if (mapsInfo.root().contains(mapId))
const auto *mapsInfoFile = root.tryLocate<File>("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();
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion doomsday/apps/gloomed/src/main.cpp
Expand Up @@ -26,6 +26,7 @@
#include <de/Beacon>
#include <de/CommandLine>
#include <de/EmbeddedApp>
#include <de/FileSystem>
#include <de/EventLoop>
#include <de/Loop>
#include <de/Info>
Expand Down Expand Up @@ -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<const Folder>("/home").correspondingNativePath().c_str()));
return 0;
},
[](int) {
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/gloom/src/world/mapimport.cpp
Expand Up @@ -378,7 +378,7 @@ Map &MapImport::map()

String MapImport::mapId() const
{
return "map." + d->mapId;
return d->mapId;
}

StringList MapImport::materials() const
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 28fd8e3

Please sign in to comment.