Progress implementing TylerMapSource.
This commit is contained in:
parent
ab17e7a4d0
commit
d21a567fb7
4 changed files with 204 additions and 4 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/vector.hpp"
|
||||
#include "doorkeeper/components/basemapsource.hpp"
|
||||
#include "doorkeeper/implem/maptypes.hpp"
|
||||
#include <fstream>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
@ -19,6 +20,7 @@
|
|||
namespace dkh {
|
||||
template <uint32_t D>
|
||||
class TylerMapSource : public dk::BaseMapSource<D> {
|
||||
typedef std::istream::pos_type pos_type;
|
||||
public:
|
||||
typedef dk::Vector<D> coords;
|
||||
enum {
|
||||
|
@ -44,6 +46,16 @@ namespace dkh {
|
|||
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize );
|
||||
|
||||
std::unique_ptr<std::istream> m_stream;
|
||||
|
||||
std::map<std::string, std::string> m_comments;
|
||||
coords m_map_size;
|
||||
coords m_tile_size;
|
||||
pos_type m_stream_start;
|
||||
std::string m_file_vendor;
|
||||
dk::MapTypes m_map_type;
|
||||
uint16_t m_map_version_major;
|
||||
uint16_t m_map_version_minor;
|
||||
uint8_t m_layer_count;
|
||||
};
|
||||
|
||||
#if defined(WITH_TYLERMAP_WRITER)
|
||||
|
@ -60,6 +72,8 @@ namespace dkh {
|
|||
|
||||
class InvalidMapFileException : public std::exception {
|
||||
};
|
||||
class InvalidMapDimensionsException : public std::exception {
|
||||
};
|
||||
|
||||
namespace implem {
|
||||
struct TylerMapHeader {
|
||||
|
@ -71,13 +85,27 @@ namespace dkh {
|
|||
uint8_t map_type;
|
||||
uint8_t map_info_type;
|
||||
uint8_t dimensions;
|
||||
uint32_t dimensions_start;
|
||||
uint32_t comment_start;
|
||||
uint32_t layer_start;
|
||||
} __attribute__((packed, aligned(__alignof__(uint32_t))));
|
||||
|
||||
struct TylerMapLayerHeader {
|
||||
uint32_t layer_length;
|
||||
uint32_t layer_format;
|
||||
} __attribute__((packed, aligned(__alignof__(uint32_t))));
|
||||
|
||||
typedef std::map<std::string, std::string> CommentMap;
|
||||
|
||||
void read_header ( std::istream& parStream, TylerMapHeader& parHeader );
|
||||
void read_layer_header ( std::istream& parStream, TylerMapLayerHeader& parHeader );
|
||||
void read_comments ( std::istream& parStream, std::string& parVendor, CommentMap& parComments );
|
||||
void read_dimensions ( std::istream& parStream, uint32_t parDimensions, std::vector<uint32_t>& parMap, std::vector<uint16_t>& parTile );
|
||||
|
||||
void extract_array_from_comments ( std::vector<std::string>& parOut, const std::string& parPrefix, const std::map<std::string, std::string>& parMap );
|
||||
} //namespace implem
|
||||
} //namespace dkh
|
||||
|
||||
#include "doorkeeper/implem/tylermapsource.inl"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,21 +1,103 @@
|
|||
namespace dkh {
|
||||
template <uint32_t D>
|
||||
TylerMapSource<D>::TylerMapSource (const char* parFilename) :
|
||||
m_stream(new std::ifstream(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(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(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);
|
||||
}
|
||||
} //namespace dkh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue