From fb2a9bc40e8f2ec60ddea23c43ad83c5c28524ac Mon Sep 17 00:00:00 2001 From: danij Date: Sat, 15 Feb 2014 23:39:51 +0000 Subject: [PATCH] libcommon: Added a basic GameStateReaderFactory With runtime registration so that new IGameStateReaders can be added without requiring the factory to have compile time knowledge of the derived classes. Todo: The implementation could probably be improved (factory should return instances with std::auto_ptr?). Perhaps libdeng2 could provide the abstract components necessary for building a factory? --- doomsday/plugins/common/include/common.h | 8 ++ .../plugins/common/include/gamestatereader.h | 77 +++++++++++++++++-- .../plugins/common/include/gamestatewriter.h | 4 +- doomsday/plugins/common/include/p_saveg.h | 10 +++ .../plugins/common/src/gamestatereader.cpp | 5 ++ .../plugins/common/src/gamestatewriter.cpp | 6 +- doomsday/plugins/common/src/p_saveg.cpp | 56 +++++++------- doomsday/plugins/doom/doom.pro | 2 +- doomsday/plugins/doom/include/acfnlink.h | 2 +- doomsday/plugins/doom/include/d_main.h | 73 ++++++++---------- .../doom/include/doomv9gamestatereader.h | 8 +- doomsday/plugins/doom/include/p_pspr.h | 18 +++-- doomsday/plugins/doom/include/wi_stuff.h | 10 ++- .../plugins/doom/src/{d_main.c => d_main.cpp} | 6 +- .../doom/src/doomv9gamestatereader.cpp | 5 ++ doomsday/plugins/doom64/include/acfnlink.h | 2 +- doomsday/plugins/doom64/include/wi_stuff.h | 11 ++- doomsday/plugins/heretic/heretic.pro | 2 +- doomsday/plugins/heretic/include/acfnlink.h | 2 +- doomsday/plugins/heretic/include/h_main.h | 73 ++++++++---------- .../include/hereticv13gamestatereader.h | 8 +- doomsday/plugins/heretic/include/p_pspr.h | 18 +++-- .../heretic/src/{h_main.c => h_main.cpp} | 6 +- .../heretic/src/hereticv13gamestatereader.cpp | 5 ++ doomsday/plugins/hexen/include/acfnlink.h | 2 +- doomsday/plugins/hexen/include/p_pspr.h | 18 +++-- 26 files changed, 278 insertions(+), 159 deletions(-) rename doomsday/plugins/doom/src/{d_main.c => d_main.cpp} (98%) rename doomsday/plugins/heretic/src/{h_main.c => h_main.cpp} (98%) diff --git a/doomsday/plugins/common/include/common.h b/doomsday/plugins/common/include/common.h index 5055ca27c2..600f6f6909 100644 --- a/doomsday/plugins/common/include/common.h +++ b/doomsday/plugins/common/include/common.h @@ -50,6 +50,14 @@ DENG_EXTERN_C dd_bool sc_FileScripts; DENG_EXTERN_C char const *sc_ScriptsDir; +#ifdef __cplusplus +extern "C" { +#endif + int Common_GetInteger(int id); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // LIBCOMMON_GAME_INCLUDES diff --git a/doomsday/plugins/common/include/gamestatereader.h b/doomsday/plugins/common/include/gamestatereader.h index 40a75343db..88a9c463e1 100644 --- a/doomsday/plugins/common/include/gamestatereader.h +++ b/doomsday/plugins/common/include/gamestatereader.h @@ -44,28 +44,89 @@ class IGameStateReader * Attempt to load (read/interpret) the saved game state. * * @param info SaveInfo for the saved game state to be read/interpreted. - * @param path Path to the resource file to be recognized. + * @param path Path to the saved game state to be read. + * + * @todo @a path should be provided by SaveInfo. */ virtual void read(SaveInfo &info, Str const *path) = 0; }; /** - * @ingroup libcommon - * @see GameStateWriter + * Game state recognizer function ptr. + * + * The job of a recognizer function is to determine whether the resource file on @a path is interpretable + * as a potentially loadable game state. + * + * @param info SaveInfo to attempt to read game session header into. + * @param path Path to the resource file to be recognized. */ -class GameStateReader : public IGameStateReader +typedef bool (*GameStateRecognizeFunc)(SaveInfo &info, Str const *path); + +/// Game state reader instantiator function ptr. +typedef IGameStateReader *(*GameStateReaderMakeFunc)(); + +/** + * Factory for the construction of new IGameStateReader-derived instances. + */ +class GameStateReaderFactory { public: - GameStateReader(); - ~GameStateReader(); + /** + * Register a game state reader. + * + * @param recognizer Game state recognizer function. + * @param maker Game state reader instantiator function. + */ + void declareReader(GameStateRecognizeFunc recognizer, GameStateReaderMakeFunc maker) + { + ReaderInfo info; + info.recognize = recognizer; + info.makeInstance = maker; + readers.push_back(info); + } /** - * Determines whether the resource file on @a path is interpretable as a game state which can - * be loaded with a GameStateReader. + * Returns a new IGameStateReader instance appropriate for the specified save game @a info. * * @param info SaveInfo to attempt to read game session header into. * @param path Path to the resource file to be recognized. + * + * @return New reader instance if recognized; otherwise @c 0. Ownership given to the caller. */ + IGameStateReader *newReaderFor(SaveInfo &info, Str const *path) + { + DENG2_FOR_EACH_CONST(ReaderInfos, i, readers) + { + if(i->recognize(info, path)) + { + return i->makeInstance(); + } + } + return 0; // Unrecognized + } + +private: + struct ReaderInfo { + GameStateRecognizeFunc recognize; + GameStateReaderMakeFunc makeInstance; + }; + typedef std::list ReaderInfos; + ReaderInfos readers; +}; + +/** + * Native saved game state reader. + * + * @ingroup libcommon + * @see GameStateWriter + */ +class GameStateReader : public IGameStateReader +{ +public: + GameStateReader(); + ~GameStateReader(); + + static IGameStateReader *make(); static bool recognize(SaveInfo &info, Str const *path); void read(SaveInfo &info, Str const *path); diff --git a/doomsday/plugins/common/include/gamestatewriter.h b/doomsday/plugins/common/include/gamestatewriter.h index 6cbbd6fbe6..7a9fb868a8 100644 --- a/doomsday/plugins/common/include/gamestatewriter.h +++ b/doomsday/plugins/common/include/gamestatewriter.h @@ -26,6 +26,8 @@ #include /** + * Native saved game state writer. + * * @ingroup libcommon * @see GameStateReader */ @@ -38,7 +40,7 @@ class GameStateWriter public: GameStateWriter(); - void write(SaveInfo *saveInfo, Str const *path); + void write(SaveInfo &info, Str const *path); private: DENG2_PRIVATE(d) diff --git a/doomsday/plugins/common/include/p_saveg.h b/doomsday/plugins/common/include/p_saveg.h index 3f0dfde9a0..1914ef5cd8 100644 --- a/doomsday/plugins/common/include/p_saveg.h +++ b/doomsday/plugins/common/include/p_saveg.h @@ -132,6 +132,16 @@ void SV_SaveInfo_Read(SaveInfo *info, Reader *reader); #endif #ifdef __cplusplus +#include "gamestatereader.h" + +/** + * Declare a new saved game state reader/interpreter. + * + * @param recognizer Format recognizer function. + * @param maker Reader instantiator function. + */ +void SV_DeclareGameStateReader(GameStateRecognizeFunc recognizer, GameStateReaderMakeFunc maker); + class MapStateReader; class MapStateWriter; diff --git a/doomsday/plugins/common/src/gamestatereader.cpp b/doomsday/plugins/common/src/gamestatereader.cpp index f92248d34b..fb6506f42f 100644 --- a/doomsday/plugins/common/src/gamestatereader.cpp +++ b/doomsday/plugins/common/src/gamestatereader.cpp @@ -323,6 +323,11 @@ bool GameStateReader::recognize(SaveInfo &info, Str const *path) // static return true; } +IGameStateReader *GameStateReader::make() // static +{ + return new GameStateReader; +} + void GameStateReader::read(SaveInfo &info, Str const *path) { DENG_ASSERT(path != 0); diff --git a/doomsday/plugins/common/src/gamestatewriter.cpp b/doomsday/plugins/common/src/gamestatewriter.cpp index c041c1f997..862c294daa 100644 --- a/doomsday/plugins/common/src/gamestatewriter.cpp +++ b/doomsday/plugins/common/src/gamestatewriter.cpp @@ -123,10 +123,10 @@ DENG2_PIMPL(GameStateWriter) GameStateWriter::GameStateWriter() : d(new Instance(this)) {} -void GameStateWriter::write(SaveInfo *saveInfo, Str const *path) +void GameStateWriter::write(SaveInfo &info, Str const *path) { - DENG_ASSERT(saveInfo != 0 && path != 0); - d->saveInfo = saveInfo; + DENG_ASSERT(path != 0); + d->saveInfo = &info; // In networked games the server tells the clients to save their games. #if !__JHEXEN__ diff --git a/doomsday/plugins/common/src/p_saveg.cpp b/doomsday/plugins/common/src/p_saveg.cpp index 80478b563e..e61974feca 100644 --- a/doomsday/plugins/common/src/p_saveg.cpp +++ b/doomsday/plugins/common/src/p_saveg.cpp @@ -30,12 +30,6 @@ #include "gamestatereader.h" #include "mapstatereader.h" #include "mapstatewriter.h" -#if __JDOOM__ -# include "doomv9gamestatereader.h" -#endif -#if __JHERETIC__ -# include "hereticv13gamestatereader.h" -#endif #include #include #include @@ -43,6 +37,7 @@ static bool inited = false; +static GameStateReaderFactory gameStateReaderFactory; static SaveSlots sslots(NUMSAVESLOTS); SaveSlots *saveSlots = &sslots; @@ -880,6 +875,12 @@ void SV_Initialize() // (Re)Initialize the saved game paths, possibly creating them if they do not exist. SV_ConfigureSavePaths(); + if(!inited) + { + // Declare the native game state reader. + gameStateReaderFactory.declareReader(&GameStateReader::recognize, &GameStateReader::make); + } + inited = true; } @@ -893,6 +894,23 @@ void SV_Shutdown() inited = false; } +void SV_DeclareGameStateReader(GameStateRecognizeFunc recognizer, GameStateReaderMakeFunc maker) +{ + DENG_ASSERT(inited); + gameStateReaderFactory.declareReader(recognizer, maker); +} + +static std::auto_ptr gameStateReaderFor(SaveInfo &info, Str const *path) +{ + std::auto_ptr p(gameStateReaderFactory.newReaderFor(info, path)); + if(!p.get()) + { + /// @throw Error The saved game state format was not recognized. + throw de::Error("gameStateReaderFor", "Unrecognized savegame format"); + } + return p; +} + dd_bool SV_LoadGame(int slot) { DENG_ASSERT(inited); @@ -931,28 +949,8 @@ dd_bool SV_LoadGame(int slot) { SaveInfo &info = saveSlots->saveInfo(logicalSlot); - if(GameStateReader::recognize(info, path)) - { - GameStateReader().read(info, path); - } - // Perhaps an original game state? -#if __JDOOM__ - else if(DoomV9GameStateReader::recognize(info, path)) - { - DoomV9GameStateReader().read(info, path); - } -#endif -#if __JHERETIC__ - else if(HereticV13GameStateReader::recognize(info, path)) - { - HereticV13GameStateReader().read(info, path); - } -#endif - else - { - /// @throw Error The savegame was not recognized. - throw de::Error("loadGameState", "Unrecognized savegame format"); - } + // Attempt to recognize and load the saved game state. + gameStateReaderFor(info, path)->read(info, path); // Make note of the last used save slot. Con_SetInteger2("game-save-last-slot", slot, SVF_WRITE_OVERRIDE); @@ -1000,7 +998,7 @@ dd_bool SV_SaveGame(int slot, char const *description) SaveInfo *info = SaveInfo::newWithCurrentSessionMetadata(AutoStr_FromTextStd(description)); try { - GameStateWriter().write(info, path); + GameStateWriter().write(*info, path); // Swap the save info. saveSlots->replaceSaveInfo(logicalSlot, info); diff --git a/doomsday/plugins/doom/doom.pro b/doomsday/plugins/doom/doom.pro index 40572116f6..bb64ed6c4a 100644 --- a/doomsday/plugins/doom/doom.pro +++ b/doomsday/plugins/doom/doom.pro @@ -75,7 +75,7 @@ SOURCES += \ src/d_api.c \ src/d_console.c \ src/d_items.c \ - src/d_main.c \ + src/d_main.cpp \ src/d_refresh.c \ src/doomv9gamestatereader.cpp \ src/m_cheat.c \ diff --git a/doomsday/plugins/doom/include/acfnlink.h b/doomsday/plugins/doom/include/acfnlink.h index b6e7d6f78e..96223ec20a 100644 --- a/doomsday/plugins/doom/include/acfnlink.h +++ b/doomsday/plugins/doom/include/acfnlink.h @@ -37,7 +37,7 @@ typedef struct { void (C_DECL *func)(); // Pointer to the function. } actionlink_t; -extern actionlink_t actionlinks[]; +DENG_EXTERN_C actionlink_t actionlinks[]; void C_DECL A_BabyMetal(); void C_DECL A_BFGsound(); diff --git a/doomsday/plugins/doom/include/d_main.h b/doomsday/plugins/doom/include/d_main.h index 5671bbca74..4b7a834b97 100644 --- a/doomsday/plugins/doom/include/d_main.h +++ b/doomsday/plugins/doom/include/d_main.h @@ -1,25 +1,21 @@ -/**\file d_main.h - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file d_main.h Doom-specific game initialization * - *\author Copyright © 2003-2013 Jaakko Keränen - *\author Copyright © 2005-2013 Daniel Swanson + * @authors Copyright © 2003-2013 Jaakko Keränen + * @authors Copyright © 2005-2013 Daniel Swanson * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. You should have received a copy of the GNU + * General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA */ #ifndef LIBJDOOM_MAIN_H @@ -31,40 +27,37 @@ #include "doomdef.h" -#ifdef __cplusplus -extern "C" { -#endif - -extern int verbose; +DENG_EXTERN_C int verbose; -//extern dd_bool noMonstersParm; // checkparm of -nomonsters -//extern dd_bool respawnParm; // checkparm of -respawn -//extern dd_bool turboParm; // checkparm of -turbo -//extern dd_bool randomClassParm; // checkparm of -randclass -//extern dd_bool devParm; // checkparm of -devparm -//extern dd_bool fastParm; // checkparm of -fast +DENG_EXTERN_C float turboMul; // Multiplier for turbo. -extern float turboMul; // Multiplier for turbo. +DENG_EXTERN_C gamemode_t gameMode; +DENG_EXTERN_C int gameModeBits; -extern gamemode_t gameMode; -extern int gameModeBits; +DENG_EXTERN_C char *borderGraphics[]; -extern char* borderGraphics[]; +DENG_EXTERN_C float defFontRGB[]; +DENG_EXTERN_C float defFontRGB2[]; +DENG_EXTERN_C float defFontRGB3[]; -extern float defFontRGB[]; -extern float defFontRGB2[]; -extern float defFontRGB3[]; +DENG_EXTERN_C dd_bool monsterInfight; -extern dd_bool monsterInfight; +#ifdef __cplusplus +extern "C" { +#endif void D_PreInit(void); + void D_PostInit(void); + void D_Shutdown(void); + int D_GetInteger(int id); -void* D_GetVariable(int id); + +void *D_GetVariable(int id); #ifdef __cplusplus } // extern "C" #endif -#endif /* LIBJDOOM_MAIN_H */ +#endif // LIBJDOOM_MAIN_H diff --git a/doomsday/plugins/doom/include/doomv9gamestatereader.h b/doomsday/plugins/doom/include/doomv9gamestatereader.h index 59845a36ba..bec2c3676a 100644 --- a/doomsday/plugins/doom/include/doomv9gamestatereader.h +++ b/doomsday/plugins/doom/include/doomv9gamestatereader.h @@ -40,13 +40,7 @@ class DoomV9GameStateReader : public IGameStateReader DoomV9GameStateReader(); ~DoomV9GameStateReader(); - /** - * Determines whether the resource file on @a path is interpretable as a game state which can - * be loaded with a DoomV9GameStateReader. - * - * @param info SaveInfo to attempt to read game session header into. - * @param path Path to the resource file to be recognized. - */ + static IGameStateReader *make(); static bool recognize(SaveInfo &info, Str const *path); void read(SaveInfo &info, Str const *path); diff --git a/doomsday/plugins/doom/include/p_pspr.h b/doomsday/plugins/doom/include/p_pspr.h index 5905c21692..dd29848420 100644 --- a/doomsday/plugins/doom/include/p_pspr.h +++ b/doomsday/plugins/doom/include/p_pspr.h @@ -50,12 +50,20 @@ typedef enum { } psprnum_t; typedef struct { - state_t* state; // A NULL state means not active. - int tics; - float pos[2]; // [x, y]. + state_t *state; // A NULL state means not active. + int tics; + float pos[2]; // [x, y]. } pspdef_t; -void R_GetWeaponBob(int player, float* x, float* y); -void P_BringUpWeapon(struct player_s *player); +#ifdef __cplusplus +extern "C" { +#endif + +void R_GetWeaponBob(int player, float *x, float *y); +void P_BringUpWeapon(struct player_s *player); + +#ifdef __cplusplus +} // extern "C" +#endif #endif diff --git a/doomsday/plugins/doom/include/wi_stuff.h b/doomsday/plugins/doom/include/wi_stuff.h index d00d582b68..5c2724fe9c 100644 --- a/doomsday/plugins/doom/include/wi_stuff.h +++ b/doomsday/plugins/doom/include/wi_stuff.h @@ -81,6 +81,10 @@ typedef enum { ILS_SHOW_NEXTMAP } interludestate_t; +#ifdef __cplusplus +extern "C" { +#endif + /// To be called to register the console commands and variables of this module. void WI_Register(void); @@ -116,4 +120,8 @@ void WI_End(void); */ void IN_SkipToNext(void); -#endif /* LIBDOOM_WI_STUFF_H */ +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // LIBDOOM_WI_STUFF_H diff --git a/doomsday/plugins/doom/src/d_main.c b/doomsday/plugins/doom/src/d_main.cpp similarity index 98% rename from doomsday/plugins/doom/src/d_main.c rename to doomsday/plugins/doom/src/d_main.cpp index e9ab63288b..95f3d1bddc 100644 --- a/doomsday/plugins/doom/src/d_main.c +++ b/doomsday/plugins/doom/src/d_main.cpp @@ -1,4 +1,4 @@ -/** @file d_main.c Doom-specific game initialization. +/** @file d_main.cpp Doom-specific game initialization. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2005-2013 Daniel Swanson @@ -26,6 +26,7 @@ #include "m_argv.h" #include "p_map.h" #include "p_saveg.h" +#include "doomv9gamestatereader.h" #include "am_map.h" #include "g_defs.h" #include @@ -396,6 +397,9 @@ void D_PreInit(void) // Do the common pre init routine; G_CommonPreInit(); G_InitSpecialFilter(); + + // Declare the Doom V9 game state reader/interpreter. + SV_DeclareGameStateReader(&DoomV9GameStateReader::recognize, &DoomV9GameStateReader::make); } /** diff --git a/doomsday/plugins/doom/src/doomv9gamestatereader.cpp b/doomsday/plugins/doom/src/doomv9gamestatereader.cpp index 7d73bba209..f690208f27 100644 --- a/doomsday/plugins/doom/src/doomv9gamestatereader.cpp +++ b/doomsday/plugins/doom/src/doomv9gamestatereader.cpp @@ -954,6 +954,11 @@ bool DoomV9GameStateReader::recognize(SaveInfo &info, Str const *path) // static return result; } +IGameStateReader *DoomV9GameStateReader::make() +{ + return new DoomV9GameStateReader; +} + void DoomV9GameStateReader::read(SaveInfo &info, Str const *path) { DENG_ASSERT(path != 0); diff --git a/doomsday/plugins/doom64/include/acfnlink.h b/doomsday/plugins/doom64/include/acfnlink.h index 6d61318e1f..d30c80cd2c 100644 --- a/doomsday/plugins/doom64/include/acfnlink.h +++ b/doomsday/plugins/doom64/include/acfnlink.h @@ -42,7 +42,7 @@ typedef struct { void (C_DECL *func)(); // Pointer to the function. } actionlink_t; -extern actionlink_t actionlinks[]; +DENG_EXTERN_C actionlink_t actionlinks[]; void C_DECL A_BabyMetal(); void C_DECL A_BFGsound(); diff --git a/doomsday/plugins/doom64/include/wi_stuff.h b/doomsday/plugins/doom64/include/wi_stuff.h index 281fcfb040..b4c8231eeb 100644 --- a/doomsday/plugins/doom64/include/wi_stuff.h +++ b/doomsday/plugins/doom64/include/wi_stuff.h @@ -83,6 +83,10 @@ typedef enum { /// relevant state progressions. } interludestate_t; +#ifdef __cplusplus +extern "C" { +#endif + /// To be called to register the console commands and variables of this module. void WI_Register(void); @@ -116,4 +120,9 @@ void WI_End(void); */ void IN_SkipToNext(void); -#endif /* LIBDOOM_WI_STUFF_H */ +#ifdef __cplusplus +} // extern "C" +#endif + + +#endif // LIBDOOM_WI_STUFF_H diff --git a/doomsday/plugins/heretic/heretic.pro b/doomsday/plugins/heretic/heretic.pro index 793c43d857..35582e757e 100644 --- a/doomsday/plugins/heretic/heretic.pro +++ b/doomsday/plugins/heretic/heretic.pro @@ -74,7 +74,7 @@ SOURCES += \ src/acfnlink.c \ src/h_api.c \ src/h_console.c \ - src/h_main.c \ + src/h_main.cpp \ src/h_refresh.c \ src/hereticv13gamestatereader.cpp \ src/in_lude.c \ diff --git a/doomsday/plugins/heretic/include/acfnlink.h b/doomsday/plugins/heretic/include/acfnlink.h index 7055bd320c..4df249a39f 100644 --- a/doomsday/plugins/heretic/include/acfnlink.h +++ b/doomsday/plugins/heretic/include/acfnlink.h @@ -41,7 +41,7 @@ typedef struct { void (C_DECL *func) (); // Pointer to the function. } actionlink_t; -extern actionlink_t actionlinks[]; +DENG_EXTERN_C actionlink_t actionlinks[]; void C_DECL A_AccTeleGlitter(); void C_DECL A_AddPlayerCorpse(); diff --git a/doomsday/plugins/heretic/include/h_main.h b/doomsday/plugins/heretic/include/h_main.h index 433c4b9958..5f65d90444 100644 --- a/doomsday/plugins/heretic/include/h_main.h +++ b/doomsday/plugins/heretic/include/h_main.h @@ -1,25 +1,21 @@ -/**\file h_main.h - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file h_main.h Heretic-specific game initialization. * - *\author Copyright © 2003-2013 Jaakko Keränen - *\author Copyright © 2006-2013 Daniel Swanson + * @authors Copyright © 2003-2013 Jaakko Keränen + * @authors Copyright © 2006-2013 Daniel Swanson * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. You should have received a copy of the GNU + * General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA */ #ifndef LIBJHERETIC_MAIN_H @@ -29,40 +25,39 @@ # error "Using jHeretic headers without __JHERETIC__" #endif -#ifdef __cplusplus -extern "C" { -#endif +#include "doomdef.h" -extern int verbose; +DENG_EXTERN_C int verbose; -//extern dd_bool noMonstersParm; // checkparm of -nomonsters -//extern dd_bool respawnParm; // checkparm of -respawn -//extern dd_bool turboParm; // checkparm of -turbo -//extern dd_bool randomClassParm; // checkparm of -randclass -//extern dd_bool devParm; // checkparm of -devparm -//extern dd_bool fastParm; // checkparm of -fast +DENG_EXTERN_C float turboMul; // Multiplier for turbo. -extern float turboMul; // Multiplier for turbo. +DENG_EXTERN_C gamemode_t gameMode; +DENG_EXTERN_C int gameModeBits; -extern gamemode_t gameMode; -extern int gameModeBits; +DENG_EXTERN_C char *borderGraphics[]; -extern char* borderGraphics[]; +DENG_EXTERN_C float const defFontRGB[]; +DENG_EXTERN_C float const defFontRGB2[]; +DENG_EXTERN_C float const defFontRGB3[]; -extern const float defFontRGB[]; -extern const float defFontRGB2[]; -extern const float defFontRGB3[]; +DENG_EXTERN_C dd_bool monsterInfight; -extern dd_bool monsterInfight; +#ifdef __cplusplus +extern "C" { +#endif void H_PreInit(void); + void H_PostInit(void); + void H_Shutdown(void); + int H_GetInteger(int id); -void* H_GetVariable(int id); + +void *H_GetVariable(int id); #ifdef __cplusplus } // extern "C" #endif -#endif /* LIBJHERETIC_MAIN_H */ +#endif // LIBJHERETIC_MAIN_H diff --git a/doomsday/plugins/heretic/include/hereticv13gamestatereader.h b/doomsday/plugins/heretic/include/hereticv13gamestatereader.h index 2c115ca0fa..3e1f6e93c7 100644 --- a/doomsday/plugins/heretic/include/hereticv13gamestatereader.h +++ b/doomsday/plugins/heretic/include/hereticv13gamestatereader.h @@ -40,13 +40,7 @@ class HereticV13GameStateReader : public IGameStateReader HereticV13GameStateReader(); ~HereticV13GameStateReader(); - /** - * Determines whether the resource file on @a path is interpretable as a game state which can - * be loaded with a HereticV13GameStateReader. - * - * @param info SaveInfo to attempt to read game session header into. - * @param path Path to the resource file to be recognized. - */ + static IGameStateReader *make(); static bool recognize(SaveInfo &info, Str const *path); void read(SaveInfo &info, Str const *path); diff --git a/doomsday/plugins/heretic/include/p_pspr.h b/doomsday/plugins/heretic/include/p_pspr.h index 4bd076c34c..6a8dc2de40 100644 --- a/doomsday/plugins/heretic/include/p_pspr.h +++ b/doomsday/plugins/heretic/include/p_pspr.h @@ -43,12 +43,20 @@ typedef enum { } psprnum_t; typedef struct pspdef_s { - state_t* state; // a NULL state means not active. - int tics; - float pos[2]; + state_t *state; // a NULL state means not active. + int tics; + float pos[2]; } pspdef_t; -void P_BringUpWeapon(struct player_s *player); -void R_GetWeaponBob(int player, float* x, float* y); +#ifdef __cplusplus +extern "C" { +#endif + +void R_GetWeaponBob(int player, float *x, float *y); +void P_BringUpWeapon(struct player_s *player); + +#ifdef __cplusplus +} // extern "C" +#endif #endif diff --git a/doomsday/plugins/heretic/src/h_main.c b/doomsday/plugins/heretic/src/h_main.cpp similarity index 98% rename from doomsday/plugins/heretic/src/h_main.c rename to doomsday/plugins/heretic/src/h_main.cpp index 1840157b13..148b5f0894 100644 --- a/doomsday/plugins/heretic/src/h_main.c +++ b/doomsday/plugins/heretic/src/h_main.cpp @@ -1,4 +1,4 @@ -/** @file h_main.c Heretic-specific game initialization. +/** @file h_main.cpp Heretic-specific game initialization. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2005-2013 Daniel Swanson @@ -26,6 +26,7 @@ #include "m_argv.h" #include "p_map.h" #include "p_saveg.h" +#include "hereticv13gamestatereader.h" #include "am_map.h" #include "g_defs.h" #include "p_inventory.h" @@ -332,6 +333,9 @@ void H_PreInit(void) // Do the common pre init routine; G_CommonPreInit(); + + // Declare the Heretic V13 game state reader/interpreter. + SV_DeclareGameStateReader(&HereticV13GameStateReader::recognize, &HereticV13GameStateReader::make); } /** diff --git a/doomsday/plugins/heretic/src/hereticv13gamestatereader.cpp b/doomsday/plugins/heretic/src/hereticv13gamestatereader.cpp index aeb5b2b22b..c1d7e0ccc0 100644 --- a/doomsday/plugins/heretic/src/hereticv13gamestatereader.cpp +++ b/doomsday/plugins/heretic/src/hereticv13gamestatereader.cpp @@ -966,6 +966,11 @@ bool HereticV13GameStateReader::recognize(SaveInfo &info, Str const *path) // st return result; } +IGameStateReader *HereticV13GameStateReader::make() +{ + return new HereticV13GameStateReader; +} + void HereticV13GameStateReader::read(SaveInfo &info, Str const *path) { DENG_ASSERT(path != 0); diff --git a/doomsday/plugins/hexen/include/acfnlink.h b/doomsday/plugins/hexen/include/acfnlink.h index 866be7519c..eda93248d5 100644 --- a/doomsday/plugins/hexen/include/acfnlink.h +++ b/doomsday/plugins/hexen/include/acfnlink.h @@ -40,7 +40,7 @@ typedef struct { void (C_DECL * func) (); // Pointer to the function. } actionlink_t; -extern actionlink_t actionlinks[]; +DENG_EXTERN_C actionlink_t actionlinks[]; void C_DECL A_AddPlayerCorpse(); void C_DECL A_BatMove(); diff --git a/doomsday/plugins/hexen/include/p_pspr.h b/doomsday/plugins/hexen/include/p_pspr.h index 9a406818ec..a481ac5300 100644 --- a/doomsday/plugins/hexen/include/p_pspr.h +++ b/doomsday/plugins/hexen/include/p_pspr.h @@ -41,12 +41,20 @@ typedef enum { } psprnum_t; typedef struct { - state_t* state; // @c NULL means not active. - int tics; - float pos[2]; + state_t *state; // @c NULL means not active. + int tics; + float pos[2]; } pspdef_t; -void P_BringUpWeapon(struct player_s *player); -void R_GetWeaponBob(int player, float* x, float* y); +#ifdef __cplusplus +extern "C" { +#endif + +void R_GetWeaponBob(int player, float *x, float *y); +void P_BringUpWeapon(struct player_s *player); + +#ifdef __cplusplus +} // extern "C" +#endif #endif