Skip to content

Commit

Permalink
Refactor: Rewrote the help text database (dd_help)
Browse files Browse the repository at this point in the history
dd_help.c was rewritten to use C++, libdeng2, and more efficient
data structures. It now also supports full Unicode text.

Updated the module's internal C API with modern conventions in mind
(the API itself was left unchanged).

Important note: the source data (cphelp.txt, conhelp.txt) is now read
directly from within the PK3s using libdeng2. Thus it is no longer
necessary to deploy them as "startupdata" in the installation.
  • Loading branch information
skyjake committed Dec 13, 2012
1 parent f05e497 commit 02664a8
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 377 deletions.
11 changes: 3 additions & 8 deletions doomsday/engine/engine.pro
Expand Up @@ -457,7 +457,7 @@ SOURCES += \
src/con_data.cpp \
src/con_main.c \
src/dd_games.cpp \
src/dd_help.c \
src/dd_help.cpp \
src/dd_init.cpp \
src/dd_loop.c \
src/dd_main.cpp \
Expand Down Expand Up @@ -658,9 +658,6 @@ mod.files = \
$$DENG_MODULES_DIR/Config.de \
$$DENG_MODULES_DIR/recutil.de

startupdata.files = \
data/cphelp.txt

# These fonts may be needed during the initial startup busy mode.
startupfonts.files = \
data/fonts/console11.dfn \
Expand Down Expand Up @@ -690,11 +687,10 @@ macx {

data.path = $${res.path}
mod.path = $${res.path}/modules
startupdata.path = $${res.path}/data
startupfonts.path = $${res.path}/data/fonts
startupgfx.path = $${res.path}/data/graphics

QMAKE_BUNDLE_DATA += mod res data startupfonts startupdata startupgfx
QMAKE_BUNDLE_DATA += mod res data startupfonts startupgfx

QMAKE_INFO_PLIST = ../build/mac/Info.plist

Expand Down Expand Up @@ -732,11 +728,10 @@ macx {

!macx {
# Common (non-Mac) parts of the installation.
INSTALLS += target data startupdata startupgfx startupfonts mod
INSTALLS += target data startupgfx startupfonts mod

target.path = $$DENG_BIN_DIR
data.path = $$DENG_DATA_DIR
startupdata.path = $$DENG_DATA_DIR
startupgfx.path = $$DENG_DATA_DIR/graphics
startupfonts.path = $$DENG_DATA_DIR/fonts
mod.path = $$DENG_BASE_DIR/modules
Expand Down
39 changes: 37 additions & 2 deletions doomsday/engine/include/dd_help.h
Expand Up @@ -33,6 +33,8 @@
extern "C" {
#endif

typedef void const *HelpNode;

// Help string types.
enum {
HST_DESCRIPTION,
Expand All @@ -44,12 +46,45 @@ enum {

void DH_Register(void);

/**
* Initializes the help string database. After which, attempts to read the
* engine's own help string file.
*/
void DD_InitHelp(void);

/**
* Attempts to read help strings from the game-specific help file.
*/
void DD_ReadGameHelp(void);

/**
* Shuts down the help string database. Frees all storage and destroys
* database itself.
*/
void DD_ShutdownHelp(void);

void* DH_Find(const char* id);
char* DH_GetString(void* found, int type);
/**
* Finds a node matching the ID. Use DH_GetString to read strings from it.
*
* @param id Help node ID to be searched for.
*
* @return Pointer to help data, if matched; otherwise @c NULL.
*/
HelpNode DH_Find(char const *id);

/**
* Return a string from within the helpnode. Strings are stored internally
* and indexed by their type (e.g. HST_DESCRIPTION).
*
* @param foundNode The helpnode to return the string from.
* @param type The string type (index) to look for within the node.
*
* @return Pointer to the found string; otherwise @c NULL. Note, may also
* return @c NULL, if passed an invalid helpnode ptr OR the help string
* database has not beeen initialized yet. The returned string is actually from
* an AutoStr; it will only be valid until the next garbage recycling.
*/
char const *DH_GetString(HelpNode found, int type);

#ifdef __cplusplus
} // extern "C"
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/src/con_data.cpp
Expand Up @@ -1150,7 +1150,7 @@ void Con_PrintCCmdUsage(ccmd_t* ccmd, boolean printInfo)
if(printInfo)
{
// Check for extra info about this ccmd's usage.
char* info = DH_GetString(DH_Find(ccmd->name), HST_INFO);
char const *info = DH_GetString(DH_Find(ccmd->name), HST_INFO);
if(info)
{
// Lets indent for neatness.
Expand Down Expand Up @@ -1487,9 +1487,9 @@ static void printHelpAbout(char const* query)
// Try the console commands first.
if(ccmd_t* ccmd = Con_FindCommand(query))
{
void* helpRecord = DH_Find(ccmd->name);
char const* description = DH_GetString(helpRecord, HST_DESCRIPTION);
char const* info = DH_GetString(helpRecord, HST_INFO);
HelpNode help = DH_Find(ccmd->name);
char const* description = DH_GetString(help, HST_DESCRIPTION);
char const* info = DH_GetString(help, HST_INFO);

if(description)
Con_Printf("%s\n", description);
Expand Down Expand Up @@ -1588,8 +1588,8 @@ static int printKnownWordWorker(knownword_t const* word, void* parameters)
switch(word->type)
{
case WT_CCMD: {
ccmd_t* ccmd = (ccmd_t*) word->data;
char* str;
ccmd_t *ccmd = (ccmd_t *) word->data;
char const *str;

if(ccmd->prevOverload)
return 0; // Skip overloaded variants.
Expand Down

0 comments on commit 02664a8

Please sign in to comment.