Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|Plugins: Use C++11 for iterating plugin hooks
One can now use a C++11 lambda for iterating through plugin hooks,
allowing for more flexible ways of executing the hook functions,
interpreting their return value, aborting early/processing a subset
of the hooks, etc...

The unused mechanism for exclusive hooks was removed.
The MAX_HOOKS per hook-type fixed limit was removed.
  • Loading branch information
danij-deng committed Jul 31, 2015
1 parent 89dbb61 commit a587725
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 273 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/dd_loop.cpp
Expand Up @@ -250,7 +250,7 @@ static void baseTicker(timespan_t time)
}

// Plugins tick always.
DoomsdayApp::plugins().callHooks(HOOK_TICKER, 0, &time);
DoomsdayApp::plugins().callAllHooks(HOOK_TICKER, 0, &time);

// The netcode gets to tick, too.
Net_Ticker(time);
Expand Down
7 changes: 4 additions & 3 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -1091,7 +1091,7 @@ static dint DD_ActivateGameWorker(void *context)
if(App_GameLoaded())
{
// Any game initialization hooks?
plugins.callHooks(HOOK_GAME_INIT, 0, 0);
plugins.callAllHooks(HOOK_GAME_INIT);

if(gx.PreInit)
{
Expand Down Expand Up @@ -2021,7 +2021,7 @@ static dint DD_StartupWorker(void * /*context*/)
Con_SetProgress(10);

// Any startup hooks?
DoomsdayApp::plugins().callHooks(HOOK_STARTUP, 0, 0);
DoomsdayApp::plugins().callAllHooks(HOOK_STARTUP);
Con_SetProgress(20);

// Was the change to userdir OK?
Expand Down Expand Up @@ -2105,7 +2105,8 @@ static dint DD_StartupWorker(void * /*context*/)
}
Con_SetProgress(199);

DoomsdayApp::plugins().callHooks(HOOK_INIT, 0, 0); // Any initialization hooks?
// Any initialization hooks?
DoomsdayApp::plugins().callAllHooks(HOOK_INIT);
Con_SetProgress(200);

#ifdef WIN32
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/def_main.cpp
Expand Up @@ -472,7 +472,7 @@ static void translateMapInfos(QStringList const &mapInfoUrns, String &xlat, Stri
try
{
Str_Set(&parm.paths, delimitedPaths.toUtf8().constData());
if(DoomsdayApp::plugins().callHooks(HOOK_MAPINFO_CONVERT, 0, &parm))
if(DoomsdayApp::plugins().callAllHooks(HOOK_MAPINFO_CONVERT, 0, &parm))
{
xlat = Str_Text(&parm.translated);
xlatCustom = Str_Text(&parm.translatedCustom);
Expand Down Expand Up @@ -1157,7 +1157,7 @@ void Def_Read()
readAllDefinitions();

// Any definition hooks?
DoomsdayApp::plugins().callHooks(HOOK_DEFS, 0, &defs);
DoomsdayApp::plugins().callAllHooks(HOOK_DEFS, 0, &defs);

#ifdef __CLIENT__
// Composite fonts.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/network/net_demo.cpp
Expand Up @@ -358,7 +358,7 @@ dd_bool Demo_ReadPacket()
{
Demo_StopPlayback();
// Any interested parties?
DoomsdayApp::plugins().callHooks(HOOK_DEMO_STOP, false, 0);
DoomsdayApp::plugins().callAllHooks(HOOK_DEMO_STOP);
return false;
}

Expand Down Expand Up @@ -672,7 +672,7 @@ D_CMD(StopDemo)
// Aborted.
Demo_StopPlayback();
// Any interested parties?
DoomsdayApp::plugins().callHooks(HOOK_DEMO_STOP, true, 0);
DoomsdayApp::plugins().callAllHooks(HOOK_DEMO_STOP, true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/viewports.cpp
Expand Up @@ -348,7 +348,7 @@ void R_UpdateViewPortGeometry(viewport_t *port, dint col, dint row)
p.geometry.size.width = port->geometry.width();
p.geometry.size.height = port->geometry.height();

DoomsdayApp::plugins().callHooks(HOOK_VIEWPORT_RESHAPE, port->console, (void *)&p);
DoomsdayApp::plugins().callAllHooks(HOOK_VIEWPORT_RESHAPE, port->console, (void *)&p);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/resource/resourcesystem.cpp
Expand Up @@ -2191,7 +2191,7 @@ DENG2_PIMPL(ResourceSystem)

void runTask()
{
DoomsdayApp::plugins().callHooks(HOOK_SAVEGAME_CONVERT, 0, &parm);
DoomsdayApp::plugins().callAllHooks(HOOK_SAVEGAME_CONVERT, 0, &parm);
}
};
TaskPool convertSavegameTasks;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp
Expand Up @@ -485,7 +485,7 @@ DENG2_PIMPL(FinaleInterpreter)
#endif

// Any hooks?
DoomsdayApp::plugins().callHooks(HOOK_FINALE_SCRIPT_STOP, id, 0);
DoomsdayApp::plugins().callAllHooks(HOOK_FINALE_SCRIPT_STOP, id);
}

bool atEnd() const
Expand Down Expand Up @@ -933,7 +933,7 @@ void FinaleInterpreter::loadScript(char const *script)
}

// Any hooks?
DoomsdayApp::plugins().callHooks(HOOK_FINALE_SCRIPT_BEGIN, d->id, 0);
DoomsdayApp::plugins().callAllHooks(HOOK_FINALE_SCRIPT_BEGIN, d->id);
}

void FinaleInterpreter::resume()
Expand Down Expand Up @@ -1011,7 +1011,7 @@ static bool runOneTick(FinaleInterpreter &fi)
de::zap(parm);
parm.runTick = true;
parm.canSkip = fi.canSkip();
DoomsdayApp::plugins().callHooks(HOOK_FINALE_SCRIPT_TICKER, fi.id(), &parm);
DoomsdayApp::plugins().callAllHooks(HOOK_FINALE_SCRIPT_TICKER, fi.id(), &parm);
return parm.runTick;
}

Expand Down Expand Up @@ -1532,7 +1532,7 @@ DEFFC(If)
ddhook_finale_script_evalif_paramaters_t p; de::zap(p);
p.token = token;
p.returnVal = 0;
if(DoomsdayApp::plugins().callHooks(HOOK_FINALE_EVAL_IF, fi.id(), (void *) &p))
if(DoomsdayApp::plugins().callAllHooks(HOOK_FINALE_EVAL_IF, fi.id(), (void *) &p))
{
val = p.returnVal;
LOG_SCR_XVERBOSE("HOOK_FINALE_EVAL_IF: %s => %i") << token << val;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/world/worldsystem.cpp
Expand Up @@ -370,8 +370,8 @@ DENG2_PIMPL(WorldSystem)
// Ask each converter in turn whether the map format is recognizable
// and if so to interpret and transfer it to us via the runtime map
// editing interface.
if(!DoomsdayApp::plugins().callHooks(HOOK_MAP_CONVERT, 0,
const_cast<Id1MapRecognizer *>(&mapManifest.recognizer())))
if(!DoomsdayApp::plugins().callAllHooks(HOOK_MAP_CONVERT, 0,
const_cast<Id1MapRecognizer *>(&mapManifest.recognizer())))
return nullptr;

// A converter signalled success.
Expand Down
27 changes: 13 additions & 14 deletions doomsday/apps/libdoomsday/include/doomsday/library.h
@@ -1,6 +1,5 @@
/**
* @file library.h
* Dynamic libraries. @ingroup base
/** @file library.h Dynamic libraries.
* @ingroup base
*
* These functions provide roughly the same functionality as the ltdl library.
* Since the ltdl library appears to be broken on Mac OS X, these will be used
Expand All @@ -14,8 +13,8 @@
*
* @todo Implement and use this class for Windows.
*
* @authors Copyright © 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2009-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2015 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2009-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -80,17 +79,17 @@ LIBDOOMSDAY_PUBLIC void Library_ReleaseGames(void);
* that value is returned instead.
*/
LIBDOOMSDAY_PUBLIC
int Library_IterateAvailableLibraries(int (*func)(void *libraryFile, const char* fileName,
const char* absPath, void* data), void* data);
int Library_IterateAvailableLibraries(int (*func)(void *libraryFile, char const *fileName,
char const *absPath, void *data), void *data);

/**
* Loads a dynamic library.
*
* @param filePath Absolute path of the library to open.
*/
LIBDOOMSDAY_PUBLIC Library* Library_New(const char* filePath);
LIBDOOMSDAY_PUBLIC Library *Library_New(char const *filePath);

LIBDOOMSDAY_PUBLIC void Library_Delete(Library* lib);
LIBDOOMSDAY_PUBLIC void Library_Delete(Library *lib);

/**
* Returns the type identifier of the library.
Expand All @@ -100,7 +99,7 @@ LIBDOOMSDAY_PUBLIC void Library_Delete(Library* lib);
*
* @return Type identifier string, e.g., "deng-plugin/game".
*/
LIBDOOMSDAY_PUBLIC const char* Library_Type(const Library* lib);
LIBDOOMSDAY_PUBLIC char const *Library_Type(Library const *lib);

/**
* Looks up a symbol from the library.
Expand All @@ -111,15 +110,15 @@ LIBDOOMSDAY_PUBLIC const char* Library_Type(const Library* lib);
* @return @c NULL if the symbol is not defined. Otherwise the address of
* the symbol.
*/
LIBDOOMSDAY_PUBLIC void* Library_Symbol(Library* lib, const char* symbolName);
LIBDOOMSDAY_PUBLIC void *Library_Symbol(Library *lib, char const *symbolName);

#ifdef __cplusplus
} // extern "C"
} // extern "C"
#endif

#ifdef __cplusplus
#include <de/LibraryFile>
LIBDOOMSDAY_PUBLIC de::LibraryFile& Library_File(Library* lib);
LIBDOOMSDAY_PUBLIC de::LibraryFile &Library_File(Library *lib);
#endif

#endif /* LIBDOOMSDAY_LIBRARY_H */
#endif // LIBDOOMSDAY_LIBRARY_H

0 comments on commit a587725

Please sign in to comment.