Skip to content

Commit

Permalink
Fixed|Console|libdoomsday: Adding all games as known words
Browse files Browse the repository at this point in the history
Added a callback for app-specific known words. libdoomsday has no
access to the set of all games at the moment.
  • Loading branch information
skyjake committed May 4, 2014
1 parent 713409f commit 73094ff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
10 changes: 10 additions & 0 deletions doomsday/client/src/dd_pinit.cpp
Expand Up @@ -115,10 +115,20 @@ void DD_InitCommandLine()
CommandLine_Alias("-verbose", "-v");
}

static void App_AddKnownWords()
{
// Add games as known words.
foreach(Game *game, App_Games().all())
{
Con_AddKnownWord(WT_GAME, game);
}
}

void DD_ConsoleInit()
{
// Get the console online ASAP.
Con_Init();
Con_SetApplicationKnownWordCallback(App_AddKnownWords);

LOG_NOTE("Executable: " DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_FULLTEXT);

Expand Down
8 changes: 8 additions & 0 deletions doomsday/libdoomsday/include/doomsday/console/knownword.h
Expand Up @@ -49,6 +49,14 @@ void Con_UpdateKnownWords();

void Con_ClearKnownWords();

/**
* Sets a callback that is called whenever the set of known words needs updating.
* The callback should add all the known words using Con_AddKnownWord.
*
* @param callback Known word addition callback.
*/
LIBDOOMSDAY_PUBLIC void Con_SetApplicationKnownWordCallback(void (*callback)());

LIBDOOMSDAY_PUBLIC void Con_AddKnownWord(knownwordtype_t type, void *ptr);

/**
Expand Down
18 changes: 9 additions & 9 deletions doomsday/libdoomsday/src/console/knownword.cpp
Expand Up @@ -40,6 +40,8 @@ using namespace de;
static QList<knownword_t> knownWords;
static dd_bool knownWordsNeedUpdate;

static void (*appWordsCallback)();

void Con_ClearKnownWords(void)
{
knownWords.clear();
Expand Down Expand Up @@ -176,17 +178,10 @@ static void updateKnownWords(void)
// Add aliases?
Con_AddKnownWordsForAliases();

/// @todo Add a callback for app-specific known words. -jk

#if 0 // we don't have access to the games list!
// Add games?
foreach(Game *game, App_Games().all())
if(appWordsCallback)
{
knownWords[knownWordIdx].type = WT_GAME;
knownWords[knownWordIdx].data = game;
++knownWordIdx;
appWordsCallback();
}
#endif

// Sort it so we get nice alphabetical word completions.
qSort(knownWords.begin(), knownWords.end(), compareKnownWordByName);
Expand Down Expand Up @@ -422,3 +417,8 @@ shell::Lexicon Con_Lexicon()
lexi.setAdditionalWordChars("-_.");
return lexi;
}

void Con_SetApplicationKnownWordCallback(void (*callback)())
{
appWordsCallback = callback;
}

0 comments on commit 73094ff

Please sign in to comment.