Advancing with the implementation.
The iterator is not included anywhere yet so it's completely untested. Next step is to define the relationship between views and layers, so iterators can be put into the class that will be responsible to spawn them.
This commit is contained in:
parent
cce2da8bd7
commit
9086de8dae
8 changed files with 95 additions and 16 deletions
|
@ -12,11 +12,13 @@ namespace dk {
|
||||||
public:
|
public:
|
||||||
typedef Vector<CoordinateScalarType, D> coords;
|
typedef Vector<CoordinateScalarType, D> coords;
|
||||||
|
|
||||||
explicit LayerBase ( const coords& parSize );
|
LayerBase ( const coords& parSize, const coords& parTileSize, const coords& parMasterTileSize );
|
||||||
virtual ~LayerBase ( void ) noexcept = default;
|
virtual ~LayerBase ( void ) noexcept = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
coords m_size;
|
coords m_size;
|
||||||
|
coords m_tilesize;
|
||||||
|
coords m_mastersize;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, size_t D>
|
template <typename T, size_t D>
|
||||||
|
@ -27,7 +29,7 @@ namespace dk {
|
||||||
|
|
||||||
Layer ( const Layer& ) = delete;
|
Layer ( const Layer& ) = delete;
|
||||||
Layer ( Layer&& ) = default;
|
Layer ( Layer&& ) = default;
|
||||||
Layer ( const coords& parSize, streamer_type&& parStreamer );
|
Layer ( const coords& parSize, const coords& parTileSize, const coords& parMasterTileSize, streamer_type&& parStreamer );
|
||||||
virtual ~Layer ( void ) noexcept = default;
|
virtual ~Layer ( void ) noexcept = default;
|
||||||
|
|
||||||
Layer& operator= ( const Layer& ) = delete;
|
Layer& operator= ( const Layer& ) = delete;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#ifndef id873715F57B504CCF8227CE03EA28CAFA
|
#ifndef id873715F57B504CCF8227CE03EA28CAFA
|
||||||
#define id873715F57B504CCF8227CE03EA28CAFA
|
#define id873715F57B504CCF8227CE03EA28CAFA
|
||||||
|
|
||||||
|
#include "primitivetypes.hpp"
|
||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include "primitivetypes.hpp"
|
#include <vector>
|
||||||
|
|
||||||
namespace dk {
|
namespace dk {
|
||||||
template <typename T, size_t D>
|
template <typename T, size_t D>
|
||||||
|
@ -24,7 +25,8 @@ namespace dk {
|
||||||
void advance ( size_t parAdvance );
|
void advance ( size_t parAdvance );
|
||||||
ptrdiff_t distance_to ( const MeshSelectionIterator& parOther );
|
ptrdiff_t distance_to ( const MeshSelectionIterator& parOther );
|
||||||
bool equal ( const MeshSelectionIterator& parOther ) const;
|
bool equal ( const MeshSelectionIterator& parOther ) const;
|
||||||
T& dereference ( void ) const;
|
T& dereference ( void ) const { return m_data[get_current_index()]; }
|
||||||
|
size_t get_current_index ( void ) const;
|
||||||
|
|
||||||
coords m_pos;
|
coords m_pos;
|
||||||
coords m_from;
|
coords m_from;
|
||||||
|
@ -32,6 +34,7 @@ namespace dk {
|
||||||
coords m_areafrom;
|
coords m_areafrom;
|
||||||
coords m_areato;
|
coords m_areato;
|
||||||
coords m_total;
|
coords m_total;
|
||||||
|
std::vector<T>* m_data;
|
||||||
};
|
};
|
||||||
} //namespace dk
|
} //namespace dk
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,19 @@ namespace dk {
|
||||||
typedef typename LayerBase<D>::coords coords;
|
typedef typename LayerBase<D>::coords coords;
|
||||||
|
|
||||||
Tyler ( void ) = delete;
|
Tyler ( void ) = delete;
|
||||||
explicit Tyler ( const coords& parSize );
|
Tyler ( const coords& parSize, const coords& parTileSize );
|
||||||
~Tyler ( void ) noexcept = default;
|
~Tyler ( void ) noexcept = default;
|
||||||
|
|
||||||
typename coords::value_type tiles_count ( void ) const;
|
typename coords::value_type tiles_count ( void ) const;
|
||||||
const coords& map_size ( void ) const { return m_size; }
|
const coords& map_size ( void ) const { return m_size; }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t push_layer ( typename Layer<T, D>::streamer_type&& parStreamer );
|
size_t push_layer ( typename Layer<T, D>::streamer_type&& parStreamer );
|
||||||
|
template <typename T>
|
||||||
|
size_t push_layer ( typename Layer<T, D>::streamer_type&& parStreamer, const coords& parSubdiv );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const coords m_size;
|
const coords m_size;
|
||||||
|
const coords m_tilesize;
|
||||||
LayerList m_layers;
|
LayerList m_layers;
|
||||||
};
|
};
|
||||||
} //namespace dk
|
} //namespace dk
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#define id2E81C803F1B94170B2C61A63D5020E08
|
#define id2E81C803F1B94170B2C61A63D5020E08
|
||||||
|
|
||||||
#if !defined(DK_COORD_SCALAR_TYPE)
|
#if !defined(DK_COORD_SCALAR_TYPE)
|
||||||
|
/* this type represent tiles' coordinates, so it should be an integer type */
|
||||||
|
/* so it's not the tile position in your game world */
|
||||||
# define DK_COORD_SCALAR_TYPE int
|
# define DK_COORD_SCALAR_TYPE int
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -21,4 +23,15 @@ typedef DK_COORD_SCALAR_TYPE MAKE_DK_NAME(CoordinateScalarType);
|
||||||
#undef DK_COORD_SCALAR_TYPE
|
#undef DK_COORD_SCALAR_TYPE
|
||||||
#undef MAKE_DK_NAME
|
#undef MAKE_DK_NAME
|
||||||
|
|
||||||
|
#if !defined(NDEBUG) && !defined(NO_DK_ASSERTIONS)
|
||||||
|
# if !defined(DK_ASSERT)
|
||||||
|
# include <cassert>
|
||||||
|
# define DK_ASSERT(a) assert(a)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# if !defined(DK_ASSERT)
|
||||||
|
# define DK_ASSERT(a)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,16 +2,19 @@ namespace dk {
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
template <size_t D>
|
template <size_t D>
|
||||||
LayerBase<D>::LayerBase (const coords& parSize) :
|
LayerBase<D>::LayerBase (const coords& parSize, const coords& parTileSize, const coords& parMasterTileSize) :
|
||||||
m_size(parSize)
|
m_size(parSize),
|
||||||
|
m_tilesize(parTileSize),
|
||||||
|
m_mastersize(parMasterTileSize)
|
||||||
{
|
{
|
||||||
|
DK_ASSERT((parMasterTileSize / parTileSize) * parTileSize == parMasterTileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
template <typename T, size_t D>
|
template <typename T, size_t D>
|
||||||
Layer<T, D>::Layer (const coords& parSize, streamer_type&& parStreamer) :
|
Layer<T, D>::Layer (const coords& parSize, const coords& parTileSize, const coords& parMasterTileSize, streamer_type&& parStreamer) :
|
||||||
LayerBase<D>(parSize),
|
LayerBase<D>(parSize, parTileSize, parMasterTileSize),
|
||||||
m_streamer(std::move(parStreamer))
|
m_streamer(std::move(parStreamer))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,4 +43,48 @@ namespace dk {
|
||||||
}
|
}
|
||||||
++m_pos[D - 1];
|
++m_pos[D - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t D>
|
||||||
|
void TileIterator<T, D>::decrement() {
|
||||||
|
for (size_t d = 0; d < D; ++d) {
|
||||||
|
if (m_pos[d] > m_areafrom[d]) {
|
||||||
|
--m_pos[d];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_pos[d] = m_areato[d];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++m_pos[D - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t D>
|
||||||
|
size_t TileIterator<T, D>::get_current_index() const {
|
||||||
|
size_t index = 0;
|
||||||
|
for (size_t d = 0; d < D; ++d) {
|
||||||
|
size_t pos = static_cast<size_t>(m_pos[D - 1 - d]);
|
||||||
|
for (size_t p = 0; p < D - 1 - d; ++p) {
|
||||||
|
pos *= static_cast<size_t>(m_total[p]);
|
||||||
|
}
|
||||||
|
|
||||||
|
index += pos;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t D>
|
||||||
|
void TileIterator<T, D>::advance (size_t parAdvance) {
|
||||||
|
//TODO: implement
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t D>
|
||||||
|
ptrdiff_t TileIterator<T, D>::distance_to (const MeshSelectionIterator& parOther) {
|
||||||
|
//TODO: implement
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t D>
|
||||||
|
bool TileIterator<T, D>::equal (const MeshSelectionIterator& parOther) const {
|
||||||
|
//TODO: implement
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} //namespace dk
|
} //namespace dk
|
||||||
|
|
|
@ -2,8 +2,9 @@ namespace dk {
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
template <size_t D>
|
template <size_t D>
|
||||||
Tyler<D>::Tyler (const coords& parSize) :
|
Tyler<D>::Tyler (const coords& parSize, const coords& parTileSize) :
|
||||||
m_size(parSize)
|
m_size(parSize),
|
||||||
|
m_tilesize(parTileSize)
|
||||||
{
|
{
|
||||||
assert(m_size.x() > 0 and m_size.y() > 0);
|
assert(m_size.x() > 0 and m_size.y() > 0);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,17 @@ namespace dk {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t Tyler<D>::push_layer (typename Layer<T, D>::streamer_type&& parStreamer) {
|
size_t Tyler<D>::push_layer (typename Layer<T, D>::streamer_type&& parStreamer) {
|
||||||
const size_t retval = m_layers.size();
|
const size_t retval = m_layers.size();
|
||||||
m_layers.push_back(LayerPtr(new Layer<T, D>(m_size, std::move(parStreamer))));
|
m_layers.push_back(LayerPtr(new Layer<T, D>(m_size, m_tilesize, coords(1), std::move(parStreamer))));
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
///--------------------------------------------------------------------------
|
||||||
|
///--------------------------------------------------------------------------
|
||||||
|
template <size_t D>
|
||||||
|
template <typename T>
|
||||||
|
size_t Tyler<D>::push_layer (typename Layer<T, D>::streamer_type&& parStreamer, const coords& parSubdiv) {
|
||||||
|
const size_t retval = m_layers.size();
|
||||||
|
m_layers.push_back(LayerPtr(new Layer<T, D>(m_size * parSubdiv, m_tilesize / parSubdiv, m_tilesize, std::move(parStreamer))));
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
} //namespace dk
|
} //namespace dk
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
typedef dk::Tyler<2> Tiler;
|
typedef dk::Tyler<2> Tiler;
|
||||||
|
typedef std::unique_ptr<std::ifstream> ifstreamptr;
|
||||||
|
|
||||||
Tiler tiler(Tiler::coords(200, 150));
|
Tiler tiler(Tiler::coords(200, 150), Tiler::coords(64));
|
||||||
|
|
||||||
tiler.push_layer<int>(
|
tiler.push_layer<int>(dk::Layer<int, 2>::streamer_type(ifstreamptr(new std::ifstream("test.map"))));
|
||||||
dk::Layer<int, 2>::streamer_type(std::unique_ptr<std::ifstream>(new std::ifstream("test.map")))
|
tiler.push_layer<char>(dk::Layer<char, 2>::streamer_type(ifstreamptr(new std::ifstream("test_2.map"))));
|
||||||
);
|
|
||||||
|
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
std::cout << "Map size: " << tiler.map_size() << '\n';
|
std::cout << "Map size: " << tiler.map_size() << '\n';
|
||||||
|
|
Loading…
Reference in a new issue