Skip to content

Commit

Permalink
libcommon|MapStateWriter: MapStateWriter now has ThingArchive ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 21, 2014
1 parent ef290eb commit 4f14a8f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/mapstatewriter.h
Expand Up @@ -33,7 +33,7 @@
class MapStateWriter
{
public:
MapStateWriter(ThingArchive &thingArchive);
MapStateWriter();

/**
* Serialize the map state using the specified @a reader.
Expand Down
6 changes: 1 addition & 5 deletions doomsday/plugins/common/src/gamesessionwriter.cpp
Expand Up @@ -41,20 +41,17 @@ using de::game::SessionMetadata;
DENG2_PIMPL(GameSessionWriter)
{
SavedSession &session; // Saved session to be updated Not owned.
ThingArchive *thingArchive;
writer_s *writer;

Instance(Public *i, SavedSession &session)
: Base(i)
, session (session)
, thingArchive(0)
, writer (0)
{}

~Instance()
{
Writer_Delete(writer);
delete thingArchive;
}

void beginSegment(int segId)
Expand All @@ -81,7 +78,7 @@ DENG2_PIMPL(GameSessionWriter)

void writeMap()
{
MapStateWriter(*thingArchive).write(writer);
MapStateWriter().write(writer);
}
};

Expand Down Expand Up @@ -126,7 +123,6 @@ void GameSessionWriter::write(String const &userDescription)
LOG_MSG("Wrote ") << outFile.as<NativeFile>().nativePath().pretty();

// Cleanup.
delete d->thingArchive; d->thingArchive = 0;
Writer_Delete(d->writer); d->writer = 0;

delete metadata;
Expand Down
11 changes: 5 additions & 6 deletions doomsday/plugins/common/src/mapstatewriter.cpp
Expand Up @@ -44,7 +44,7 @@ using namespace internal;

DENG2_PIMPL(MapStateWriter)
{
ThingArchive *thingArchive; // Not owned.
ThingArchive *thingArchive;
MaterialArchive *materialArchive;
Writer *writer; // Not owned.

Expand All @@ -58,6 +58,7 @@ DENG2_PIMPL(MapStateWriter)
~Instance()
{
MaterialArchive_Delete(materialArchive);
delete thingArchive;
}

void beginSegment(int segId)
Expand Down Expand Up @@ -295,11 +296,8 @@ DENG2_PIMPL(MapStateWriter)
}
};

MapStateWriter::MapStateWriter(ThingArchive &thingArchive)
: d(new Instance(this))
{
d->thingArchive = &thingArchive;
}
MapStateWriter::MapStateWriter() : d(new Instance(this))
{}

void MapStateWriter::write(Writer *writer)
{
Expand Down Expand Up @@ -340,6 +338,7 @@ void MapStateWriter::write(Writer *writer)

// Cleanup.
MaterialArchive_Delete(d->materialArchive); d->materialArchive = 0;
delete d->thingArchive; d->thingArchive = 0;
}

ThingArchive::SerialId MapStateWriter::serialIdFor(mobj_t *mobj)
Expand Down

0 comments on commit 4f14a8f

Please sign in to comment.