King_DuckZ
fd8a1cbabc
This is needed to recognize what type of tiles a layer contains. Client code has to fill in a map of hash => add_layer<T>() pointers. As a layer is loaded, the correct add_layer<T>() is called based on the hash saved with the layer itself.
117 lines
3.1 KiB
C++
117 lines
3.1 KiB
C++
namespace dkh {
|
|
template <uint32_t D>
|
|
struct TylerMapSource<D>::LayerInfo {
|
|
dk::HashType hash;
|
|
uint32_t data_start;
|
|
uint32_t data_length;
|
|
};
|
|
|
|
template <uint32_t D>
|
|
TylerMapSource<D>::TylerMapSource (const char* parFilename) :
|
|
m_stream(new std::ifstream(parFilename)),
|
|
m_stream_start(m_stream->tellg())
|
|
{
|
|
parse_map_data(*m_stream);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TylerMapSource<D>::TylerMapSource (const std::string& parFilename) :
|
|
m_stream(new std::ifstream(parFilename)),
|
|
m_stream_start(m_stream->tellg())
|
|
{
|
|
parse_map_data(*m_stream);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TylerMapSource<D>::TylerMapSource (std::istream* parData) :
|
|
m_stream(parData),
|
|
m_stream_start(m_stream->tellg())
|
|
{
|
|
parse_map_data(*m_stream);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
void TylerMapSource<D>::parse_map_data (std::istream& parSrc) {
|
|
//Read file header
|
|
implem::TylerMapHeader header;
|
|
implem::read_header(parSrc, header);
|
|
|
|
if (header.dimensions != D) {
|
|
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, D, map_dims, tile_dims);
|
|
for (std::size_t z = 0; z < map_dims.size(); ++z) {
|
|
m_map_size[z] = map_dims[z];
|
|
m_tile_size[z] = tile_dims[z];
|
|
}
|
|
}
|
|
|
|
//Read vorbis comments
|
|
parSrc.seekg(header.comment_start + m_stream_start, std::ios_base::beg);
|
|
implem::read_comments(parSrc, m_file_vendor, m_comments);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
const typename TylerMapSource<D>::coords& TylerMapSource<D>::mapSize() const {
|
|
return m_map_size;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
const typename TylerMapSource<D>::coords& TylerMapSource<D>::tileSize() const {
|
|
return m_tile_size;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
void TylerMapSource<D>::fetch_raw (char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize) {
|
|
(void)parOut;
|
|
(void)parFrom;
|
|
(void)parTo;
|
|
(void)parSize;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
dk::MapTypes TylerMapSource<D>::mapType() const {
|
|
return m_map_type;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
int TylerMapSource<D>::layersCount() const {
|
|
return m_layer_count;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
void TylerMapSource<D>::chainedMaps (std::vector<std::string>& parOut) const {
|
|
implem::extract_array_from_comments(parOut, "chained_map", m_comments);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
dk::HashType TylerMapSource<D>::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;
|
|
}
|
|
} //namespace dkh
|