2015-05-28 22:15:06 +00:00
|
|
|
#ifndef id3F4AB2FAA29D4A0FA87760E61F0762C0
|
|
|
|
#define id3F4AB2FAA29D4A0FA87760E61F0762C0
|
|
|
|
|
|
|
|
#include "doorkeeper/primitivetypes.hpp"
|
|
|
|
#include "doorkeeper/implem/vector.hpp"
|
|
|
|
#include "doorkeeper/components/basemapsource.hpp"
|
2015-06-06 12:32:36 +00:00
|
|
|
#include "doorkeeper/implem/maptypes.hpp"
|
2015-05-28 22:15:06 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <ciso646>
|
|
|
|
#include <exception>
|
|
|
|
|
2015-06-04 18:59:07 +00:00
|
|
|
#if !defined(NDEBUG) && !defined(WITH_TYLERMAP_WRITER)
|
|
|
|
# define WITH_TYLERMAP_WRITER
|
|
|
|
#endif
|
|
|
|
|
2015-05-28 22:15:06 +00:00
|
|
|
namespace dkh {
|
2015-06-06 12:14:00 +00:00
|
|
|
template <uint32_t D>
|
|
|
|
class TylerMapSource : public dk::BaseMapSource<D> {
|
2015-06-06 12:32:36 +00:00
|
|
|
typedef std::istream::pos_type pos_type;
|
2015-05-28 22:15:06 +00:00
|
|
|
public:
|
2015-06-06 11:52:48 +00:00
|
|
|
typedef dk::Vector<D> coords;
|
2015-05-28 22:15:06 +00:00
|
|
|
enum {
|
|
|
|
MapDimensions = D
|
|
|
|
};
|
|
|
|
|
|
|
|
TylerMapSource ( void ) = delete;
|
|
|
|
TylerMapSource ( const TylerMapSource& ) = delete;
|
|
|
|
TylerMapSource ( TylerMapSource&& ) = default;
|
|
|
|
explicit TylerMapSource ( const char* parFilename );
|
|
|
|
explicit TylerMapSource ( const std::string& parFilename );
|
|
|
|
explicit TylerMapSource ( std::istream* parData );
|
|
|
|
virtual ~TylerMapSource ( void ) noexcept = default;
|
|
|
|
|
|
|
|
virtual const coords& mapSize ( void ) const;
|
|
|
|
virtual const coords& tileSize ( void ) const;
|
|
|
|
virtual dk::MapTypes mapType ( void ) const;
|
|
|
|
virtual int layersCount ( void ) const;
|
|
|
|
virtual void chainedMaps ( std::vector<std::string>& parOut ) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void parse_map_data ( std::istream& parSrc );
|
2015-06-06 12:14:00 +00:00
|
|
|
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize );
|
2015-05-28 22:15:06 +00:00
|
|
|
|
|
|
|
std::unique_ptr<std::istream> m_stream;
|
2015-06-06 12:32:36 +00:00
|
|
|
|
|
|
|
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;
|
2015-05-28 22:15:06 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 18:59:07 +00:00
|
|
|
#if defined(WITH_TYLERMAP_WRITER)
|
|
|
|
class TylerMapWriter {
|
|
|
|
public:
|
|
|
|
TylerMapWriter ( void ) = delete;
|
|
|
|
TylerMapWriter ( const TylerMapWriter& ) = delete;
|
|
|
|
TylerMapWriter ( TylerMapWriter&& ) = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<std::ostream> m_stream;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-05-28 22:15:06 +00:00
|
|
|
class InvalidMapFileException : public std::exception {
|
|
|
|
};
|
2015-06-06 12:32:36 +00:00
|
|
|
class InvalidMapDimensionsException : public std::exception {
|
|
|
|
};
|
2015-05-28 22:15:06 +00:00
|
|
|
|
|
|
|
namespace implem {
|
|
|
|
struct TylerMapHeader {
|
|
|
|
uint32_t signature;
|
|
|
|
uint32_t file_size;
|
|
|
|
uint16_t version_major;
|
|
|
|
uint16_t version_minor;
|
|
|
|
uint8_t layer_count;
|
|
|
|
uint8_t map_type;
|
|
|
|
uint8_t map_info_type;
|
|
|
|
uint8_t dimensions;
|
2015-06-06 12:32:36 +00:00
|
|
|
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;
|
2015-05-28 22:15:06 +00:00
|
|
|
} __attribute__((packed, aligned(__alignof__(uint32_t))));
|
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> CommentMap;
|
|
|
|
|
|
|
|
void read_header ( std::istream& parStream, TylerMapHeader& parHeader );
|
2015-06-06 12:32:36 +00:00
|
|
|
void read_layer_header ( std::istream& parStream, TylerMapLayerHeader& parHeader );
|
2015-05-28 22:15:06 +00:00
|
|
|
void read_comments ( std::istream& parStream, std::string& parVendor, CommentMap& parComments );
|
2015-06-06 12:32:36 +00:00
|
|
|
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 );
|
2015-05-28 22:15:06 +00:00
|
|
|
} //namespace implem
|
|
|
|
} //namespace dkh
|
|
|
|
|
2015-06-06 12:32:36 +00:00
|
|
|
#include "doorkeeper/implem/tylermapsource.inl"
|
|
|
|
|
2015-05-28 22:15:06 +00:00
|
|
|
#endif
|