Skip to content

Commit

Permalink
libcommon: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 17, 2014
1 parent 66e23fc commit 60e9dd6
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 165 deletions.
11 changes: 8 additions & 3 deletions doomsday/plugins/common/include/mapstatereader.h
Expand Up @@ -61,7 +61,7 @@ class MapStateReader
/**
* Lookup a pointer to a Mobj with the given @a serialId.
*/
struct mobj_s *mobj(ThingArchive::SerialId serialId, void *address);
struct mobj_s *mobj(ThingArchive::SerialId serialId, void *address) const;

/**
* Lookup a pointer to a Material with the given @a serialId.
Expand All @@ -72,12 +72,17 @@ class MapStateReader
*
* @return Pointer to the associated material; otherwise @c 0 (not archived).
*/
Material *material(materialarchive_serialid_t serialId, int group);
Material *material(materialarchive_serialid_t serialId, int group) const;

/**
* Lookup a pointer to a Side with the given @a sideIndex.
*/
Side *side(int sideIndex);
Side *side(int sideIndex) const;

/**
* Lookup a pointer to a player with the given @a serialId.
*/
struct player_s *player(int serialId) const;

public: /// @todo refactor away:
void addMobjToThingArchive(struct mobj_s *mobj, ThingArchive::SerialId);
Expand Down
11 changes: 0 additions & 11 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -32,12 +32,6 @@ DENG_EXTERN_C int saveToRealPlayerNum[MAXPLAYERS];
DENG_EXTERN_C targetplraddress_t *targetPlayerAddrs;
#endif

DENG_EXTERN_C SaveInfo const *curInfo;

#if __JHEXEN__
DENG_EXTERN_C byte *saveBuffer;
#endif

DENG_EXTERN_C SaveSlots *saveSlots;

#ifdef __cplusplus
Expand Down Expand Up @@ -159,9 +153,4 @@ void SV_WriteSector(Sector *sec, MapStateWriter *msw);
void SV_ReadSector(Sector *sec, MapStateReader *msr);
#endif // __cplusplus

dd_bool SV_OpenGameSaveFile(Str const *fileName, dd_bool write);
#if __JHEXEN__
dd_bool SV_OpenMapSaveFile(Str const *path);
#endif

#endif // LIBCOMMON_SAVESTATE_H
9 changes: 9 additions & 0 deletions doomsday/plugins/common/include/p_saveio.h
Expand Up @@ -43,6 +43,10 @@ typedef enum savestatesegment_e {
ASEG_WORLDSCRIPTDATA // Hexen only
} savestatesegment_t;

#if __JHEXEN__
DENG_EXTERN_C byte *saveBuffer;
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -66,6 +70,11 @@ dd_bool SV_ExistingFile(Str const *filePath);
int SV_RemoveFile(Str const *filePath);
void SV_CopyFile(Str const *srcPath, Str const *destPath);

dd_bool SV_OpenGameSaveFile(Str const *fileName, dd_bool write);
#if __JHEXEN__
dd_bool SV_OpenMapSaveFile(Str const *path);
#endif

#if __JHEXEN__
saveptr_t *SV_HxSavePtr(void);
void SV_HxSetSaveEndPtr(void *endPtr);
Expand Down
38 changes: 20 additions & 18 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -1157,9 +1157,9 @@ static void printMapBanner(void)
#if __JHEXEN__
mapinfo_t const *mapInfo = P_MapInfo(0/*current map*/);
int warpNum = (mapInfo? mapInfo->warpTrans : -1);
dd_snprintf(buf, 64, "Map %u (%u): " DE2_ESC(b) "%s", warpNum + 1, gameMap + 1, title);
dd_snprintf(buf, 64, "Map %s (%u): " DE2_ESC(b) "%s", Str_Text(Uri_ToString(gameMapUri)), warpNum + 1, title);
#else
dd_snprintf(buf, 64, "Map %u: " DE2_ESC(b) "%s", gameMap + 1, title);
dd_snprintf(buf, 64, "Map %s: " DE2_ESC(b) "%s", Str_Text(Uri_ToString(gameMapUri)), title);
#endif
App_Log(DE2_MAP_NOTE, "%s", buf);
}
Expand Down Expand Up @@ -2825,8 +2825,8 @@ void G_DoLeaveMap(void)
{ uint i;
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = players + i;
ddplayer_t* ddplr = plr->plr;
player_t *plr = players + i;
ddplayer_t *ddplr = plr->plr;

if(!ddplr->inGame) continue;

Expand Down Expand Up @@ -2862,6 +2862,7 @@ void G_DoLeaveMap(void)
}

gameMap = nextMap;
Uri_Copy(gameMapUri, p.mapUri);

// If we're the server, let clients know the map will change.
NetSv_UpdateGameConfigDescription();
Expand Down Expand Up @@ -4231,6 +4232,7 @@ D_CMD(WarpMap)
{
dd_bool const forceNewGameSession = IS_NETGAME != 0;
uint epsd, map, i;
Uri *newMapUri;

// Only server operators can warp maps in network games.
/// @todo Implement vote or similar mechanics.
Expand Down Expand Up @@ -4283,12 +4285,15 @@ D_CMD(WarpMap)
P_SetMessage(players + CONSOLEPLAYER, LMF_NO_HIDE, Str_Text(msg));
return false;
}
newMapUri = G_ComposeMapUri(epsd, map);

#if __JHEXEN__
// Hexen does not allow warping to the current map.
if(!forceNewGameSession && gameInProgress && map == gameMap)
if(!forceNewGameSession && gameInProgress &&
Uri_Equality(gameMapUri, newMapUri))
{
P_SetMessage(players + CONSOLEPLAYER, LMF_NO_HIDE, "Cannot warp to the current map.");
Uri_Delete(newMapUri);
return false;
}
#endif
Expand All @@ -4311,23 +4316,19 @@ D_CMD(WarpMap)
// So be it.
briefDisabled = true;

if(!forceNewGameSession && gameInProgress)
{
Uri *newMapUri = G_ComposeMapUri(epsd, map);
if(!forceNewGameSession && gameInProgress)
{
#if __JHEXEN__
nextMap = map;
nextMapEntrance = 0;
G_SetGameAction(GA_LEAVEMAP);
nextMap = map;
nextMapEntrance = 0;
G_SetGameAction(GA_LEAVEMAP);
#else
G_DeferredNewGame(newMapUri, 0/*default*/, &gameRules);
G_DeferredNewGame(newMapUri, 0/*default*/, &gameRules);
#endif
}
else
{
G_DeferredNewGame(newMapUri, 0/*default*/, &gameRules);
}
Uri_Delete(newMapUri);
}
else
{
G_DeferredNewGame(newMapUri, 0/*default*/, &gameRules);
}

// If the command source was "us" the game library then it was probably in
Expand All @@ -4350,5 +4351,6 @@ D_CMD(WarpMap)
S_LocalSound(soundId, NULL);
}

Uri_Delete(newMapUri);
return true;
}
2 changes: 0 additions & 2 deletions doomsday/plugins/common/src/gamestatereader.cpp
Expand Up @@ -326,8 +326,6 @@ void GameStateReader::read(SaveInfo &info, Str const *path)
DENG_ASSERT(path != 0);
d->saveInfo = &info;

curInfo = d->saveInfo;

if(!SV_OpenGameSaveFile(path, false/*for reading*/))
{
throw FileAccessError("GameStateReader", "Failed opening \"" + de::String(Str_Text(path)) + "\"");
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/gamestatewriter.cpp
Expand Up @@ -24,7 +24,7 @@
#include "d_net.h" // NetSv_SaveGame
#include "mapstatewriter.h"
#include "p_saveio.h"
#include "p_saveg.h" /// @todo remove me
#include "p_saveg.h" /// playerheader_t @todo remove me
#include "thingarchive.h"
#include <de/String>

Expand Down
14 changes: 10 additions & 4 deletions doomsday/plugins/common/src/mapstatereader.cpp
Expand Up @@ -24,7 +24,7 @@
#include "dmu_lib.h"
#include "dmu_archiveindex.h"
#include "p_actor.h"
#include "p_saveg.h"
#include "p_saveg.h" // SV_ReadLine, SV_ReadSector
#include "p_saveio.h"
#include "polyobjs.h"
#include "thinkerinfo.h"
Expand Down Expand Up @@ -596,24 +596,30 @@ void MapStateReader::read(Reader *reader)
MaterialArchive_Delete(d->materialArchive); d->materialArchive = 0;
}

mobj_t *MapStateReader::mobj(ThingArchive::SerialId serialId, void *address)
mobj_t *MapStateReader::mobj(ThingArchive::SerialId serialId, void *address) const
{
DENG_ASSERT(d->thingArchive != 0);
return d->thingArchive->mobj(serialId, address);
}

Material *MapStateReader::material(materialarchive_serialid_t serialId, int group)
Material *MapStateReader::material(materialarchive_serialid_t serialId, int group) const
{
DENG_ASSERT(d->materialArchive != 0);
return MaterialArchive_Find(d->materialArchive, serialId, group);
}

Side *MapStateReader::side(int sideIndex)
Side *MapStateReader::side(int sideIndex) const
{
DENG_ASSERT(d->sideArchive != 0);
return (Side *)d->sideArchive->at(sideIndex);
}

player_t *MapStateReader::player(int serialId) const
{
DENG_ASSERT(serialId > 0 && serialId <= MAXPLAYERS);
return players + saveToRealPlayerNum[serialId - 1];
}

int MapStateReader::mapVersion()
{
return d->mapVersion;
Expand Down
124 changes: 56 additions & 68 deletions doomsday/plugins/common/src/mobj.cpp
Expand Up @@ -549,72 +549,6 @@ void mobj_s::write(MapStateWriter *msw) const
#endif
}

static void RestoreMobj(mobj_t *mo, int ver)
{
#if __JDOOM64__
DENG_UNUSED(ver);
#endif

mo->info = &MOBJINFO[mo->type];

Mobj_SetState(mo, PTR2INT(mo->state));
#if __JHEXEN__
if(mo->flags2 & MF2_DORMANT)
mo->tics = -1;
#endif

if(mo->player)
{
// The player number translation table is used to find out the
// *current* (actual) player number of the referenced player.
int pNum = saveToRealPlayerNum[PTR2INT(mo->player) - 1];

#if __JHEXEN__
if(pNum < 0)
{
// This saved player does not exist in the current game!
// Destroy this mobj.
Z_Free(mo);

return; // Don't add this thinker.
}
#endif

mo->player = &players[pNum];
mo->dPlayer = mo->player->plr;

mo->dPlayer->mo = mo;
//mo->dPlayer->clAngle = mo->angle; /* $unifiedangles */
mo->dPlayer->lookDir = 0; /* $unifiedangles */
}

mo->visAngle = mo->angle >> 16;

#if !__JHEXEN__
if(mo->dPlayer && !mo->dPlayer->inGame)
{
mo->dPlayer->mo = 0;
Mobj_Destroy(mo);

return;
}
#endif

#if !__JDOOM64__
// Do we need to update this mobj's flag values?
if(ver < MOBJ_SAVEVERSION)
{
SV_TranslateLegacyMobjFlags(mo, ver);
}
#endif

P_MobjLink(mo);
mo->floorZ = P_GetDoublep(Mobj_Sector(mo), DMU_FLOOR_HEIGHT);
mo->ceilingZ = P_GetDoublep(Mobj_Sector(mo), DMU_CEILING_HEIGHT);

return;
}

int mobj_s::read(MapStateReader *msr)
{
#define FF_FULLBRIGHT 0x8000 ///< Used to be a flag in thing->frame.
Expand Down Expand Up @@ -873,8 +807,62 @@ int mobj_s::read(MapStateReader *msr)
}
#endif

// Restore! (unmangle)
RestoreMobj(this, ver);
/*
* Restore! (unmangle)
*/
info = &MOBJINFO[type];

Mobj_SetState(this, PTR2INT(state));
#if __JHEXEN__
if(flags2 & MF2_DORMANT)
{
tics = -1;
}
#endif

if(player)
{
// The player number translation table is used to find out the
// *current* (actual) player number of the referenced player.
player = msr->player(PTR2INT(player));
#if __JHEXEN__
if(!player)
{
// This saved player does not exist in the current game!
// Destroy this mobj.
Mobj_Destroy(this);
return false;
}
#endif
dPlayer = player->plr;

dPlayer->mo = this;
//dPlayer->clAngle = angle; /* $unifiedangles */
dPlayer->lookDir = 0; /* $unifiedangles */
}

visAngle = angle >> 16;

#if !__JHEXEN__
if(dPlayer && !dPlayer->inGame)
{
dPlayer->mo = 0;
Mobj_Destroy(this);
return false;
}
#endif

#if !__JDOOM64__
// Do we need to update this mobj's flag values?
if(ver < MOBJ_SAVEVERSION)
{
SV_TranslateLegacyMobjFlags(this, ver);
}
#endif

P_MobjLink(this);
floorZ = P_GetDoublep(Mobj_Sector(this), DMU_FLOOR_HEIGHT);
ceilingZ = P_GetDoublep(Mobj_Sector(this), DMU_CEILING_HEIGHT);

return false;

Expand Down

0 comments on commit 60e9dd6

Please sign in to comment.