Skip to content

Commit

Permalink
GloomEd: Use EmbeddedApp and DoomsdayApp for handling data bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 0093b78 commit 2f34275
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
14 changes: 7 additions & 7 deletions doomsday/apps/gloomed/src/editor.cpp
Expand Up @@ -53,13 +53,13 @@ struct EntityType {
QString label;
};
static const QMap<Entity::Type, QString> entityMetadata {
std::make_pair(Entity::Light, QString("Light")),
std::make_pair(Entity::Spotlight, QString("Spotlight")),
std::make_pair(Entity::Tree1, QString("Tree1")),
std::make_pair(Entity::Tree2, QString("Tree2")),
std::make_pair(Entity::Tree3, QString("Tree3")),
std::make_pair(Entity::TestSphere, QString("Test Sphere")),
std::make_pair(Entity::Buggy, QString("Buggy"))
{Entity::Light, QString("Light")},
{Entity::Spotlight, QString("Spotlight")},
{Entity::Tree1, QString("Tree1")},
{Entity::Tree2, QString("Tree2")},
{Entity::Tree3, QString("Tree3")},
{Entity::TestSphere, QString("Test Sphere")},
{Entity::Buggy, QString("Buggy")}
};

enum Direction {
Expand Down
60 changes: 42 additions & 18 deletions doomsday/apps/gloomed/src/main.cpp
Expand Up @@ -18,20 +18,31 @@

#include "editorwindow.h"
#include "utils.h"

#include <doomsday/DoomsdayApp>

#include <de/App>
#include <de/Beacon>
#include <de/CommandLine>
#include <de/EmbeddedApp>
#include <de/EventLoop>
#include <de/Loop>
#include <de/Info>

#include <QApplication>
#include <QMessageBox>
#include <QTimer>

using namespace de;

static const duint16 COMMAND_PORT = 14666;
struct GloomCommander;

static GloomCommander *gloomCommander;
static const duint16 COMMAND_PORT = 14666;

/**
* Sends commands to the Gloom viewer app and listens to beacon messages.
*/
struct GloomCommander : DE_OBSERVES(Beacon, Discovery)
{
cplus::ref<iProcess> proc;
Expand All @@ -45,6 +56,8 @@ struct GloomCommander : DE_OBSERVES(Beacon, Discovery)

void beaconFoundHost(const Address &host, const Block &message) override
{
if (!address.isNull()) return; // Ignore additional replies.

qDebug("GloomEd beacon found:%s [%s]", host.asText().c_str(), message.c_str());
if (message.beginsWith(DE_STR("GloomApp:")))
{
Expand All @@ -57,8 +70,10 @@ struct GloomCommander : DE_OBSERVES(Beacon, Discovery)
}
}
};
static GloomCommander *gloomCommander;

/**
* Launch the Gloom viewer, if one is not already running.
*/
static bool launchGloom()
{
if (gloomCommander)
Expand All @@ -83,26 +98,27 @@ static bool launchGloom()
return bool(gloomCommander->proc);
}

struct EmbeddedApp : public App
struct EditorApp : public EmbeddedApp, public DoomsdayApp
{
EventLoop deEventLoop{EventLoop::Manual};
Loop deLoop;

EmbeddedApp(const StringList &args) : App(args)
EditorApp(const StringList &args)
: EmbeddedApp(args)
, DoomsdayApp(nullptr,
DoomsdayApp::DisableGameProfiles |
DoomsdayApp::DisablePersistentConfig |
DoomsdayApp::DisableSaveGames)
{}

NativePath appDataPath() const
void initialize()
{
return NativePath::homePath() / unixHomeFolderName();
initSubsystems(DisablePersistentData | DisablePlugins);
DoomsdayApp::initialize();
}

void processEvents()
void checkPackageCompatibility(const de::StringList &,
const de::String &,
const std::function<void()> &finalizeFunc)
{
// Manually handle events and loop iteration callbacks.
deLoop.iterate();
deEventLoop.processQueuedEvents();
fflush(stdout);
fflush(stderr);
finalizeFunc();
}
};

Expand Down Expand Up @@ -134,7 +150,7 @@ int main(int argc, char **argv)
}
catch (const Error &er)
{
warning("Map build error: %s", er.asPlainText().c_str());
qWarning("Map build error: %s", er.asPlainText().c_str());
}
});

Expand All @@ -144,8 +160,16 @@ int main(int argc, char **argv)
* available and active. Use a QTimer to continually check for events and perform
* loop iteration.
*/
EmbeddedApp deApp(makeList(argc, argv));
deApp.initSubsystems(App::DisablePersistentData | App::DisablePlugins);
EditorApp deApp(makeList(argc, argv));
{
auto &amd = deApp.metadata();
amd.set(App::APP_NAME, convert(app.applicationName()));
amd.set(App::APP_VERSION, convert(app.applicationVersion()));
amd.set(App::ORG_NAME, convert(app.organizationName()));
amd.set(App::ORG_DOMAIN, convert(app.organizationDomain()));
amd.set(App::UNIX_HOME, ".gloomed");
}
deApp.initialize();
QTimer deTimer;
QObject::connect(&deTimer, &QTimer::timeout, [&deApp]() { deApp.processEvents(); });
deTimer.start(100);
Expand Down

0 comments on commit 2f34275

Please sign in to comment.