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:
King_DuckZ 2014-12-11 23:58:52 +01:00
parent cce2da8bd7
commit 9086de8dae
8 changed files with 95 additions and 16 deletions

View File

@ -12,11 +12,13 @@ namespace dk {
public:
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;
protected:
coords m_size;
coords m_tilesize;
coords m_mastersize;
};
template <typename T, size_t D>
@ -27,7 +29,7 @@ namespace dk {
Layer ( const Layer& ) = delete;
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;
Layer& operator= ( const Layer& ) = delete;

View File

@ -1,9 +1,10 @@
#ifndef id873715F57B504CCF8227CE03EA28CAFA
#define id873715F57B504CCF8227CE03EA28CAFA
#include "primitivetypes.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <iterator>
#include "primitivetypes.hpp"
#include <vector>
namespace dk {
template <typename T, size_t D>
@ -24,7 +25,8 @@ namespace dk {
void advance ( size_t parAdvance );
ptrdiff_t distance_to ( const MeshSelectionIterator& parOther );
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_from;
@ -32,6 +34,7 @@ namespace dk {
coords m_areafrom;
coords m_areato;
coords m_total;
std::vector<T>* m_data;
};
} //namespace dk

View File

@ -19,16 +19,19 @@ namespace dk {
typedef typename LayerBase<D>::coords coords;
Tyler ( void ) = delete;
explicit Tyler ( const coords& parSize );
Tyler ( const coords& parSize, const coords& parTileSize );
~Tyler ( void ) noexcept = default;
typename coords::value_type tiles_count ( void ) const;
const coords& map_size ( void ) const { return m_size; }
template <typename T>
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:
const coords m_size;
const coords m_tilesize;
LayerList m_layers;
};
} //namespace dk

View File

@ -2,6 +2,8 @@
#define id2E81C803F1B94170B2C61A63D5020E08
#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
#endif
@ -21,4 +23,15 @@ typedef DK_COORD_SCALAR_TYPE MAKE_DK_NAME(CoordinateScalarType);
#undef DK_COORD_SCALAR_TYPE
#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

View File

@ -2,16 +2,19 @@ namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <size_t D>
LayerBase<D>::LayerBase (const coords& parSize) :
m_size(parSize)
LayerBase<D>::LayerBase (const coords& parSize, const coords& parTileSize, const coords& parMasterTileSize) :
m_size(parSize),
m_tilesize(parTileSize),
m_mastersize(parMasterTileSize)
{
DK_ASSERT((parMasterTileSize / parTileSize) * parTileSize == parMasterTileSize);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, size_t D>
Layer<T, D>::Layer (const coords& parSize, streamer_type&& parStreamer) :
LayerBase<D>(parSize),
Layer<T, D>::Layer (const coords& parSize, const coords& parTileSize, const coords& parMasterTileSize, streamer_type&& parStreamer) :
LayerBase<D>(parSize, parTileSize, parMasterTileSize),
m_streamer(std::move(parStreamer))
{
}

View File

@ -43,4 +43,48 @@ namespace dk {
}
++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

View File

@ -2,8 +2,9 @@ namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <size_t D>
Tyler<D>::Tyler (const coords& parSize) :
m_size(parSize)
Tyler<D>::Tyler (const coords& parSize, const coords& parTileSize) :
m_size(parSize),
m_tilesize(parTileSize)
{
assert(m_size.x() > 0 and m_size.y() > 0);
}
@ -25,7 +26,17 @@ namespace dk {
template <typename T>
size_t Tyler<D>::push_layer (typename Layer<T, D>::streamer_type&& parStreamer) {
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;
}
} //namespace dk

View File

@ -5,12 +5,12 @@
int main() {
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>(
dk::Layer<int, 2>::streamer_type(std::unique_ptr<std::ifstream>(new std::ifstream("test.map")))
);
tiler.push_layer<int>(dk::Layer<int, 2>::streamer_type(ifstreamptr(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)
std::cout << "Map size: " << tiler.map_size() << '\n';