Skip to content

Commit

Permalink
Refactor|libcommon: Renamed GameStateWriter as GameSessionWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 20, 2014
1 parent 8477c87 commit b2101c0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions doomsday/plugins/common/common.pri
Expand Up @@ -24,7 +24,7 @@ HEADERS += \
$$common_inc/g_eventsequence.h \
$$common_inc/g_update.h \
$$common_inc/gamerules.h \
$$common_inc/gamestatewriter.h \
$$common_inc/gamesessionwriter.h \
$$common_inc/gl_drawpatch.h \
$$common_inc/hexlex.h \
$$common_inc/hu_automap.h \
Expand Down Expand Up @@ -89,7 +89,7 @@ SOURCES += \
$$common_src/g_game.cpp \
$$common_src/g_update.c \
$$common_src/gamerules.cpp \
$$common_src/gamestatewriter.cpp \
$$common_src/gamesessionwriter.cpp \
$$common_src/gl_drawpatch.c \
$$common_src/hexlex.cpp \
$$common_src/hu_automap.cpp \
Expand Down
@@ -1,4 +1,4 @@
/** @file gamestatewriter.h Saved game state writer.
/** @file gamesessionwriter.h Serializing game state to a saved session.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -18,27 +18,26 @@
* 02110-1301 USA</small>
*/

#ifndef LIBCOMMON_GAMESTATEWRITER_H
#define LIBCOMMON_GAMESTATEWRITER_H
#ifndef LIBCOMMON_GAMESESSIONWRITER_H
#define LIBCOMMON_GAMESESSIONWRITER_H

#include <de/Error>
#include <de/game/MapStateReader>
#include <de/Path>

/**
* Native saved game state writer.
* Native game state saved session writer.
*
* @ingroup libcommon
* @see GameStateReader
*/
class GameStateWriter
class GameSessionWriter
{
public:
/// An error occurred attempting to open the output file. @ingroup errors
DENG2_ERROR(FileAccessError);

public:
GameStateWriter();
GameSessionWriter();

void write(de::Path const &stateFilePath, de::Path const &mapStateFilePath,
de::game::SessionMetadata const &metadata);
Expand All @@ -47,4 +46,4 @@ class GameStateWriter
DENG2_PRIVATE(d)
};

#endif // LIBCOMMON_GAMESTATEWRITER_H
#endif // LIBCOMMON_GAMESESSIONWRITER_H
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -30,7 +30,7 @@
#include "g_controls.h"
#include "g_eventsequence.h"
#include "g_update.h"
#include "gamestatewriter.h"
#include "gamesessionwriter.h"
#include "hu_lib.h"
#include "hu_chat.h"
#include "hu_inventory.h"
Expand Down Expand Up @@ -2940,7 +2940,7 @@ static int saveGameStateWorker(void *context)
App_Log(DE2_LOG_VERBOSE, "Attempting save game to \"%s\"",
sessionPath.toString().toLatin1().constData());

GameStateWriter().write(sessionPath, mapStateFilePath, *metadata);
GameSessionWriter().write(sessionPath, mapStateFilePath, *metadata);

// Swap the saved session file.
G_SavedSessionRepository().add(sslot.repositoryPath(), session);
Expand Down
@@ -1,4 +1,4 @@
/** @file gamestatewriter.cpp Saved game state writer.
/** @file gamesessionwriter.cpp Serializing game state to a saved session.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -19,21 +19,21 @@
*/

#include "common.h"
#include "gamestatewriter.h"
#include "gamesessionwriter.h"

#include "d_net.h" // NetSv_SaveGame
#include "g_common.h" // gameMapUri
#include "d_net.h" // NetSv_SaveGame
#include "g_common.h" // gameMapUri
#include "mapstatewriter.h"
#include "p_savedef.h" // CONSISTENCY
#include "p_savedef.h" // CONSISTENCY
#include "p_saveio.h"
#include "p_saveg.h" /// playerheader_t @todo remove me
#include "p_saveg.h" /// playerheader_t @todo remove me
#include "thingarchive.h"
#include <de/NativePath>

using namespace de;
using namespace de::game;

DENG2_PIMPL(GameStateWriter)
DENG2_PIMPL(GameSessionWriter)
{
ThingArchive *thingArchive;
writer_s *writer;
Expand Down Expand Up @@ -118,10 +118,10 @@ DENG2_PIMPL(GameStateWriter)
}
};

GameStateWriter::GameStateWriter() : d(new Instance(this))
GameSessionWriter::GameSessionWriter() : d(new Instance(this))
{}

void GameStateWriter::write(Path const &stateFilePath, Path const &mapStateFilePath,
void GameSessionWriter::write(Path const &stateFilePath, Path const &mapStateFilePath,
SessionMetadata const &metadata)
{
// In networked games the server tells the clients to save their games.
Expand All @@ -131,7 +131,7 @@ void GameStateWriter::write(Path const &stateFilePath, Path const &mapStateFileP

if(!SV_OpenFile_LZSS(stateFilePath))
{
throw FileAccessError("GameStateWriter", "Failed opening \"" + NativePath(stateFilePath).pretty() + "\" for write");
throw FileAccessError("GameSessionWriter", "Failed opening \"" + NativePath(stateFilePath).pretty() + "\" for write");
}

d->writer = SV_NewWriter();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/mapstatereader.cpp
Expand Up @@ -156,7 +156,7 @@ DENG2_PIMPL(MapStateReader)
if(Reader_ReadByte(reader) != CONSISTENCY)
{
/// @throw ReadError Failed alignment check.
throw ReadError("GameStateReader", "Corrupt save game, failed consistency check");
throw ReadError("MapStateReader", "Corrupt save game, failed consistency check");
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/doom/src/doomv9mapstatereader.cpp
Expand Up @@ -694,7 +694,7 @@ DENG2_PIMPL(DoomV9MapStateReader)
break;

default:
throw ReadError("DoomV9GameStateReader", "Unknown tclass #" + String::number(tClass) + "in savegame");
throw ReadError("DoomV9MapStateReader", "Unknown tclass #" + String::number(tClass) + "in savegame");
}
}
}
Expand Down Expand Up @@ -792,7 +792,7 @@ DENG2_PIMPL(DoomV9MapStateReader)
break; }

default:
throw ReadError("DoomV9GameStateReader", "Unknown tclass #" + String::number(tClass) + "in savegame");
throw ReadError("DoomV9MapStateReader", "Unknown tclass #" + String::number(tClass) + "in savegame");
}
}
}
Expand Down Expand Up @@ -886,7 +886,7 @@ void DoomV9MapStateReader::read(String const &mapUriStr)

if(consistency != 0x1d)
{
throw ReadError("DoomV9GameStateReader", "Bad savegame (consistency test failed!)");
throw ReadError("DoomV9MapStateReader", "Bad savegame (consistency test failed!)");
}

// Material scrollers must be spawned.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/heretic/src/hereticv13mapstatereader.cpp
Expand Up @@ -710,7 +710,7 @@ DENG2_PIMPL(HereticV13MapStateReader)
break;

default:
throw ReadError("HereticV13GameStateReader", "Unknown tclass #" + String::number(tclass) + "in savegame");
throw ReadError("HereticV13MapStateReader", "Unknown tclass #" + String::number(tclass) + "in savegame");
}
}
}
Expand Down Expand Up @@ -802,7 +802,7 @@ DENG2_PIMPL(HereticV13MapStateReader)
break; }

default:
throw ReadError("HereticV13GameStateReader", "Unknown tclass #" + String::number(tclass) + "in savegame");
throw ReadError("HereticV13MapStateReader", "Unknown tclass #" + String::number(tclass) + "in savegame");
}
}
}
Expand Down Expand Up @@ -899,7 +899,7 @@ void HereticV13MapStateReader::read(String const &mapUriStr)

if(consistency != 0x1d)
{
throw ReadError("HereticV13GameStateReader", "Bad savegame (consistency test failed!)");
throw ReadError("HereticV13MapStateReader", "Bad savegame (consistency test failed!)");
}

// Material scrollers must be spawned.
Expand Down

0 comments on commit b2101c0

Please sign in to comment.