diff --git a/include/doorkeeper/components/basemapsource.hpp b/include/doorkeeper/components/basemapsource.hpp index 3ed13ee..cde13ef 100644 --- a/include/doorkeeper/components/basemapsource.hpp +++ b/include/doorkeeper/components/basemapsource.hpp @@ -12,6 +12,9 @@ #include namespace dk { + template + class PixelConv; + namespace implem { template ::value> class data_fetcher; @@ -35,6 +38,7 @@ namespace dk { virtual int layersCount ( void ) const = 0; virtual void chainedMaps ( std::vector& parOut ) const = 0; virtual HashType layerTypeHash ( int parIndex ) const = 0; + virtual const PixelConv& pixel_conv ( void ) const = 0; protected: virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize ) = 0; diff --git a/include/doorkeeper/components/pixelconv.hpp b/include/doorkeeper/components/pixelconv.hpp index e1b9c84..7f26ea7 100644 --- a/include/doorkeeper/components/pixelconv.hpp +++ b/include/doorkeeper/components/pixelconv.hpp @@ -7,10 +7,9 @@ #include namespace dk { - //MapType_IsometricStaggered, - //MapType_Isometric, - //MapType_Orthogonal, - //MapType_Hex + template + class TileIterator; + template class PixelConv { public: diff --git a/include/doorkeeper/components/tileiterator.hpp b/include/doorkeeper/components/tileiterator.hpp index 884aacf..b0a75cf 100644 --- a/include/doorkeeper/components/tileiterator.hpp +++ b/include/doorkeeper/components/tileiterator.hpp @@ -4,6 +4,7 @@ #include "doorkeeper/primitivetypes.hpp" #include "doorkeeper/implem/helpers.hpp" #include "doorkeeper/components/tilecoords.hpp" +#include "doorkeeper/components/pixelconv.hpp" #include #include #include @@ -15,6 +16,9 @@ namespace dk { template class TileIterator; + template + class PixelConv; + namespace implem { template struct TypeWithQualifiers { @@ -43,12 +47,13 @@ namespace dk { TileIterator ( void ) = default; TileIterator ( const TileIterator& parOther ) = default; TileIterator ( TileIterator&& parOther ) = default; - TileIterator ( qualif_vector_type* parData, const coords& parArea ); - TileIterator ( qualif_vector_type* parData, const coords& parStart, const coords& parArea ); + TileIterator ( qualif_vector_type* parData, const PixelConv& parPixConv, const coords& parArea ); + TileIterator ( qualif_vector_type* parData, const PixelConv& parPixConv, const coords& parStart, const coords& parArea ); ~TileIterator ( void ) = default; const TileCoordsType& raw_coords ( void ) const; const coords& position ( void ) const; + coords pixel_position ( void ) const; private: void increment ( void ); @@ -60,6 +65,7 @@ namespace dk { TileCoordsType m_tile_range;; qualif_vector_type* m_data; + const PixelConv& m_pixel_conv; }; template diff --git a/include/doorkeeper/helpers/asciimapsource.hpp b/include/doorkeeper/helpers/asciimapsource.hpp index 5fea469..e714454 100644 --- a/include/doorkeeper/helpers/asciimapsource.hpp +++ b/include/doorkeeper/helpers/asciimapsource.hpp @@ -4,6 +4,7 @@ #include "doorkeeper/primitivetypes.hpp" #include "doorkeeper/implem/vector.hpp" #include "doorkeeper/components/basemapsource.hpp" +#include "doorkeeper/components/pixelconv.hpp" #include #include @@ -34,6 +35,7 @@ namespace dkh { virtual const coords& tileSize ( void ) const; virtual void chainedMaps ( std::vector& parOut ) const; virtual dk::HashType layerTypeHash ( int parIndex ) const; + virtual const dk::PixelConv<2>& pixel_conv ( void ) const; private: void parse_map_data ( std::istream& parSrc ); @@ -41,7 +43,7 @@ namespace dkh { std::vector m_wholedata; const coords m_mapSize; - const coords m_tileSize; + const dk::PixelConvSquare<2> m_pixel_conv; const dk::MapTypes m_mapType; }; } //namespace dkh diff --git a/include/doorkeeper/implem/layer.inl b/include/doorkeeper/implem/layer.inl index 09694b5..4627c77 100644 --- a/include/doorkeeper/implem/layer.inl +++ b/include/doorkeeper/implem/layer.inl @@ -37,14 +37,14 @@ namespace dk { ///-------------------------------------------------------------------------- template typename Layer::iterator Layer::begin() { - return iterator(&m_tiles, coords(0), this->m_count); + return iterator(&m_tiles, m_tilemap->pixel_conv(), coords(0), this->m_count); } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template typename Layer::iterator Layer::end() { - return iterator(&m_tiles, make_past_end_coords(this->m_count - 1), make_past_end_coords(this->m_count - 1)); + return iterator(&m_tiles, m_tilemap->pixel_conv(), make_past_end_coords(this->m_count - 1), make_past_end_coords(this->m_count - 1)); } ///-------------------------------------------------------------------------- diff --git a/include/doorkeeper/implem/tileiterator.inl b/include/doorkeeper/implem/tileiterator.inl index c242040..7a2f651 100644 --- a/include/doorkeeper/implem/tileiterator.inl +++ b/include/doorkeeper/implem/tileiterator.inl @@ -1,18 +1,22 @@ namespace dk { template - TileIterator::TileIterator (qualif_vector_type* parData, const coords& parArea) : + TileIterator::TileIterator (qualif_vector_type* parData, const PixelConv& parPixConv, const coords& parArea) : m_tile_range(parArea), - m_data(parData) + m_data(parData), + m_pixel_conv(parPixConv) { DK_ASSERT(parData); + DK_ASSERT(&m_pixel_conv != nullptr); } template - TileIterator::TileIterator (qualif_vector_type* parData, const coords& parStart, const coords& parArea) : + TileIterator::TileIterator (qualif_vector_type* parData, const PixelConv& parPixConv, const coords& parStart, const coords& parArea) : m_tile_range(parStart, parArea), - m_data(parData) + m_data(parData), + m_pixel_conv(parPixConv) { DK_ASSERT(parData); + DK_ASSERT(&m_pixel_conv != nullptr); } template @@ -59,6 +63,11 @@ namespace dk { return m_tile_range.position(); } + template + auto TileIterator::pixel_position() const -> coords { + return m_pixel_conv.to_pixel(this->position()); + } + template inline Vector make_past_end_coords (const Vector& parTo) { Vector retval(0); diff --git a/include/doorkeeper/implem/viewport.inl b/include/doorkeeper/implem/viewport.inl index a60d94d..c05312c 100644 --- a/include/doorkeeper/implem/viewport.inl +++ b/include/doorkeeper/implem/viewport.inl @@ -20,14 +20,14 @@ namespace dk { template typename Layer::iterator Viewport::begin (Layer& parLayer) const { typedef typename Layer::iterator IterType; - return IterType(&parLayer.m_tiles, m_position, m_tyler.map_size() - 1); + return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_position, m_tyler.map_size() - 1); } template template typename Layer::iterator Viewport::end (Layer& parLayer) const { typedef typename Layer::iterator IterType; - return IterType(&parLayer.m_tiles, make_past_end_coords(m_tyler.map_size() - 1), make_past_end_coords(m_tyler.map_size() - 1)); + return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords(m_tyler.map_size() - 1), make_past_end_coords(m_tyler.map_size() - 1)); } template @@ -46,14 +46,14 @@ namespace dk { template typename Layer::const_iterator Viewport::cbegin (const Layer& parLayer) const { typedef typename Layer::const_iterator IterType; - return IterType(&parLayer.m_tiles, m_position, m_tyler.map_size() - 1); + return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_position, m_tyler.map_size() - 1); } template template typename Layer::const_iterator Viewport::cend (const Layer& parLayer) const { typedef typename Layer::const_iterator IterType; - return IterType(&parLayer.m_tiles, make_past_end_coords(m_tyler.map_size() - 1), make_past_end_coords(m_tyler.map_size() - 1)); + return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords(m_tyler.map_size() - 1), make_past_end_coords(m_tyler.map_size() - 1)); } template diff --git a/src/asciimapsource.cpp b/src/asciimapsource.cpp index 86f8634..0549d45 100644 --- a/src/asciimapsource.cpp +++ b/src/asciimapsource.cpp @@ -14,7 +14,7 @@ namespace dkh { ///------------------------------------------------------------------------- AsciiMapSource::AsciiMapSource (const char* parFilename, const coords& parSize, dk::MapTypes parMapType, const coords& parTileSize) : m_mapSize(parSize), - m_tileSize(parTileSize), + m_pixel_conv(parTileSize), m_mapType(parMapType) { std::ifstream src(parFilename); @@ -25,7 +25,7 @@ namespace dkh { ///------------------------------------------------------------------------- AsciiMapSource::AsciiMapSource (const std::string& parFilename, const coords& parSize, dk::MapTypes parMapType, const coords& parTileSize) : m_mapSize(parSize), - m_tileSize(parTileSize), + m_pixel_conv(parTileSize), m_mapType(parMapType) { std::ifstream src(parFilename); @@ -36,7 +36,7 @@ namespace dkh { ///------------------------------------------------------------------------- AsciiMapSource::AsciiMapSource (std::istream& parData, const coords& parSize, dk::MapTypes parMapType, const coords& parTileSize) : m_mapSize(parSize), - m_tileSize(parTileSize), + m_pixel_conv(parTileSize), m_mapType(parMapType) { parse_map_data(parData); @@ -88,7 +88,7 @@ namespace dkh { } const AsciiMapSource::coords& AsciiMapSource::tileSize() const { - return m_tileSize; + return m_pixel_conv.tile_size(); } void AsciiMapSource::fetch_raw (char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize) { @@ -118,4 +118,8 @@ namespace dkh { #endif return dk::type_name_hash(); } + + const dk::PixelConv<2>& AsciiMapSource::pixel_conv() const { + return m_pixel_conv; + } } //namespace dkh diff --git a/test/unit/asciimapsource.cpp b/test/unit/asciimapsource.cpp index 735919b..8309702 100644 --- a/test/unit/asciimapsource.cpp +++ b/test/unit/asciimapsource.cpp @@ -63,6 +63,7 @@ TEST_F(asciimapsource, coordinates) { const coords2 expected_coords(tsize * itTile.position()); const auto returned_coords(iso_conv.to_pixel(itTile.position())); EXPECT_EQ(expected_coords, returned_coords); + EXPECT_EQ(expected_coords, itTile.pixel_position()); } //Check staggered diamond coordinates, second row reentrant diff --git a/test/unit/tileiterator.cpp b/test/unit/tileiterator.cpp index b330d7e..a4b424c 100644 --- a/test/unit/tileiterator.cpp +++ b/test/unit/tileiterator.cpp @@ -1,5 +1,6 @@ #include #include "doorkeeper/components/tileiterator.hpp" +#include "doorkeeper/components/pixelconv.hpp" #include #include #include @@ -11,10 +12,11 @@ TEST(tileiterator, increment) { using boost::counting_iterator; std::vector data(counting_iterator(0), counting_iterator(100000)); + dk::PixelConvSquare<7> pixconv(coords7(16)); { const coords7 max_coords(99, 999, 2, 2, 2, 2, 2); - tileit7 it(&data, max_coords); + tileit7 it(&data, pixconv, max_coords); for (std::size_t z = 0; z < data.size(); ++z) { EXPECT_EQ(data[z], *it);