void Terrain::Tile::save(list<DataFile::Statement> &st) const
{
- bool flat = true;
- for(unsigned i=1; (flat && i<4); ++i)
- flat = (nodes[i].elevation==nodes[0].elevation && nodes[i].ground==nodes[0].ground && nodes[i].wall==nodes[0].wall);
- if(flat)
- {
- st.push_back((DataFile::Statement("elevation"), nodes[0].elevation));
- st.push_back((DataFile::Statement("ground"), nodes[0].ground));
- }
- else
+ float elevation_mode = find_mode(&Node::elevation);
+ unsigned ground_mode = find_mode(&Node::ground);
+ if(elevation_mode)
+ st.push_back((DataFile::Statement("elevation"), elevation_mode));
+ if(ground_mode)
+ st.push_back((DataFile::Statement("ground"), ground_mode));
+
+ for(unsigned i=0; i<4; ++i)
{
- for(unsigned i=0; i<4; ++i)
- {
- DataFile::Statement ss("node");
- ss.append(i);
- nodes[i].save(ss.sub);
- st.push_back(ss);
- }
+ if(nodes[i].elevation==elevation_mode && nodes[i].ground==ground_mode)
+ continue;
+
+ DataFile::Statement ss("node");
+ ss.append(i);
+ if(nodes[i].elevation!=elevation_mode)
+ ss.sub.push_back((DataFile::Statement("elevation"), nodes[i].elevation));
+ if(nodes[i].ground!=ground_mode)
+ ss.sub.push_back((DataFile::Statement("ground"), nodes[i].ground));
+ st.push_back(ss);
}
}
+template<typename T>
+T Terrain::Tile::find_mode(T Node::*member) const
+{
+ for(unsigned i=0; i<3; ++i)
+ for(unsigned j=i+1; j<4; ++j)
+ if(nodes[i].*member==nodes[j].*member)
+ return nodes[i].*member;
+ return T();
+}
+
Terrain::NodeCoordinates::NodeCoordinates():
x(0),