diff --git a/CMakeLists.txt b/CMakeLists.txt index 9da3425..c0170b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,12 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -g -O0 -Wall -Wex set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -O3 -Wall -Wextra") #string(COMPARE EQUAL CMAKE_BINARY_DIR CMAKE_SOURCE_DIR IN_SOURCE_BUILD) +find_library(Boost 1.21.0 REQUIRED) + +include_directories(SYSTEM + ${Boost_INCLUDE_DIRECTORIES} +) + include_directories( src/ include/ @@ -13,4 +19,5 @@ include_directories( add_executable(${PROJECT_NAME} src/main.cpp src/doorkeeper.cpp + src/test/test_tiler.cpp ) diff --git a/include/components/tileiterator.hpp b/include/components/tileiterator.hpp new file mode 100644 index 0000000..1f0a35f --- /dev/null +++ b/include/components/tileiterator.hpp @@ -0,0 +1,40 @@ +#ifndef id873715F57B504CCF8227CE03EA28CAFA +#define id873715F57B504CCF8227CE03EA28CAFA + +#include +#include +#include "primitivetypes.hpp" + +namespace dk { + template + class TileIterator : public boost::iterator_facade, T, boost::biderectional_traversal_tag> { + friend class boost::iterator_core_access; + public: + typedef Vector coords; + + TileIterator ( void ); + TileIterator ( const TileIterator& parOther ) = default; + TileIterator ( const coords& parFrom, const coords& parTo ); + TileIterator ( const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parTotal ); + ~TileIterator ( void ) = default; + + private: + void increment ( void ); + void decrement ( void ); + void advance ( size_t parAdvance ); + ptrdiff_t distance_to ( const MeshSelectionIterator& parOther ); + bool equal ( const MeshSelectionIterator& parOther ) const; + T& dereference ( void ) const; + + coords m_pos; + coords m_from; + coords m_to; + coords m_areafrom; + coords m_areato; + coords m_total; + }; +} //namespace dk + +#include "implem/tileiterator.inl" + +#endif diff --git a/include/components/tilestreamer.hpp b/include/components/tilestreamer.hpp new file mode 100644 index 0000000..1d7ea02 --- /dev/null +++ b/include/components/tilestreamer.hpp @@ -0,0 +1,33 @@ +#ifndef id9B1C02049E474F6997D367932C4C2D21 +#define id9B1C02049E474F6997D367932C4C2D21 + +#include "primitivetypes.hpp" +#include +#include +#include +#include + +namespace dk { + template + class TileStreamer { + public: + typedef Vector coords; + typedef std::unique_ptr StreamPtr; + + explicit TileStreamer ( StreamPtr&& parStream ); + TileStreamer ( const TileStreamer& ) = delete; + TileStreamer ( TileStreamer&& ) = default; + ~TileStreamer ( void ) noexcept = default; + + TileStreamer& operator= ( const TileStreamer& ) = delete; + + void copy ( std::vector& parDest, const coords& parFrom, const coords& parTo ); + + private: + StreamPtr m_stream; + }; +} //namespace dk + +#include "implem/tilestreamer.inl" + +#endif diff --git a/include/components/tyler.hpp b/include/components/tyler.hpp index fb683df..3856d8e 100644 --- a/include/components/tyler.hpp +++ b/include/components/tyler.hpp @@ -1,25 +1,38 @@ #ifndef id6FB3FC97331449038D42AAAB4C01ABA1 #define id6FB3FC97331449038D42AAAB4C01ABA1 -#include "implem/coords.hpp" +#include "primitivetypes.hpp" +#include "components/tilestreamer.hpp" #include +#include +#include namespace dk { + template class Viewport; - template + template > class Tyler { public: - Tyler ( const coords& parCoords ); + typedef S streamer_type; + typedef Vector coords; + + Tyler ( void ) = delete; + Tyler ( const coords& parSize, streamer_type&& ); virtual ~Tyler ( void ) noexcept = default; - virtual bool batch_load ( const coords& parFrom, const coords& parTo ); - virtual bool single_load ( const coords& parCoords ); + virtual bool batch_load ( const std::vector& parLoad ) = 0; + virtual bool single_load ( const T& parLoad ) = 0; + + size_t tiles_count ( void ) const { return m_tiles.size(); } private: const coords m_size; std::vector m_tiles; + streamer_type m_streamer; }; } //namespace dk +#include "implem/tyler.inl" + #endif diff --git a/include/components/viewport.hpp b/include/components/viewport.hpp index 2cdf86b..793fb4c 100644 --- a/include/components/viewport.hpp +++ b/include/components/viewport.hpp @@ -1,11 +1,14 @@ #ifndef id0ADBCC15BA574485BF3267254090D99B #define id0ADBCC15BA574485BF3267254090D99B -#include "implem/coords.hpp" +#include "primitivetypes.hpp" namespace dk { + template class Viewport { public: + typedef Vector coords; + explicit Viewport ( const coords& parSize ); Viewport ( const coords& parSize, const coords& parPos ); ~Viewport ( void ) noexcept = default; diff --git a/include/doorkeeper.hpp b/include/doorkeeper.hpp index 6d6d13b..96a24bb 100644 --- a/include/doorkeeper.hpp +++ b/include/doorkeeper.hpp @@ -1,6 +1,7 @@ #ifndef id5A4C05FA7D264B65B7B7D14A0792E3A2 #define id5A4C05FA7D264B65B7B7D14A0792E3A2 +#include "primitivetypes.hpp" #include "components/tyler.hpp" #include "components/viewport.hpp" diff --git a/include/implem/configuration.h b/include/implem/configuration.h new file mode 100644 index 0000000..5768e6d --- /dev/null +++ b/include/implem/configuration.h @@ -0,0 +1,24 @@ +#ifndef id2E81C803F1B94170B2C61A63D5020E08 +#define id2E81C803F1B94170B2C61A63D5020E08 + +#if !defined(DK_COORD_SCALAR_TYPE) +# define DK_COORD_SCALAR_TYPE int +#endif + +#if defined(__cplusplus) +# define MAKE_DK_NAME(a) a +namespace dk { +#else +# define MAKE_DK_NAME(a) dk_ ## a +#endif + +typedef DK_COORD_SCALAR_TYPE MAKE_DK_NAME(CoordinateScalarType); + +#if defined(__cplusplus) +} //namespace dk +#endif + +#undef DK_COORD_SCALAR_TYPE +#undef MAKE_DK_NAME + +#endif diff --git a/include/implem/coords.hpp b/include/implem/coords.hpp deleted file mode 100644 index 7cc057d..0000000 --- a/include/implem/coords.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef id305A77366E3B4D3C84CC345C93A7C38B -#define id305A77366E3B4D3C84CC345C93A7C38B - -#include "implem/vector.hpp" - -namespace dk { - typedef int coord_type; - typedef cloonel::Vector coords; - typedef cloonel::Vector int2; -} //namespace dk - -#endif diff --git a/include/implem/tileiterator.inl b/include/implem/tileiterator.inl new file mode 100644 index 0000000..5c70b19 --- /dev/null +++ b/include/implem/tileiterator.inl @@ -0,0 +1,46 @@ +namespace dk { + template + TileIterator::TileIterator() : + m_pos(CoordinateScalarType()), + m_from(CoordinateScalarType()), + m_to(CoordinateScalarType()), + m_areafrom(CoordinateScalarType()), + m_areato(CoordinateScalarType()), + m_total(CoordinateScalarType()) + { + } + + template + TileIterator::TileIterator (const coords& parFrom, const coords& parTo) : + m_pos(parFrom), + m_from(parFrom), + m_to(parTo), + m_areafrom(parFrom), + m_areato(parTo), + m_total(parTo - parFrom) + { + } + + template + TileIterator::TileIterator (const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parTotal) : + m_pos(parFrom), + m_from(parFrom), + m_to(parTo), + m_areafrom(parAreaFrom), + m_areato(parAreaTo), + m_total(parTotal) + { + } + + template + void TileIterator::increment() { + for (size_t d = 0; d < D - 1; ++d) { + ++m_pos[d]; + if (m_pos[d] >= m_areato[d]) + m_pos[d] = m_areafrom[d]; + else + return; + } + ++m_pos[D - 1]; + } +} //namespace dk diff --git a/include/implem/tilestreamer.inl b/include/implem/tilestreamer.inl new file mode 100644 index 0000000..c68e80b --- /dev/null +++ b/include/implem/tilestreamer.inl @@ -0,0 +1,7 @@ +namespace dk { + template + TileStreamer::TileStreamer (StreamPtr&& parStream) : + m_stream(std::move(parStream)) + { + } +} //namespace dk diff --git a/include/implem/tyler.inl b/include/implem/tyler.inl new file mode 100644 index 0000000..ccc622d --- /dev/null +++ b/include/implem/tyler.inl @@ -0,0 +1,12 @@ +namespace dk { + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + template + Tyler::Tyler (const coords& parSize, streamer_type&& parStream) : + m_size(parSize), + m_tiles(parSize.x() * parSize.y()), + m_streamer(std::move(parStream)) + { + assert(m_size.x() > 0 and m_size.y() > 0); + } +} //namespace dk diff --git a/include/primitivetypes.hpp b/include/primitivetypes.hpp new file mode 100644 index 0000000..42121d0 --- /dev/null +++ b/include/primitivetypes.hpp @@ -0,0 +1,11 @@ +#ifndef id583F11FE0934446E9135B4ADCFA1E4F9 +#define id583F11FE0934446E9135B4ADCFA1E4F9 + +#include "implem/configuration.h" +#include "implem/vector.hpp" + +namespace dk { + using cloonel::Vector; +} //namespace dk + +#endif diff --git a/src/main.cpp b/src/main.cpp index c660073..1ea6ce1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,9 @@ #include -#include "doorkeeper.hpp" +#include "test/test_tiler.hpp" int main() { + TestTiler simpleMap(TestTiler::coords(200, 150), "test.map"); + + std::cout << "Total tiles: " << simpleMap.tiles_count() << "\n"; return 0; } diff --git a/src/test/test_tiler.cpp b/src/test/test_tiler.cpp new file mode 100644 index 0000000..2208c23 --- /dev/null +++ b/src/test/test_tiler.cpp @@ -0,0 +1,26 @@ +#include +#include +#include "test/test_tiler.hpp" + +typedef dk::TileStreamer TileStreamerType; + +///---------------------------------------------------------------------------- +///---------------------------------------------------------------------------- +TestTiler::TestTiler (const coords& parSize, const std::string&& parPath) : + parent_type(parSize, TileStreamerType(TileStreamerType::StreamPtr(new std::ifstream(parPath)))) +{ +} + +///---------------------------------------------------------------------------- +///---------------------------------------------------------------------------- +bool TestTiler::batch_load (const std::vector& parLoad) { + std::cout << "Would batch-load " << parLoad.size() << " elements\n"; + return true; +} + +///---------------------------------------------------------------------------- +///---------------------------------------------------------------------------- +bool TestTiler::single_load (const int&) { + std::cout << "Would load 1 element\n"; + return true; +} diff --git a/src/test/test_tiler.hpp b/src/test/test_tiler.hpp new file mode 100644 index 0000000..6030dd4 --- /dev/null +++ b/src/test/test_tiler.hpp @@ -0,0 +1,19 @@ +#ifndef idDD0A66B75FF546FCAF01C65E980DF224 +#define idDD0A66B75FF546FCAF01C65E980DF224 + +#include "doorkeeper.hpp" + +class TestTiler : public dk::Tyler { + typedef dk::Tyler parent_type; +public: + typedef parent_type::coords coords; + + TestTiler ( const coords& parSize, const std::string&& parPath ); + + virtual ~TestTiler ( void ) noexcept = default; + + virtual bool batch_load ( const std::vector& parLoad ); + virtual bool single_load ( const int& parLoad ); +}; + +#endif