Add pixel_position() to tile iterator.
This commit is contained in:
parent
a1ae683601
commit
ae05910316
10 changed files with 49 additions and 22 deletions
|
@ -12,6 +12,9 @@
|
|||
#include <cstddef>
|
||||
|
||||
namespace dk {
|
||||
template <uint32_t D>
|
||||
class PixelConv;
|
||||
|
||||
namespace implem {
|
||||
template <typename T, uint32_t D, bool POD=std::is_pod<T>::value>
|
||||
class data_fetcher;
|
||||
|
@ -35,6 +38,7 @@ namespace dk {
|
|||
virtual int layersCount ( void ) const = 0;
|
||||
virtual void chainedMaps ( std::vector<std::string>& parOut ) const = 0;
|
||||
virtual HashType layerTypeHash ( int parIndex ) const = 0;
|
||||
virtual const PixelConv<D>& pixel_conv ( void ) const = 0;
|
||||
|
||||
protected:
|
||||
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize ) = 0;
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
#include <ciso646>
|
||||
|
||||
namespace dk {
|
||||
//MapType_IsometricStaggered,
|
||||
//MapType_Isometric,
|
||||
//MapType_Orthogonal,
|
||||
//MapType_Hex
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
class TileIterator;
|
||||
|
||||
template <uint32_t D>
|
||||
class PixelConv {
|
||||
public:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/helpers.hpp"
|
||||
#include "doorkeeper/components/tilecoords.hpp"
|
||||
#include "doorkeeper/components/pixelconv.hpp"
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
@ -15,6 +16,9 @@ namespace dk {
|
|||
template <typename T, uint32_t D, typename T1>
|
||||
class TileIterator;
|
||||
|
||||
template <uint32_t D>
|
||||
class PixelConv;
|
||||
|
||||
namespace implem {
|
||||
template <typename I, typename O>
|
||||
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<D>& parPixConv, const coords& parArea );
|
||||
TileIterator ( qualif_vector_type* parData, const PixelConv<D>& 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<D>& m_pixel_conv;
|
||||
};
|
||||
|
||||
template <uint32_t D>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/implem/vector.hpp"
|
||||
#include "doorkeeper/components/basemapsource.hpp"
|
||||
#include "doorkeeper/components/pixelconv.hpp"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
@ -34,6 +35,7 @@ namespace dkh {
|
|||
virtual const coords& tileSize ( void ) const;
|
||||
virtual void chainedMaps ( std::vector<std::string>& 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<MapTileType> m_wholedata;
|
||||
const coords m_mapSize;
|
||||
const coords m_tileSize;
|
||||
const dk::PixelConvSquare<2> m_pixel_conv;
|
||||
const dk::MapTypes m_mapType;
|
||||
};
|
||||
} //namespace dkh
|
||||
|
|
|
@ -37,14 +37,14 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
template <typename T, uint32_t D>
|
||||
typename Layer<T, D>::iterator Layer<T, D>::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 T, uint32_t D>
|
||||
typename Layer<T, D>::iterator Layer<T, D>::end() {
|
||||
return iterator(&m_tiles, make_past_end_coords<D>(this->m_count - 1), make_past_end_coords<D>(this->m_count - 1));
|
||||
return iterator(&m_tiles, m_tilemap->pixel_conv(), make_past_end_coords<D>(this->m_count - 1), make_past_end_coords<D>(this->m_count - 1));
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
namespace dk {
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parArea) :
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const PixelConv<D>& 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 <typename T, uint32_t D, typename T1>
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parStart, const coords& parArea) :
|
||||
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const PixelConv<D>& 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 <typename T, uint32_t D, typename T1>
|
||||
|
@ -59,6 +63,11 @@ namespace dk {
|
|||
return m_tile_range.position();
|
||||
}
|
||||
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
auto TileIterator<T, D, T1>::pixel_position() const -> coords {
|
||||
return m_pixel_conv.to_pixel(this->position());
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
inline Vector<D> make_past_end_coords (const Vector<D>& parTo) {
|
||||
Vector<D> retval(0);
|
||||
|
|
|
@ -20,14 +20,14 @@ namespace dk {
|
|||
template <typename T>
|
||||
typename Layer<T, D>::iterator Viewport<D>::begin (Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::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 <uint32_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::iterator Viewport<D>::end (Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
|
@ -46,14 +46,14 @@ namespace dk {
|
|||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::cbegin (const Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::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 <uint32_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::cend (const Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::const_iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
|
|
|
@ -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<int>();
|
||||
}
|
||||
|
||||
const dk::PixelConv<2>& AsciiMapSource::pixel_conv() const {
|
||||
return m_pixel_conv;
|
||||
}
|
||||
} //namespace dkh
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "doorkeeper/components/tileiterator.hpp"
|
||||
#include "doorkeeper/components/pixelconv.hpp"
|
||||
#include <vector>
|
||||
#include <boost/iterator/counting_iterator.hpp>
|
||||
#include <limits>
|
||||
|
@ -11,10 +12,11 @@ TEST(tileiterator, increment) {
|
|||
using boost::counting_iterator;
|
||||
|
||||
std::vector<int> data(counting_iterator<int>(0), counting_iterator<int>(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);
|
||||
|
|
Loading…
Reference in a new issue