Skip to content

Commit

Permalink
Refactor|libcommon: Further simplified acs::System
Browse files Browse the repository at this point in the history
Since the recent introduction of acs::Module there is no longer a
need for the acs::System pimpl struct to hold a reference to the
public instance.
  • Loading branch information
danij-deng committed Feb 24, 2015
1 parent 3473044 commit 3a37d7e
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions doomsday/plugins/common/src/acs/system.cpp
Expand Up @@ -24,7 +24,6 @@
#include <de/ISerializable>
#include <de/Log>
#include <de/NativePath>
#include "acs/interpreter.h"
#include "acs/module.h"
#include "acs/script.h"
#include "gamesession.h"
Expand All @@ -33,7 +32,7 @@ using namespace de;

namespace acs {

DENG2_PIMPL(System)
DENG2_PIMPL_NOREF(System)
{
std::unique_ptr<Module> currentModule;
QList<Script *> scripts; ///< Scripts for the current module (if any).
Expand Down Expand Up @@ -83,7 +82,6 @@ DENG2_PIMPL(System)
};
QList<ScriptStartTask *> tasks;

Instance(Public *i) : Base(i) {}
~Instance()
{
clearTasks();
Expand Down Expand Up @@ -116,31 +114,9 @@ DENG2_PIMPL(System)
{
qDeleteAll(tasks); tasks.clear();
}

void runAllTasks(de::Uri const &mapUri)
{
for(int i = 0; i < tasks.count(); ++i)
{
ScriptStartTask *task = tasks[i];
if(task->mapUri != mapUri) continue;

if(self.hasScript(task->scriptNumber))
{
self.script(task->scriptNumber)
.start(task->scriptArgs, nullptr, nullptr, 0, TICSPERSEC);
}
else
{
LOG_SCR_WARNING("Unknown script #%i") << task->scriptNumber;
}

delete tasks.takeAt(i);
i -= 1;
}
}
};

System::System() : d(new Instance(this))
System::System() : d(new Instance)
{
mapVars.fill(0);
worldVars.fill(0);
Expand All @@ -166,7 +142,7 @@ void System::loadModuleForMap(de::Uri const &mapUri)

/// @todo Should be using MapDef here...
lumpnum_t const markerLumpNum = CentralLumpIndex().findLast(mapUri.path() + ".lmp");
lumpnum_t moduleLumpNum = markerLumpNum + 11 /*ML_BEHAVIOR*/;
lumpnum_t const moduleLumpNum = markerLumpNum + 11 /*ML_BEHAVIOR*/;
if(!CentralLumpIndex().hasLump(moduleLumpNum)) return;

de::File1 &file = CentralLumpIndex()[moduleLumpNum];
Expand Down Expand Up @@ -263,9 +239,9 @@ bool System::deferScriptStart(de::Uri const &mapUri, int scriptNumber,
return true;
}

de::Block System::serializeWorldState() const
Block System::serializeWorldState() const
{
de::Block data;
Block data;
de::Writer writer(data);

// Write the world-global variable namespace.
Expand Down Expand Up @@ -318,7 +294,24 @@ void System::readMapState(MapStateReader *msr)
void System::runDeferredTasks(de::Uri const &mapUri)
{
LOG_AS("acs::System");
d->runAllTasks(mapUri);
for(int i = 0; i < d->tasks.count(); ++i)
{
Instance::ScriptStartTask *task = d->tasks[i];
if(task->mapUri != mapUri) continue;

if(hasScript(task->scriptNumber))
{
script(task->scriptNumber)
.start(task->scriptArgs, nullptr, nullptr, 0, TICSPERSEC);
}
else
{
LOG_SCR_WARNING("Unknown script #%i") << task->scriptNumber;
}

delete d->tasks.takeAt(i);
i -= 1;
}
}

void System::worldSystemMapChanged()
Expand Down

0 comments on commit 3a37d7e

Please sign in to comment.