Skip to content

Commit

Permalink
Refactor|libcommon: Cleaned up high level game/map save state IO
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 24, 2013
1 parent 763bf95 commit 7cea400
Show file tree
Hide file tree
Showing 5 changed files with 704 additions and 673 deletions.
118 changes: 56 additions & 62 deletions doomsday/plugins/common/include/p_savedef.h
Original file line number Diff line number Diff line change
@@ -1,89 +1,83 @@
/**\file p_savedef.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
/** @file common/p_savedef.h Common game-save state management.
*
*\author Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* 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
* <small>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</small>
*/

#ifndef LIBCOMMON_SAVEGAME_DEFS_H
#define LIBCOMMON_SAVEGAME_DEFS_H

#define MY_SAVE_VERSION 11

#if __JDOOM__
# define MY_SAVE_MAGIC 0x1DEAD666
# define MY_CLIENT_SAVE_MAGIC 0x2DEAD666
# define MY_SAVE_VERSION 11
# define CONSISTENCY 0x2c
# define SAVEGAMENAME "DoomSav"
# define CLIENTSAVEGAMENAME "DoomCl"
# define SAVEGAMEEXTENSION "dsg"
# define SAVEGAME_DEFAULT_DIR "savegame"
# define MY_SAVE_MAGIC 0x1DEAD666
# define MY_CLIENT_SAVE_MAGIC 0x2DEAD666
# define CONSISTENCY 0x2c
# define SAVEGAMENAME "DoomSav"
# define CLIENTSAVEGAMENAME "DoomCl"
# define SAVEGAMEEXTENSION "dsg"
# define SAVEGAME_DEFAULT_DIR "savegame"

# define AUTO_SLOT 9
# define AUTO_SLOT 9

#elif __JDOOM64__
# define MY_SAVE_MAGIC 0x1D6420F4
# define MY_CLIENT_SAVE_MAGIC 0x2D6420F4
# define MY_SAVE_VERSION 11
# define CONSISTENCY 0x2c
# define SAVEGAMENAME "D64Sav"
# define CLIENTSAVEGAMENAME "D64Cl"
# define SAVEGAMEEXTENSION "6sg"
# define SAVEGAME_DEFAULT_DIR "savegame"
# define MY_SAVE_MAGIC 0x1D6420F4
# define MY_CLIENT_SAVE_MAGIC 0x2D6420F4
# define CONSISTENCY 0x2c
# define SAVEGAMENAME "D64Sav"
# define CLIENTSAVEGAMENAME "D64Cl"
# define SAVEGAMEEXTENSION "6sg"
# define SAVEGAME_DEFAULT_DIR "savegame"

# define AUTO_SLOT 9
# define AUTO_SLOT 9

#elif __JHERETIC__
# define MY_SAVE_MAGIC 0x7D9A12C5
# define MY_CLIENT_SAVE_MAGIC 0x1062AF43
# define MY_SAVE_VERSION 11
# define CONSISTENCY 0x9d
# define SAVEGAMENAME "HticSav"
# define CLIENTSAVEGAMENAME "HticCl"
# define SAVEGAMEEXTENSION "hsg"
# define SAVEGAME_DEFAULT_DIR "savegame"
# define MY_SAVE_MAGIC 0x7D9A12C5
# define MY_CLIENT_SAVE_MAGIC 0x1062AF43
# define CONSISTENCY 0x9d
# define SAVEGAMENAME "HticSav"
# define CLIENTSAVEGAMENAME "HticCl"
# define SAVEGAMEEXTENSION "hsg"
# define SAVEGAME_DEFAULT_DIR "savegame"

# define AUTO_SLOT 9
# define AUTO_SLOT 9

#elif __JHEXEN__
# define MY_SAVE_MAGIC 0x1B17CC00
# define MY_CLIENT_SAVE_MAGIC 0x2B17CC00
# define MY_SAVE_VERSION 11
# define SAVEGAMENAME "hex"
# define CLIENTSAVEGAMENAME "hexencl"
# define SAVEGAMEEXTENSION "hxs"
# define SAVEGAME_DEFAULT_DIR "hexndata"
# define MY_SAVE_MAGIC 0x1B17CC00
# define MY_CLIENT_SAVE_MAGIC 0x2B17CC00
# define SAVEGAMENAME "hex"
# define CLIENTSAVEGAMENAME "hexencl"
# define SAVEGAMEEXTENSION "hxs"
# define SAVEGAME_DEFAULT_DIR "hexndata"

# define MOBJ_XX_PLAYER -2
# define MOBJ_XX_PLAYER -2

# define BASE_SLOT 6
# define AUTO_SLOT 7
# define BASE_SLOT 6
# define AUTO_SLOT 7

typedef union saveptr_u {
byte *b;
short *w;
int *l;
float *f;
byte *b;
short *w;
int *l;
float *f;
} saveptr_t;

typedef struct targetplraddress_s {
void **address;
void **address;
struct targetplraddress_s *next;
} targetplraddress_t;

Expand All @@ -93,4 +87,4 @@ typedef struct targetplraddress_s {
#define PRE_VER5_END_SPECIALS 7
#endif

#endif
#endif // LIBCOMMON_SAVEGAME_DEFS_H
33 changes: 23 additions & 10 deletions doomsday/plugins/common/include/p_saveio.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {

typedef enum gamearchivesegment_e {
ASEG_MAP_HEADER = 102, // Hexen only
ASEG_WORLD,
ASEG_MAP_ELEMENTS,
ASEG_POLYOBJS, // Hexen only
ASEG_MOBJS, // Hexen < ver 4 only
ASEG_THINKERS,
Expand All @@ -44,7 +44,7 @@ typedef enum gamearchivesegment_e {
ASEG_MISC, // Hexen only
ASEG_END,
ASEG_MATERIAL_ARCHIVE,
ASEG_MAP_HEADER2, // Hexen only
ASEG_MAP_HEADER2,
ASEG_PLAYER_HEADER,
ASEG_GLOBALSCRIPTDATA // Hexen only
} gamearchivesegment_t;
Expand All @@ -66,26 +66,39 @@ const char* SV_ClientSavePath(void);
/*
* File management
*/
LZFILE* SV_OpenFile(const char* filePath, const char* mode);
LZFILE* SV_OpenFile(Str const *filePath, char const *mode);
void SV_CloseFile(void);
LZFILE* SV_File(void);
boolean SV_ExistingFile(const char* filePath);
int SV_RemoveFile(const Str* filePath);
void SV_CopyFile(const Str* srcPath, const Str* destPath);
boolean SV_ExistingFile(Str const *filePath);
int SV_RemoveFile(Str const *filePath);
void SV_CopyFile(Str const *srcPath, Str const *destPath);

#if __JHEXEN__
saveptr_t* SV_HxSavePtr(void);
#endif // __JHEXEN__

/**
* Exit with a fatal error if the value at the current location in the
* game-save file does not match that associated with the segment type.
* game-save file does not match that associated with the segment id.
*
* @param segType Segment type identifier to check alignment of.
* @param segmentId Identifier of the segment to check alignment of.
*/
void SV_AssertSegment(int segType);
void SV_AssertSegment(int segmentId);

void SV_BeginSegment(int segType);
/**
* Special case segment check for the map state.
*
* @param retSegmentId If not @c 0 return the determined segment id.
*
* @todo Refactor away.
*/
void SV_AssertMapSegment(gamearchivesegment_t *retSegmentId);

void SV_BeginSegment(int segmentId);
void SV_EndSegment();

void SV_WriteConsistencyBytes(void);
void SV_ReadConsistencyBytes(void);

/**
* Seek forward @a offset bytes in the save file.
Expand Down
75 changes: 38 additions & 37 deletions doomsday/plugins/common/src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -3045,8 +3045,8 @@ void G_NewGame(skillmode_t skill, uint episode, uint map, uint mapEntryPoint)

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 @@ -3078,53 +3078,54 @@ void G_NewGame(skillmode_t skill, uint episode, uint map, uint mapEntryPoint)
// Make sure that the episode and map numbers are good.
G_ValidateMap(&episode, &map);

gameSkill = skill;
gameEpisode = episode;
gameMap = map;
gameMapEntryPoint = mapEntryPoint;
gameSkill = skill;
gameEpisode = episode;
gameMap = map;
gameMapEntryPoint = mapEntryPoint;

G_ApplyGameRules(skill);
M_ResetRandom();

NetSv_UpdateGameConfigDescription();

{ loadmap_params_t p;
boolean hasBrief;
{
loadmap_params_t p;
boolean hasBrief;

p.mapUri = G_ComposeMapUri(gameEpisode, gameMap);
p.episode = gameEpisode;
p.map = gameMap;
p.revisit = false;
p.mapUri = G_ComposeMapUri(gameEpisode, gameMap);
p.episode = gameEpisode;
p.map = gameMap;
p.revisit = false;

hasBrief = G_BriefingEnabled(gameEpisode, gameMap, 0);
if(!hasBrief)
{
G_QueMapMusic(gameEpisode, gameMap);
}
hasBrief = G_BriefingEnabled(gameEpisode, gameMap, 0);
if(!hasBrief)
{
G_QueMapMusic(gameEpisode, gameMap);
}

// If we're the server, let clients know the map will change.
NetSv_SendGameState(GSF_CHANGE_MAP, DDSP_ALL_PLAYERS);
// If we're the server, let clients know the map will change.
NetSv_SendGameState(GSF_CHANGE_MAP, DDSP_ALL_PLAYERS);

if(!BusyMode_Active())
{
/// @todo Use progress bar mode and update progress during the setup.
BusyMode_RunNewTaskWithName(BUSYF_ACTIVITY | /*BUSYF_PROGRESS_BAR |*/ BUSYF_TRANSITION | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
G_DoLoadMapAndMaybeStartBriefingWorker, &p, "Loading map...");
}
else
{
G_DoLoadMapAndMaybeStartBriefing(&p);
}
if(!BusyMode_Active())
{
/// @todo Use progress bar mode and update progress during the setup.
BusyMode_RunNewTaskWithName(BUSYF_ACTIVITY | /*BUSYF_PROGRESS_BAR |*/ BUSYF_TRANSITION | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
G_DoLoadMapAndMaybeStartBriefingWorker, &p, "Loading map...");
}
else
{
G_DoLoadMapAndMaybeStartBriefing(&p);
}

if(!hasBrief)
{
// No briefing; begin the map.
HU_WakeWidgets(-1 /* all players */);
G_BeginMap();
}
if(!hasBrief)
{
// No briefing; begin the map.
HU_WakeWidgets(-1 /* all players */);
G_BeginMap();
}

Z_CheckHeap();
Uri_Delete(p.mapUri);
Z_CheckHeap();
Uri_Delete(p.mapUri);
}
}

Expand Down
Loading

0 comments on commit 7cea400

Please sign in to comment.