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-06-07 01:57:18 +00:00
|
|
|
#include "doorkeeper/components/exception.hpp"
|
2015-05-28 22:15:06 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <ciso646>
|
|
|
|
|
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-28 17:11:21 +00:00
|
|
|
namespace implem {
|
|
|
|
class TylerMapSourceBase {
|
|
|
|
public:
|
|
|
|
typedef std::istream::pos_type pos_type;
|
|
|
|
|
2015-08-16 20:29:34 +00:00
|
|
|
explicit TylerMapSourceBase ( std::istream* parStream );
|
2015-06-28 17:11:21 +00:00
|
|
|
~TylerMapSourceBase ( void );
|
|
|
|
|
|
|
|
dk::HashType layerTypeHash ( int parIndex ) const;
|
|
|
|
void chainedMaps ( std::vector<std::string>& parOut ) const;
|
|
|
|
dk::MapTypes mapType ( void ) const;
|
2015-08-16 20:29:34 +00:00
|
|
|
void parseMapHeaders ( uint32_t parDim, std::vector<uint32_t>& parMapDims, std::vector<uint16_t>& parTileDims );
|
2015-06-28 17:11:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct LayerInfo;
|
|
|
|
|
|
|
|
std::vector<LayerInfo> m_layers_info;
|
|
|
|
dk::MapTypes m_map_type;
|
|
|
|
std::map<std::string, std::string> m_comments;
|
|
|
|
std::string m_file_vendor;
|
2015-08-16 20:29:34 +00:00
|
|
|
std::unique_ptr<std::istream> m_stream;
|
2015-06-28 17:11:21 +00:00
|
|
|
pos_type m_stream_start;
|
|
|
|
};
|
|
|
|
} //namespace implem
|
|
|
|
|
2015-06-06 12:14:00 +00:00
|
|
|
template <uint32_t D>
|
2015-06-28 17:11:21 +00:00
|
|
|
class TylerMapSource : private implem::TylerMapSourceBase, public dk::BaseMapSource<D> {
|
|
|
|
typedef implem::TylerMapSourceBase base_class;
|
|
|
|
typedef base_class::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;
|
2015-06-07 01:57:18 +00:00
|
|
|
virtual dk::HashType layerTypeHash ( int parIndex ) const;
|
2015-05-28 22:15:06 +00:00
|
|
|
|
|
|
|
private:
|
2015-08-16 20:29:34 +00:00
|
|
|
void parse_map_data ( void );
|
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
|
|
|
|
2015-06-06 12:32:36 +00:00
|
|
|
coords m_map_size;
|
|
|
|
coords m_tile_size;
|
|
|
|
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-06-07 01:57:18 +00:00
|
|
|
class InvalidMapFileException : public dk::DoorKeeperException {
|
2015-05-28 22:15:06 +00:00
|
|
|
};
|
2015-06-07 01:57:18 +00:00
|
|
|
class InvalidMapDimensionsException : public dk::DoorKeeperException {
|
2015-06-06 12:32:36 +00:00
|
|
|
};
|
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;
|
2015-06-07 01:57:18 +00:00
|
|
|
uint8_t hashing_algorithm;
|
2015-05-28 22:15:06 +00:00
|
|
|
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))));
|
|
|
|
|
|
|
|
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 );
|
|
|
|
void read_dimensions ( std::istream& parStream, uint32_t parDimensions, std::vector<uint32_t>& parMap, std::vector<uint16_t>& parTile );
|
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
|