Skip to content

Commit

Permalink
#5229: Fix layer and selection set info file sections being written t…
Browse files Browse the repository at this point in the history
…wice to the .darkradiant file in consecutive saves.

Reminder to myself: std::stringstream::clear() doesn't clear its contents, it just clears the state bits.
  • Loading branch information
codereader committed Apr 26, 2020
1 parent 6df92e8 commit 965dab7
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 24 deletions.
21 changes: 13 additions & 8 deletions radiant/layers/LayerInfoFileModule.cpp
Expand Up @@ -31,12 +31,21 @@ std::string LayerInfoFileModule::getName()
return "Layer Mapping";
}

void LayerInfoFileModule::onInfoFileSaveStart()
void LayerInfoFileModule::clear()
{
_layerInfoCount = 0;
_output.str(std::string());
_output.clear();
_layerNameBuffer.str(std::string());
_layerNameBuffer.clear();

_layerNames.clear();
_layerMappings.clear();
}

void LayerInfoFileModule::onInfoFileSaveStart()
{
clear();
}

void LayerInfoFileModule::onBeginSaveMap(const scene::IMapRootNodePtr& root)
Expand Down Expand Up @@ -115,15 +124,12 @@ void LayerInfoFileModule::writeBlocks(std::ostream& stream)

void LayerInfoFileModule::onInfoFileSaveFinished()
{
_layerInfoCount = 0;
_output.str(std::string());
_output.clear();
clear();
}

void LayerInfoFileModule::onInfoFileLoadStart()
{
_layerNames.clear();
_layerMappings.clear();
clear();
}

bool LayerInfoFileModule::canParseBlock(const std::string& blockName)
Expand Down Expand Up @@ -279,8 +285,7 @@ void LayerInfoFileModule::applyInfoToScene(const IMapRootNodePtr& root, const ma

void LayerInfoFileModule::onInfoFileLoadFinished()
{
_layerNames.clear();
_layerMappings.clear();
clear();
}

}
2 changes: 1 addition & 1 deletion radiant/layers/LayerInfoFileModule.h
Expand Up @@ -48,7 +48,7 @@ class LayerInfoFileModule :

private:
void saveNode(const INodePtr& node);
void writeLayerNames(std::ostream& stream);
void clear();

void parseLayerNames(parser::DefTokeniser& tok);
void parseNodeToLayerMapping(parser::DefTokeniser& tok);
Expand Down
14 changes: 11 additions & 3 deletions radiant/map/MapPropertyInfoFileModule.cpp
Expand Up @@ -18,8 +18,15 @@ std::string MapPropertyInfoFileModule::getName()
return "Map Properties";
}

void MapPropertyInfoFileModule::clear()
{
_store.clearProperties();
}

void MapPropertyInfoFileModule::onInfoFileSaveStart()
{}
{
clear();
}

void MapPropertyInfoFileModule::onBeginSaveMap(const scene::IMapRootNodePtr& root)
{
Expand Down Expand Up @@ -62,12 +69,12 @@ void MapPropertyInfoFileModule::writeBlocks(std::ostream& stream)

void MapPropertyInfoFileModule::onInfoFileSaveFinished()
{
_store.clearProperties();
clear();
}

void MapPropertyInfoFileModule::onInfoFileLoadStart()
{
_store.clearProperties();
clear();
}

bool MapPropertyInfoFileModule::canParseBlock(const std::string& blockName)
Expand Down Expand Up @@ -123,6 +130,7 @@ void MapPropertyInfoFileModule::applyInfoToScene(const scene::IMapRootNodePtr& r
void MapPropertyInfoFileModule::onInfoFileLoadFinished()
{
rMessage() << "[InfoFile]: Parsed " << _store.getPropertyCount() << " map properties." << std::endl;
clear();
}

}
3 changes: 3 additions & 0 deletions radiant/map/MapPropertyInfoFileModule.h
Expand Up @@ -32,6 +32,9 @@ class MapPropertyInfoFileModule :
void parseBlock(const std::string& blockName, parser::DefTokeniser& tok) override;
void applyInfoToScene(const scene::IMapRootNodePtr& root, const NodeIndexMap& nodeMap) override;
void onInfoFileLoadFinished() override;

private:
void clear();
};

}
21 changes: 13 additions & 8 deletions radiant/selection/group/SelectionGroupInfoFileModule.cpp
Expand Up @@ -28,14 +28,23 @@ std::string SelectionGroupInfoFileModule::getName()
return "Selection Groups";
}

void SelectionGroupInfoFileModule::onInfoFileSaveStart()
void SelectionGroupInfoFileModule::clear()
{
_groupInfo.clear();
_nodeMapping.clear();

_output.str(std::string());
_output.clear();
_selectionGroupBuffer.str(std::string());
_selectionGroupBuffer.clear();
_nodeInfoCount = 0;
}

void SelectionGroupInfoFileModule::onInfoFileSaveStart()
{
clear();
}

void SelectionGroupInfoFileModule::onBeginSaveMap(const scene::IMapRootNodePtr& root)
{
// Selection Group output
Expand Down Expand Up @@ -151,15 +160,12 @@ void SelectionGroupInfoFileModule::writeBlocks(std::ostream& stream)

void SelectionGroupInfoFileModule::onInfoFileSaveFinished()
{
_output.str(std::string());
_output.clear();
_nodeInfoCount = 0;
clear();
}

void SelectionGroupInfoFileModule::onInfoFileLoadStart()
{
_groupInfo.clear();
_nodeMapping.clear();
clear();
}

bool SelectionGroupInfoFileModule::canParseBlock(const std::string& blockName)
Expand Down Expand Up @@ -346,8 +352,7 @@ void SelectionGroupInfoFileModule::applyInfoToScene(const scene::IMapRootNodePtr

void SelectionGroupInfoFileModule::onInfoFileLoadFinished()
{
_groupInfo.clear();
_nodeMapping.clear();
clear();
}

}
1 change: 1 addition & 0 deletions radiant/selection/group/SelectionGroupInfoFileModule.h
Expand Up @@ -57,6 +57,7 @@ class SelectionGroupInfoFileModule :
void saveNode(const scene::INodePtr& node, std::size_t entityNum, std::size_t primitiveNum);
void parseSelectionGroups(parser::DefTokeniser& tok);
void parseNodeMappings(parser::DefTokeniser& tok);
void clear();
};

}
14 changes: 10 additions & 4 deletions radiant/selection/selectionset/SelectionSetInfoFileModule.cpp
Expand Up @@ -21,6 +21,12 @@ std::string SelectionSetInfoFileModule::getName()
return "Selection Set Mapping";
}

void SelectionSetInfoFileModule::clear()
{
_importInfo.clear();
_exportInfo.clear();
}

void SelectionSetInfoFileModule::onBeginSaveMap(const scene::IMapRootNodePtr& root)
{
// Visit all selection sets and assemble the info into the structures
Expand All @@ -39,7 +45,7 @@ void SelectionSetInfoFileModule::onFinishSaveMap(const scene::IMapRootNodePtr& r

void SelectionSetInfoFileModule::onInfoFileSaveStart()
{
_exportInfo.clear();
clear();
}

void SelectionSetInfoFileModule::onSavePrimitive(const scene::INodePtr& node, std::size_t entityNum, std::size_t primitiveNum)
Expand Down Expand Up @@ -107,12 +113,12 @@ void SelectionSetInfoFileModule::writeBlocks(std::ostream& stream)

void SelectionSetInfoFileModule::onInfoFileSaveFinished()
{
_exportInfo.clear();
clear();
}

void SelectionSetInfoFileModule::onInfoFileLoadStart()
{
_importInfo.clear();
clear();
}

bool SelectionSetInfoFileModule::canParseBlock(const std::string& blockName)
Expand Down Expand Up @@ -228,7 +234,7 @@ void SelectionSetInfoFileModule::applyInfoToScene(const scene::IMapRootNodePtr&

void SelectionSetInfoFileModule::onInfoFileLoadFinished()
{
_importInfo.clear();
clear();
}

}
3 changes: 3 additions & 0 deletions radiant/selection/selectionset/SelectionSetInfoFileModule.h
Expand Up @@ -58,6 +58,9 @@ class SelectionSetInfoFileModule :
void parseBlock(const std::string& blockName, parser::DefTokeniser& tok) override;
void applyInfoToScene(const scene::IMapRootNodePtr& root, const map::NodeIndexMap& nodeMap) override;
void onInfoFileLoadFinished() override;

private:
void clear();
};

}

0 comments on commit 965dab7

Please sign in to comment.