Navigation Menu

Skip to content

Commit

Permalink
libcommon|GameSessionWriter|MapStateWriter: Relocated map state seria…
Browse files Browse the repository at this point in the history
…lization from the session writer
  • Loading branch information
danij-deng committed Mar 21, 2014
1 parent 22b3d60 commit ef290eb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
38 changes: 1 addition & 37 deletions doomsday/plugins/common/src/gamesessionwriter.cpp
Expand Up @@ -83,34 +83,6 @@ DENG2_PIMPL(GameSessionWriter)
{
MapStateWriter(*thingArchive).write(writer);
}

void writePlayers()
{
beginSegment(ASEG_PLAYER_HEADER);
playerheader_t plrHdr;
plrHdr.write(writer);

beginSegment(ASEG_PLAYERS);
{
#if __JHEXEN__
for(int i = 0; i < MAXPLAYERS; ++i)
{
Writer_WriteByte(writer, players[i].plr->inGame);
}
#endif

for(int i = 0; i < MAXPLAYERS; ++i)
{
player_t *plr = players + i;
if(!plr->plr->inGame)
continue;

Writer_WriteInt32(writer, Net_GetPlayerID(i));
plr->write(writer, plrHdr);
}
}
endSegment();
}
};

GameSessionWriter::GameSessionWriter(SavedSession &session)
Expand All @@ -119,7 +91,7 @@ GameSessionWriter::GameSessionWriter(SavedSession &session)

void GameSessionWriter::write(String const &userDescription)
{
de::game::SessionMetadata *metadata = G_CurrentSessionMetadata();
SessionMetadata *metadata = G_CurrentSessionMetadata();

// In networked games the server tells the clients to save their games.
#if !__JHEXEN__
Expand All @@ -141,14 +113,6 @@ void GameSessionWriter::write(String const &userDescription)
d->writer = SV_NewWriter();
d->writeWorldACScriptData();

// Set the mobj archive numbers.
d->thingArchive = new ThingArchive;
d->thingArchive->initForSave(false/*do not exclude players*/);
#if !__JHEXEN__
Writer_WriteInt32(d->writer, d->thingArchive->size());
#endif
d->writePlayers();

// Serialized map states are written to separate files.
SV_CloseFile();
SV_OpenFileForWrite(mapStateFilePath);
Expand Down
48 changes: 43 additions & 5 deletions doomsday/plugins/common/src/mapstatewriter.cpp
Expand Up @@ -83,12 +83,10 @@ DENG2_PIMPL(MapStateWriter)

void writeMapHeader()
{
Writer_WriteInt32(writer, MY_SAVE_MAGIC);

// Map states have a version number.
Writer_WriteInt32(writer, MY_SAVE_VERSION);

#if __JHEXEN__
// Maps have their own version number.
Writer_WriteByte(writer, MY_SAVE_VERSION);

// Write the map timer
Writer_WriteInt32(writer, mapTime);
#endif
Expand All @@ -99,6 +97,34 @@ DENG2_PIMPL(MapStateWriter)
MaterialArchive_Write(materialArchive, writer);
}

void writePlayers()
{
beginSegment(ASEG_PLAYER_HEADER);
playerheader_t plrHdr;
plrHdr.write(writer);

beginSegment(ASEG_PLAYERS);
{
#if __JHEXEN__
for(int i = 0; i < MAXPLAYERS; ++i)
{
Writer_WriteByte(writer, players[i].plr->inGame);
}
#endif

for(int i = 0; i < MAXPLAYERS; ++i)
{
player_t *plr = players + i;
if(!plr->plr->inGame)
continue;

Writer_WriteInt32(writer, Net_GetPlayerID(i));
plr->write(writer, plrHdr);
}
}
endSegment();
}

void writeElements()
{
beginSegment(ASEG_MAP_ELEMENTS);
Expand Down Expand Up @@ -283,6 +309,18 @@ void MapStateWriter::write(Writer *writer)
// Prepare and populate the material archive.
d->materialArchive = MaterialArchive_New(useMaterialArchiveSegments());

Writer_WriteInt32(writer, MY_SAVE_MAGIC);
Writer_WriteInt32(writer, MY_SAVE_VERSION);

// Set the mobj archive numbers.
d->thingArchive = new ThingArchive;
d->thingArchive->initForSave(false/*do not exclude players*/);
#if !__JHEXEN__
Writer_WriteInt32(d->writer, d->thingArchive->size());
#endif

d->writePlayers();

// Serialize the map.
d->beginSegment(ASEG_MAP_HEADER2);
{
Expand Down

0 comments on commit ef290eb

Please sign in to comment.