Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor: Action functions and XG classes moved from def_main to libd…
…oomsday

To facilitate moving `Games` to libdoomsday, the dependent
game-interfacing functionality of querying action functions and XG
classes was moved to libdoomsday.

Consequently also part of the game-facing API (DD_* constants) are
now defined in libdoomsday's gameapi.h (renamed from gameexport.h).
  • Loading branch information
skyjake committed Jul 23, 2015
1 parent 694cda7 commit f6375a4
Show file tree
Hide file tree
Showing 28 changed files with 331 additions and 199 deletions.
95 changes: 0 additions & 95 deletions doomsday/apps/api/dd_share.h
Expand Up @@ -165,101 +165,6 @@ enum {
DD_USING_HEAD_TRACKING
};

/// General constants (not to be used with Get/Set).
enum {
DD_DISABLE,
DD_ENABLE,
DD_UNUSED22, // DD_MASK
DD_YES,
DD_NO,
DD_UNUSED23, // DD_MATERIAL
DD_UNUSED24, // DD_OFFSET
DD_UNUSED25, // DD_HEIGHT
DD_UNUSED2,
DD_UNUSED3,
DD_UNUSED26, // DD_COLOR_LIMIT
DD_PRE,
DD_POST,
DD_PLUGIN_VERSION_SHORT,
DD_PLUGIN_VERSION_LONG,
DD_UNUSED27, // DD_HORIZON
DD_OLD_GAME_ID,
DD_UNUSED32, // DD_DEF_MOBJ
DD_UNUSED33, // DD_DEF_MOBJ_BY_NAME
DD_UNUSED29, // DD_DEF_STATE
DD_UNUSED34, // DD_DEF_SPRITE
DD_DEF_SOUND,
DD_UNUSED14, // DD_DEF_MUSIC
DD_UNUSED13, // DD_DEF_MAP_INFO
DD_UNUSED28, // DD_DEF_TEXT
DD_UNUSED36, // DD_DEF_VALUE
DD_UNUSED37, // DD_DEF_VALUE_BY_INDEX
DD_DEF_LINE_TYPE,
DD_DEF_SECTOR_TYPE,
DD_PSPRITE_BOB_X,
DD_PSPRITE_BOB_Y,
DD_UNUSED19, // DD_DEF_FINALE_AFTER
DD_UNUSED20, // DD_DEF_FINALE_BEFORE
DD_UNUSED21, // DD_DEF_FINALE
DD_RENDER_RESTART_PRE,
DD_RENDER_RESTART_POST,
DD_UNUSED35, // DD_DEF_SOUND_BY_NAME
DD_DEF_SOUND_LUMPNAME,
DD_UNUSED16, // DD_ID
DD_LUMP,
DD_UNUSED17, // DD_CD_TRACK
DD_UNUSED30, // DD_SPRITE
DD_UNUSED31, // DD_FRAME
DD_GAME_CONFIG, ///< String: dm/co-op, jumping, etc.
DD_PLUGIN_NAME, ///< (e.g., jdoom, jheretic etc..., suitable for use with filepaths)
DD_PLUGIN_NICENAME, ///< (e.g., jDoom, MyGame:Episode2 etc..., fancy name)
DD_PLUGIN_HOMEURL,
DD_PLUGIN_DOCSURL,
DD_DEF_ACTION,
DD_UNUSED15, // DD_DEF_MUSIC_CDTRACK

// Non-integer/special values for Set/Get
DD_UNUSED9, // DD_TRANSLATIONTABLES_ADDRESS
DD_UNUSED4, // DD_TRACE_ADDRESS
DD_SPRITE_REPLACEMENT, ///< Sprite <-> model replacement.
DD_ACTION_LINK, ///< State action routine addresses.
DD_UNUSED10, // DD_MAP_NAME
DD_UNUSED11, // DD_MAP_AUTHOR
DD_MAP_MUSIC,
DD_MAP_MIN_X,
DD_MAP_MIN_Y,
DD_MAP_MAX_X,
DD_MAP_MAX_Y,
DD_WINDOW_WIDTH,
DD_WINDOW_HEIGHT,
DD_WINDOW_HANDLE,
DD_DYNLIGHT_TEXTURE,
DD_GAME_EXPORTS,
DD_POLYOBJ_COUNT,
DD_XGFUNC_LINK, ///< XG line classes
DD_SHARED_FIXED_TRIGGER_OBSOLETE, ///< obsolete
DD_GAMETIC,
DD_UNUSED5, // DD_OPENRANGE
DD_UNUSED6, // DD_OPENTOP
DD_UNUSED7, // DD_OPENBOTTOM
DD_UNUSED8, // DD_LOWFLOOR
DD_CPLAYER_THRUST_MUL_OBSOLETE, ///< obsolete
DD_GRAVITY,
DD_PSPRITE_OFFSET_X, ///< 10x
DD_PSPRITE_OFFSET_Y, ///< 10x
DD_PSPRITE_LIGHTLEVEL_MULTIPLIER,
DD_TORCH_RED,
DD_TORCH_GREEN,
DD_TORCH_BLUE,
DD_TORCH_ADDITIVE,
DD_TM_FLOOR_Z, ///< output from P_CheckPosition
DD_TM_CEILING_Z, ///< output from P_CheckPosition
DD_SHIFT_DOWN,
DD_GAME_RECOMMENDS_SAVING, ///< engine asks whether game should be saved (e.g., when upgrading) (game's GetInteger)
DD_NOTIFY_GAME_SAVED, ///< savegame was written
DD_DEFS ///< engine definition database (DED)
};

//------------------------------------------------------------------------
//
// Games
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/api/def_share.h
Expand Up @@ -24,6 +24,7 @@
#define LIBDENG_SHARED_GAME_DEFINITIONS_H

#include "dd_types.h"
#include <doomsday/world/actions.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -40,8 +41,6 @@ typedef struct {
char name[5];
} sprname_t;

typedef void (C_DECL * acfnptr_t) ();

typedef struct state_s {
spritenum_t sprite;
int flags;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/api/doomsday.h
Expand Up @@ -69,7 +69,7 @@
#include "api_svg.h"
#include "api_uri.h"

#include <doomsday/gameexport.h>
#include <doomsday/gameapi.h>
#include <doomsday/plugins.h>

#include <de/memoryzone.h>
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/dd_def.h
Expand Up @@ -32,7 +32,7 @@

#include "dd_types.h"
#include <doomsday/doomsdayapp.h>
#include <doomsday/gameexport.h>
#include <doomsday/gameapi.h>
#include "api_internaldata.h"

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/dd_main.h
Expand Up @@ -25,7 +25,7 @@
#include <de/LibraryFile>
#include <de/String>
#include <doomsday/resource/resourceclass.h>
#include <doomsday/gameexport.h>
#include <doomsday/gameapi.h>
#include <doomsday/plugins.h>
#include "Games"

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/dd_pinit.h
Expand Up @@ -24,7 +24,7 @@
#define LIBDENG_PORTABLE_INIT_H

#include "api_internaldata.h"
#include <doomsday/gameexport.h>
#include <doomsday/gameapi.h>
#include <doomsday/library.h>
#include <de/c_wrapper.h>

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/de_base.h
Expand Up @@ -42,7 +42,7 @@
#include "ui/nativeui.h"
#include "ui/zonedebug.h"
#include <doomsday/library.h>
#include <doomsday/gameexport.h>
#include <doomsday/gameapi.h>
#include <doomsday/plugins.h>
#include <doomsday/uri.h>
#include <doomsday/help.h>
Expand Down
7 changes: 0 additions & 7 deletions doomsday/apps/client/include/def_main.h
Expand Up @@ -139,13 +139,6 @@ void Def_Init();
*/
void Def_Destroy();

/**
* Retrieves the XG Class list from the Game.
* XGFunc links are provided by the Game, who owns the actual
* XG classes and their functions.
*/
void Def_GetGameClasses();

/**
* Finish definition database initialization. Initialization is split into two
* phases either side of the texture manager, this being the post-phase.
Expand Down
1 change: 0 additions & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -1517,7 +1517,6 @@ bool App_ChangeGame(Game &game, bool allowReload)
<< dint(game.pluginId());
return false;
}
Def_GetGameClasses();
}

// This is now the current game.
Expand Down
58 changes: 4 additions & 54 deletions doomsday/apps/client/src/def_main.cpp
Expand Up @@ -43,15 +43,14 @@
#include <doomsday/filesys/fs_util.h>
#include <doomsday/filesys/sys_direc.h>
#include <doomsday/resource/manifest.h>
#include <doomsday/world/xg.h>

#include "dd_main.h"
#include "dd_def.h"

#include "api_def.h"
#include "api_sound.h"

#include "xgclass.h"

#include "Generator"
#ifdef __CLIENT__
# include "render/rend_particle.h"
Expand All @@ -69,25 +68,13 @@ using namespace de;
#define LOOPi(n) for(i = 0; i < (n); ++i)
#define LOOPk(n) for(k = 0; k < (n); ++k)

struct actionlink_t
{
char *name; ///< Name of the routine.
void (*func)(); ///< Pointer to the function.
};

ded_t defs; ///< The main definitions database.

RuntimeDefs runtimeDefs;

static bool defsInited;
static mobjinfo_t *gettingFor;

typedef QMap<String, acfnptr_t> ActionMap; ///< name => native function pointer.
static ActionMap actions;

static xgclass_t nullXgClassLinks; ///< Used when none defined.
static xgclass_t *xgClassLinks;

static inline FS1 &fileSys()
{
return App_FileSystem();
Expand All @@ -112,33 +99,6 @@ void RuntimeDefs::clear()
stateInfo.clear();
}

void Def_GetGameClasses()
{
// XG ckass links are provided by the game (which defines the class specific parameter names).
::xgClassLinks = nullptr;
if(gx.GetVariable)
{
::xgClassLinks = (xgclass_t *) gx.GetVariable(DD_XGFUNC_LINK);
}
if(!::xgClassLinks)
{
::xgClassLinks = &::nullXgClassLinks;
}
// Let the parser know of the XG classes.
DED_SetXGClassLinks(::xgClassLinks);

// Action links are provided by the game (which owns the actual action functions).
::actions.clear();
if(gx.GetVariable)
{
auto const *links = (actionlink_t const *) gx.GetVariable(DD_ACTION_LINK);
for(actionlink_t const *link = links; link && link->name; link++)
{
::actions.insert(String(link->name).toLower(), link->func);
}
}
}

void Def_Init()
{
::runtimeDefs.clear();
Expand Down Expand Up @@ -177,16 +137,6 @@ void Def_Destroy()
::defsInited = false;
}

acfnptr_t Def_GetActionPtr(String const &name)
{
if(!name.isEmpty())
{
auto found = actions.find(name.toLower());
if(found != actions.end()) return found.value();
}
return nullptr; // Not found.
}

state_t *Def_GetState(dint num)
{
if(num >= 0 && num < ::defs.states.size())
Expand Down Expand Up @@ -1234,7 +1184,7 @@ void Def_Read()
st->flags = dst.geti("flags");
st->frame = dst.geti("frame");
st->tics = dst.geti("tics");
st->action = Def_GetActionPtr(dst.gets("action"));
st->action = P_GetAction(dst.gets("action"));
st->nextState = defs.getStateNum(dst.gets("nextState"));

auto const &misc = dst.geta("misc");
Expand Down Expand Up @@ -1771,7 +1721,7 @@ void Def_CopyLineType(linetype_t *l, ded_linetype_t *def)
// Find the right mapping table.
for(dint k = 0; k < 20; ++k)
{
dint const a = ::xgClassLinks[l->lineClass].iparm[k].map;
dint const a = XG_Class(l->lineClass)->iparm[k].map;
if(a < 0) continue;

if(a & MAP_SND)
Expand Down Expand Up @@ -1875,7 +1825,7 @@ dint Def_Get(dint type, char const *id, void *out)
switch(type)
{
case DD_DEF_ACTION:
if(acfnptr_t action = Def_GetActionPtr(id))
if(acfnptr_t action = P_GetAction(id))
{
if(out) *(acfnptr_t *)out = action;
return true;
Expand Down
3 changes: 0 additions & 3 deletions doomsday/apps/client/src/games.cpp
Expand Up @@ -22,7 +22,6 @@
#include "games.h"

#include "dd_main.h"
#include "def_main.h"

#include <doomsday/doomsdayapp.h>
#include <doomsday/console/cmd.h>
Expand Down Expand Up @@ -218,7 +217,6 @@ void Games::locateStartupResources(Game &game)
/// @attention Kludge: Temporarily switch Game.
App::app().setGame(game);
DoomsdayApp::plugins().exchangeGameEntryPoints(game.pluginId());
Def_GetGameClasses();

// Re-init the filesystem subspace schemes using the search paths of this Game.
App_FileSystem().resetAllSchemes();
Expand All @@ -238,7 +236,6 @@ void Games::locateStartupResources(Game &game)
// Kludge end - Restore the old Game.
App::app().setGame(*oldCurrentGame);
DoomsdayApp::plugins().exchangeGameEntryPoints(oldCurrentGame->pluginId());
Def_GetGameClasses();

// Re-init the filesystem subspace schemes using the search paths of this Game.
App_FileSystem().resetAllSchemes();
Expand Down
1 change: 0 additions & 1 deletion doomsday/apps/libdoomsday/CMakeLists.txt
Expand Up @@ -13,7 +13,6 @@ include (ZLIB)
# Definitions.
add_definitions (
-D__DENG__
-D__DOOMSDAY__
-D__LIBDOOMSDAY__
)

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h
Expand Up @@ -21,7 +21,7 @@

#include "plugins.h"
#include "busymode.h"
#include "gameexport.h"
#include "gameapi.h"

/**
* Common application-level state and components.
Expand Down

0 comments on commit f6375a4

Please sign in to comment.