Skip to content

Commit

Permalink
Change IMapWriter interface to take the IEntityNodePtr as argument in…
Browse files Browse the repository at this point in the history
…stead of Entity*. This way it can still access the scene::INode supporting the entity.
  • Loading branch information
codereader committed Jan 15, 2020
1 parent edec9e5 commit 862811c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions include/imapformat.h
Expand Up @@ -14,6 +14,8 @@ namespace parser { class DefTokeniser; }
class Entity;
class IBrush;
class IPatch;
class IEntityNode;
typedef std::shared_ptr<IEntityNode> IEntityNodePtr;

/** Callback function to control how the Walker traverses the scene graph. This function
* will be provided to the map export module by the Radiant map code.
Expand Down Expand Up @@ -106,8 +108,8 @@ class IMapWriter
virtual void endWriteMap(std::ostream& stream) = 0;

// Entity export methods
virtual void beginWriteEntity(const Entity& entity, std::ostream& stream) = 0;
virtual void endWriteEntity(const Entity& entity, std::ostream& stream) = 0;
virtual void beginWriteEntity(const IEntityNodePtr& entity, std::ostream& stream) = 0;
virtual void endWriteEntity(const IEntityNodePtr& entity, std::ostream& stream) = 0;

// Brush export methods
virtual void beginWriteBrush(const IBrush& brush, std::ostream& stream) = 0;
Expand Down
12 changes: 6 additions & 6 deletions radiant/map/algorithm/MapExporter.cpp
Expand Up @@ -123,14 +123,14 @@ bool MapExporter::pre(const scene::INodePtr& node)
{
try
{
Entity* entity = Node_getEntity(node);
IEntityNodePtr entity = std::dynamic_pointer_cast<IEntityNode>(node);

if (entity != NULL)
if (entity)
{
// Progress dialog handling
onNodeProgress();

_writer.beginWriteEntity(*entity, _mapStream);
_writer.beginWriteEntity(entity, _mapStream);

if (_infoFileExporter) _infoFileExporter->visitEntity(node, _entityNum);

Expand Down Expand Up @@ -177,11 +177,11 @@ void MapExporter::post(const scene::INodePtr& node)
{
try
{
Entity* entity = Node_getEntity(node);
IEntityNodePtr entity = std::dynamic_pointer_cast<IEntityNode>(node);

if (entity != NULL)
if (entity)
{
_writer.endWriteEntity(*entity, _mapStream);
_writer.endWriteEntity(entity, _mapStream);

_entityNum++;
return;
Expand Down
8 changes: 4 additions & 4 deletions radiant/map/format/Doom3MapWriter.cpp
Expand Up @@ -27,7 +27,7 @@ void Doom3MapWriter::endWriteMap(std::ostream& stream)
// nothing
}

void Doom3MapWriter::beginWriteEntity(const Entity& entity, std::ostream& stream)
void Doom3MapWriter::beginWriteEntity(const IEntityNodePtr& entity, std::ostream& stream)
{
// Write out the entity number comment
stream << "// entity " << _entityCount++ << std::endl;
Expand All @@ -39,16 +39,16 @@ void Doom3MapWriter::beginWriteEntity(const Entity& entity, std::ostream& stream
writeEntityKeyValues(entity, stream);
}

void Doom3MapWriter::writeEntityKeyValues(const Entity& entity, std::ostream& stream)
void Doom3MapWriter::writeEntityKeyValues(const IEntityNodePtr& entity, std::ostream& stream)
{
// Export the entity key values
entity.forEachKeyValue([&](const std::string& key, const std::string& value)
entity->getEntity().forEachKeyValue([&](const std::string& key, const std::string& value)
{
stream << "\"" << key << "\" \"" << value << "\"" << std::endl;
});
}

void Doom3MapWriter::endWriteEntity(const Entity& entity, std::ostream& stream)
void Doom3MapWriter::endWriteEntity(const IEntityNodePtr& entity, std::ostream& stream)
{
// Write the closing brace for the entity
stream << "}" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions radiant/map/format/Doom3MapWriter.h
Expand Up @@ -25,8 +25,8 @@ class Doom3MapWriter :
virtual void endWriteMap(std::ostream& stream);

// Entity export methods
virtual void beginWriteEntity(const Entity& entity, std::ostream& stream);
virtual void endWriteEntity(const Entity& entity, std::ostream& stream);
virtual void beginWriteEntity(const IEntityNodePtr& entity, std::ostream& stream);
virtual void endWriteEntity(const IEntityNodePtr& entity, std::ostream& stream);

// Brush export methods
virtual void beginWriteBrush(const IBrush& brush, std::ostream& stream);
Expand All @@ -37,7 +37,7 @@ class Doom3MapWriter :
virtual void endWritePatch(const IPatch& patch, std::ostream& stream);

protected:
void writeEntityKeyValues(const Entity& entity, std::ostream& stream);
void writeEntityKeyValues(const IEntityNodePtr& entity, std::ostream& stream);
};

} // namespace

0 comments on commit 862811c

Please sign in to comment.