Move code that doesn't need to be templated to another class.
This commit is contained in:
parent
9f9ab65ff3
commit
d815b394ea
3 changed files with 145 additions and 100 deletions
|
@ -35,6 +35,8 @@
|
|||
|
||||
namespace dkh {
|
||||
namespace {
|
||||
typedef std::map<std::string, std::string> CommentMap;
|
||||
|
||||
const uint32_t g_signature = 0x52504B44; //DKPR
|
||||
|
||||
template <typename T> T lil_endian_to_machine ( T parIn ) a_pure;
|
||||
|
@ -148,16 +150,6 @@ namespace dkh {
|
|||
bool isdigit (char parChar) {
|
||||
return std::isdigit(parChar);
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
namespace implem {
|
||||
void read_header (std::istream& parStream, TylerMapHeader& parHeader) {
|
||||
parStream.read(reinterpret_cast<char*>(&parHeader), sizeof(TylerMapHeader));
|
||||
parHeader = lil_endian_to_machine(parHeader);
|
||||
|
||||
if (g_signature != parHeader.signature)
|
||||
throw InvalidMapFileException();
|
||||
}
|
||||
|
||||
void read_comments (std::istream& parStream, std::string& parVendor, CommentMap& parComments) {
|
||||
//Technically there is no limit on strings other than the uint32
|
||||
|
@ -177,25 +169,6 @@ namespace dkh {
|
|||
}
|
||||
}
|
||||
|
||||
void read_layer_header (std::istream& parStream, TylerMapLayerHeader& parHeader) {
|
||||
parStream.read(reinterpret_cast<char*>(&parHeader), sizeof(TylerMapLayerHeader));
|
||||
parHeader = lil_endian_to_machine(parHeader);
|
||||
}
|
||||
|
||||
void read_dimensions (std::istream& parStream, uint32_t parDimensions, std::vector<uint32_t>& parMap, std::vector<uint16_t>& parTile) {
|
||||
parMap.reserve(parMap.size() + parDimensions);
|
||||
for (uint32_t z = 0; z < parDimensions; ++z) {
|
||||
const auto dim = read_int<uint32_t>(parStream);
|
||||
parMap.push_back(dim);
|
||||
}
|
||||
|
||||
parTile.reserve(parTile.size() + parDimensions);
|
||||
for (uint32_t z = 0; z < parDimensions; ++z) {
|
||||
const auto dim = read_int<uint16_t>(parStream);
|
||||
parTile.push_back(dim);
|
||||
}
|
||||
}
|
||||
|
||||
void extract_array_from_comments (std::vector<std::string>& parOut, const std::string& parPrefix, const std::map<std::string, std::string>& parMap) {
|
||||
typedef decltype(std::distance(parPrefix.begin(), parPrefix.end())) diff_type;
|
||||
using std::size_t;
|
||||
|
@ -235,5 +208,104 @@ namespace dkh {
|
|||
parOut[index] = itcurr.second;
|
||||
}
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
namespace implem {
|
||||
struct TylerMapSourceBase::LayerInfo {
|
||||
dk::HashType hash;
|
||||
uint32_t data_start;
|
||||
uint32_t data_length;
|
||||
};
|
||||
|
||||
TylerMapSourceBase::TylerMapSourceBase (pos_type parStreamStartPos) :
|
||||
m_stream_start(parStreamStartPos)
|
||||
{
|
||||
}
|
||||
|
||||
TylerMapSourceBase::~TylerMapSourceBase() {
|
||||
}
|
||||
|
||||
dk::HashType TylerMapSourceBase::layerTypeHash (int parIndex) const {
|
||||
DK_ASSERT(parIndex >= 0);
|
||||
DK_ASSERT(static_cast<std::size_t>(parIndex) < m_layers_info.size());
|
||||
return m_layers_info[parIndex].hash;
|
||||
}
|
||||
|
||||
void TylerMapSourceBase::chainedMaps (std::vector<std::string>& parOut) const {
|
||||
extract_array_from_comments(parOut, "chained_map", m_comments);
|
||||
}
|
||||
|
||||
dk::MapTypes TylerMapSourceBase::mapType() const {
|
||||
return m_map_type;
|
||||
}
|
||||
|
||||
void TylerMapSourceBase::parseMapHeaders (std::istream& parSrc, uint32_t parDim, std::vector<uint32_t>& parMapDims, std::vector<uint16_t>& parTileDims) {
|
||||
//Read file header
|
||||
implem::TylerMapHeader header;
|
||||
implem::read_header(parSrc, header);
|
||||
|
||||
if (header.dimensions != parDim) {
|
||||
throw InvalidMapDimensionsException();
|
||||
}
|
||||
|
||||
switch (header.map_type) {
|
||||
case dk::MapType_IsometricStaggered:
|
||||
m_map_type = dk::MapType_IsometricStaggered;
|
||||
break;
|
||||
case dk::MapType_Isometric:
|
||||
m_map_type = dk::MapType_Isometric;
|
||||
break;
|
||||
case dk::MapType_Orthogonal:
|
||||
m_map_type = dk::MapType_Orthogonal;
|
||||
break;
|
||||
case dk::MapType_Hex:
|
||||
m_map_type = dk::MapType_Hex;
|
||||
break;
|
||||
default:
|
||||
throw InvalidMapFileException();
|
||||
}
|
||||
|
||||
//Read map and tile dimensions
|
||||
{
|
||||
std::vector<uint32_t> map_dims;
|
||||
std::vector<uint16_t> tile_dims;
|
||||
const auto read_start = (header.dimensions_start > sizeof(header) ? header.dimensions_start - sizeof(header) : sizeof(header));
|
||||
parSrc.seekg(read_start, std::ios_base::cur);
|
||||
implem::read_dimensions(parSrc, parDim, map_dims, tile_dims);
|
||||
parMapDims.swap(map_dims);
|
||||
parTileDims.swap(tile_dims);
|
||||
}
|
||||
|
||||
//Read vorbis comments
|
||||
parSrc.seekg(header.comment_start + m_stream_start, std::ios_base::beg);
|
||||
read_comments(parSrc, m_file_vendor, m_comments);
|
||||
}
|
||||
|
||||
void read_header (std::istream& parStream, TylerMapHeader& parHeader) {
|
||||
parStream.read(reinterpret_cast<char*>(&parHeader), sizeof(TylerMapHeader));
|
||||
parHeader = lil_endian_to_machine(parHeader);
|
||||
|
||||
if (g_signature != parHeader.signature)
|
||||
throw InvalidMapFileException();
|
||||
}
|
||||
|
||||
void read_layer_header (std::istream& parStream, TylerMapLayerHeader& parHeader) {
|
||||
parStream.read(reinterpret_cast<char*>(&parHeader), sizeof(TylerMapLayerHeader));
|
||||
parHeader = lil_endian_to_machine(parHeader);
|
||||
}
|
||||
|
||||
void read_dimensions (std::istream& parStream, uint32_t parDimensions, std::vector<uint32_t>& parMap, std::vector<uint16_t>& parTile) {
|
||||
parMap.reserve(parMap.size() + parDimensions);
|
||||
for (uint32_t z = 0; z < parDimensions; ++z) {
|
||||
const auto dim = read_int<uint32_t>(parStream);
|
||||
parMap.push_back(dim);
|
||||
}
|
||||
|
||||
parTile.reserve(parTile.size() + parDimensions);
|
||||
for (uint32_t z = 0; z < parDimensions; ++z) {
|
||||
const auto dim = read_int<uint16_t>(parStream);
|
||||
parTile.push_back(dim);
|
||||
}
|
||||
}
|
||||
} //namespace implem
|
||||
} //namespace dkh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue