Skip to content

Commit

Permalink
Cleanup: Renamed LoopCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 937cd52 commit fa783e6
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/network/serverlink.h
Expand Up @@ -71,7 +71,7 @@ class ServerLink : public de::shell::AbstractLink
* If information about the server at @a address is not currently available, a
* discovery query is sent to the address.
*
* After the server's profile is available, a callback is made via LoopCallback.
* After the server's profile is available, a callback is made via Dispatch.
*
* @param address Server address.
* @param resultHandler Callback for receiving the server profile. ServerLink
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/network/serverlink.cpp
Expand Up @@ -82,7 +82,7 @@ DE_PIMPL(ServerLink)
std::function<void (GameProfile const *)> profileResultCallback;
std::function<void (Address, GameProfile const *)> profileResultCallbackWithAddress;
shell::PackageDownloader downloader;
LoopCallback deferred; // for deferred actions
Dispatch deferred; // for deferred actions

Impl(Public *i, Flags flags)
: Base(i)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/render/environ.cpp
Expand Up @@ -43,7 +43,7 @@ DE_PIMPL(Environment)
enum { Interior, Exterior };

filesys::AssetObserver observer { "texture\\.reflect\\..*" };
LoopCallback mainCall;
Dispatch dispatch;

struct EnvMaps
{
Expand Down Expand Up @@ -150,7 +150,7 @@ DE_PIMPL(Environment)

void worldMapChanged()
{
mainCall.enqueue([this] () { loadTexturesForCurrentMap(); });
dispatch += [this]() { loadTexturesForCurrentMap(); };
}

void loadTexturesForCurrentMap()
Expand Down
Expand Up @@ -44,7 +44,7 @@ DE_PIMPL(PackageCompatibilityDialog)
ui::ListData actions;
ProgressWidget *updating;
bool ignoreCheck = false;
LoopCallback mainCall;
Dispatch mainCall;

Impl(Public *i) : Base(i)
{
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/ui/home/gamecolumnwidget.cpp
Expand Up @@ -103,7 +103,7 @@ DE_GUI_PIMPL(GameColumnWidget)
DE_CAST_METHODS()
};

LoopCallback mainCall;
Dispatch dispatch;
String gameFamily;
SaveListData const &savedItems;
HomeMenuWidget *menu;
Expand Down Expand Up @@ -220,7 +220,7 @@ DE_GUI_PIMPL(GameColumnWidget)
void profileAdded(Profiles::AbstractProfile &prof) override
{
// This may be called from another thread.
mainCall.enqueue([this, &prof] ()
dispatch += [this, &prof] ()
{
if (addItemForProfile(prof.as<GameProfile>()))
{
Expand All @@ -231,7 +231,7 @@ DE_GUI_PIMPL(GameColumnWidget)
DE_ASSERT(newItem);
menu->setSelectedIndex(menu->items().find(*newItem));
}
});
};
}

void profileChanged(Profiles::AbstractProfile &) override
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/ui/home/homewidget.cpp
Expand Up @@ -63,7 +63,7 @@ DE_GUI_PIMPL(HomeWidget)
Column(ColumnWidget *w, Variable *var) : widget(w), configVar(var) {}
};

LoopCallback mainCall;
Dispatch dispatch;
SaveListData savedItems; ///< All the available save games as items.

dsize visibleColumnCount = 2;
Expand Down Expand Up @@ -137,7 +137,7 @@ DE_GUI_PIMPL(HomeWidget)
});

// The task bar is created later.
mainCall.enqueue([this]() {
dispatch += [this]() {
ClientWindow::main().taskBar().audienceForOpen() += [this]() {
taskBarHintButton->disable();
taskBarHintButton->setOpacity(0, 0.25);
Expand All @@ -146,7 +146,7 @@ DE_GUI_PIMPL(HomeWidget)
taskBarHintButton->enable();
taskBarHintButton->setOpacity(.66f, 0.5);
};
});
};

// The navigation buttons should be hidden with a delay or otherwise the user
// may inadvertely click on them right after they're gone.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/home/packagescolumnwidget.cpp
Expand Up @@ -48,7 +48,7 @@ DE_GUI_PIMPL(PackagesColumnWidget)
LabelWidget * countLabel;
ButtonWidget * folderOptionsButton;
ui::ListData actions;
LoopCallback mainCall;
Dispatch mainCall;
int totalPackageCount = 0;

Impl(Public *i) : Base(i)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/nativemenu.cpp
Expand Up @@ -35,7 +35,7 @@ DE_PIMPL(NativeMenu)
// QMenuBar *menuBar = nullptr;
// QMenu *helpMenu = nullptr;
// QMenu *gameMenu = nullptr;
LoopCallback mainCall;
Dispatch dispatch;

Impl(Public *i) : Base(i)
{
Expand Down
10 changes: 5 additions & 5 deletions doomsday/apps/client/src/ui/savelistdata.cpp
Expand Up @@ -31,7 +31,7 @@ DE_PIMPL(SaveListData)
, DE_OBSERVES(FileIndex, Addition)
, DE_OBSERVES(FileIndex, Removal)
{
LoopCallback mainCall;
Dispatch dispatch;

Impl(Public *i) : Base(i)
{
Expand All @@ -49,18 +49,18 @@ DE_PIMPL(SaveListData)
GameStateFolder const &saveFolder = file.as<GameStateFolder>();
if (shouldAddFolder(saveFolder))
{
mainCall.enqueue([this, &saveFolder] ()
dispatch += [this, &saveFolder] ()
{
// Needs to be added.
self().append(new SaveItem(saveFolder));
});
};
}
}

void fileRemoved(File const &, FileIndex const &)
{
// Remove obsolete entries.
mainCall.enqueue([this] ()
dispatch += [this] ()
{
for (ui::Data::Pos idx = self().size() - 1; idx < self().size(); --idx)
{
Expand All @@ -69,7 +69,7 @@ DE_PIMPL(SaveListData)
self().remove(idx);
}
}
});
};
}

void addAllFromIndex()
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -460,8 +460,8 @@ DE_GUI_PIMPL(PackagesWidget)

using Strings = std::set<String>;

LoopCallback mainCall;
LoopCallback mainCallForIdentify;
Dispatch dispatch;
Dispatch mainCallForIdentify;

// Search filter:
LineEditWidget *search;
Expand Down Expand Up @@ -750,12 +750,12 @@ DE_GUI_PIMPL(PackagesWidget)
{
// Refiltering will potentially alter the widget tree, so doing it during
// event handling is not a great idea.
mainCall.enqueue([this]() {
dispatch += [this]() {
/// @todo Parse quoted terms. -jk
setFilterTerms(search->text().strip().split(RegExp::WHITESPACE));

menu->setOpacity(1.f, REFILTER_DELAY);
});
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/comms/src/packagedownloader.cpp
Expand Up @@ -48,7 +48,7 @@ DE_PIMPL(PackageDownloader)
AssetGroup downloads;
Hash<IDownloadable *, Rangei64> downloadBytes;
std::function<void()> postDownloadCallback;
LoopCallback deferred;
Dispatch deferred;

Impl(Public *i) : Base(i) {}

Expand Down
13 changes: 9 additions & 4 deletions doomsday/libs/core/include/de/core/loop.h
Expand Up @@ -103,20 +103,25 @@ class DE_PUBLIC Loop
};

/**
* Utility for deferring callbacks via the Loop.
* Utility for deferring callbacks via the Loop to be called later in the main thread.
*
* Use this as a member in the object where the callback occurs in, so that if the
* Dispatch is deleted, the callbacks will be cancelled.
*/
class DE_PUBLIC LoopCallback : public Lockable, DE_OBSERVES(Loop, Iteration)
class DE_PUBLIC Dispatch : public Lockable, DE_OBSERVES(Loop, Iteration)
{
public:
typedef std::function<void ()> Callback;

LoopCallback();
~LoopCallback() override;
Dispatch();
~Dispatch() override;

bool isEmpty() const;
inline operator bool() const { return !isEmpty(); }

void enqueue(const Callback& func);
inline Dispatch &operator+=(const Callback &func) { enqueue(func); return *this; }

void loopIteration() override;

private:
Expand Down
22 changes: 11 additions & 11 deletions doomsday/libs/core/src/core/loop.cpp
Expand Up @@ -31,10 +31,10 @@ static Loop *loopSingleton = nullptr;

DE_PIMPL(Loop)
{
TimeSpan interval;
bool running;
Timer timer;
LoopCallback mainCall;
TimeSpan interval;
bool running;
Timer timer;
Dispatch dispatch;

Impl(Public *i) : Base(i), running(false)
{
Expand Down Expand Up @@ -118,7 +118,7 @@ void Loop::mainCall(const std::function<void ()> &func) // static
}
else
{
Loop::get().d->mainCall.enqueue(func);
Loop::get().d->dispatch.enqueue(func);
}
}

Expand Down Expand Up @@ -147,22 +147,22 @@ void Loop::nextLoopIteration()
}
}

// LoopCallback -------------------------------------------------------------------------
// Dispatch -------------------------------------------------------------------------

LoopCallback::LoopCallback()
Dispatch::Dispatch()
{}

LoopCallback::~LoopCallback()
Dispatch::~Dispatch()
{}

bool LoopCallback::isEmpty() const
bool Dispatch::isEmpty() const
{
DE_GUARD(this);

return _funcs.isEmpty();
}

void LoopCallback::enqueue(const Callback& func)
void Dispatch::enqueue(const Callback& func)
{
DE_GUARD(this);

Expand All @@ -171,7 +171,7 @@ void LoopCallback::enqueue(const Callback& func)
Loop::get().audienceForIteration() += this;
}

void LoopCallback::loopIteration()
void Dispatch::loopIteration()
{
List<Callback> funcs;

Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/data/bank.cpp
Expand Up @@ -544,7 +544,7 @@ DE_PIMPL(Bank)
DataTree items;
TaskPool jobs;
NotifyQueue notifications;
LoopCallback mainCall;
Dispatch dispatch;

Impl(Public *i, char const *name, Flags const &flg)
: Base(i)
Expand Down Expand Up @@ -690,7 +690,7 @@ DE_PIMPL(Bank)
notifications.put(new Notification(notif));
if (isThreaded())
{
mainCall.enqueue([this] () { performNotifications(); });
dispatch += [this] () { performNotifications(); };
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/doomsday/src/doomsdayapp.cpp
Expand Up @@ -150,7 +150,7 @@ DE_PIMPL(DoomsdayApp)
res::Bundles dataBundles;
shell::PackageDownloader packageDownloader;
SaveGames saveGames;
LoopCallback mainCall;
Dispatch mainCall;
Timer configSaveTimer;

// #ifdef WIN32
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libs/doomsday/src/games.cpp
Expand Up @@ -50,7 +50,7 @@ DE_PIMPL(Games)

Hash<String, Game *> idLookup; // not owned, lower case

LoopCallback mainCall;
Dispatch dispatch;
Set<Game const *> lastCheckedPlayable; // determines when notification sent

/**
Expand Down Expand Up @@ -131,9 +131,9 @@ DE_PIMPL(Games)

void dataBundlesIdentified()
{
if (!mainCall)
if (!dispatch)
{
mainCall.enqueue([this] () { self().checkReadiness(); });
dispatch += [this]() { self().checkReadiness(); };
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/doomsday/src/resource/resources.cpp
Expand Up @@ -95,7 +95,7 @@ DE_PIMPL(Resources)
res::Textures textures;
res::AnimGroups animGroups;
res::Sprites sprites;
LoopCallback deferredReset;
Dispatch deferredReset;

Impl(Public *i)
: Base(i)
Expand Down
10 changes: 3 additions & 7 deletions doomsday/libs/gamekit/libs/common/src/game/saveslots.cpp
Expand Up @@ -223,7 +223,7 @@ DE_PIMPL(SaveSlots)
typedef std::map<String, Slot *> Slots;
typedef std::pair<String, Slot *> SlotItem;
Slots sslots;
LoopCallback mainCall;
Dispatch dispatch;

Impl(Public *i) : Base(i)
{
Expand Down Expand Up @@ -271,17 +271,13 @@ DE_PIMPL(SaveSlots)

void fileAdded(File const &saveFolder, FileIndex const &)
{
mainCall.enqueue([this, &saveFolder] ()
dispatch += [this, &saveFolder] ()
{
//for (auto i = index.begin(); i != index.end(); ++i)
//{
//auto &saveFolder = i->second->as<GameStateFolder>();
if (SaveSlot *sslot = slotBySavePath(saveFolder.path()))
{
sslot->setGameStateFolder(const_cast<GameStateFolder *>(&saveFolder.as<GameStateFolder>()));
}
//}
});
};
}

void fileRemoved(File const &saveFolder, FileIndex const &)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/gui/src/graphics/glwindow.cpp
Expand Up @@ -44,7 +44,7 @@ DE_PIMPL(GLWindow)
SDL_Window * window = nullptr;
SDL_GLContext glContext = nullptr;

LoopCallback mainCall;
Dispatch mainCall;
GLFramebuffer backing;
WindowEventHandler *handler = nullptr; ///< Event handler.
bool initialized = false;
Expand Down

0 comments on commit fa783e6

Please sign in to comment.