diff --git a/include/components/tilestream.hpp b/include/components/tilestream.hpp deleted file mode 100644 index 41d1ed8..0000000 --- a/include/components/tilestream.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef id9B1C02049E474F6997D367932C4C2D21 -#define id9B1C02049E474F6997D367932C4C2D21 - -#include "primitivetypes.hpp" -#include -#include -#include -#include -#include - -//This code might need to be removed, but for now it's handy to read a simple -//ascii file into a vector without worrying too much about details. -//TODO: remove along with the code in the constructor -#include "implem/asciimap_parser.hpp" -#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 ); - const coords& tilesCount ( void ) const { return m_count; } - - private: - StreamPtr m_stream; - coords m_count; - std::vector m_wholedata; - }; -} //namespace dk - -#include "implem/tilestreamer.inl" - -#endif diff --git a/include/helpers/asciimapsource.hpp b/include/helpers/asciimapsource.hpp index 22f00c8..c168909 100644 --- a/include/helpers/asciimapsource.hpp +++ b/include/helpers/asciimapsource.hpp @@ -1,13 +1,18 @@ #ifndef id263B7DAF9A1C40BB8517D5D328DF8A1B #define id263B7DAF9A1C40BB8517D5D328DF8A1B +#include "primitivetypes.hpp" +#include "implem/vector.hpp" #include #include +#include // source_tag namespace dkh { - class AsciiMapSource : std::streambuf { + class AsciiMapSource : public std::streambuf { public: + typedef dk::Vector coords; typedef int MapTileType; + typedef boost::iostreams::source_tag category; enum { MapDimensions = 2 }; @@ -22,13 +27,14 @@ namespace dkh { AsciiMapSource ( I parDataFrom, I parDataTo ); ~AsciiMapSource ( void ) noexcept = default; + const coords& mapSize ( void ) const noexcept { return m_mapSize; } + private: void parse_map_data ( std::istream& parSrc ); std::vector m_wholedata; - int m_width; - int m_height; + coords m_mapSize; }; -} //namespace dk +} //namespace dkh #endif diff --git a/include/implem/tilestream.inl b/include/implem/tilestream.inl deleted file mode 100644 index f886908..0000000 --- a/include/implem/tilestream.inl +++ /dev/null @@ -1,40 +0,0 @@ -namespace dk { - template - TileStreamer::TileStreamer (StreamPtr&& parStream) : - m_stream(std::move(parStream)) - { - //TODO: this loader /only/ works with 2D tilesets, remove it asap - - typedef std::istream_iterator DataIterator; - typedef boost::spirit::multi_pass WrappedIterator; - - *m_stream >> std::noskipws; - - auto first = WrappedIterator(DataIterator(*m_stream)); - auto last = WrappedIterator(DataIterator()); - implem::AsciiMapGrammar grammar(first); - const bool p = boost::spirit::qi::parse( - first, - last, - grammar, - m_wholedata - ); - - if (not p or last != first) { - throw std::runtime_error("Invalid data: can't parse file"); - } - - //Only look at the front. Besides a bug in spirit makes the other counts - //invalid, see - //http://boost.2283326.n4.nabble.com/Possible-bug-in-line-pos-iterator-td4636592.html - m_count.x() = grammar.lengths.front(); - m_count.y() = m_wholedata.size() / m_count.x(); - } - - template - void TileStreamer::copy (std::vector& parDest, const coords& /*parFrom*/, const coords& /*parTo*/) { - parDest.clear(); - parDest.reserve(m_wholedata.size()); - std::copy(m_wholedata.begin(), m_wholedata.end(), std::back_inserter(parDest)); - } -} //namespace dk diff --git a/src/asciimapsource.cpp b/src/asciimapsource.cpp index b1be8be..7766383 100644 --- a/src/asciimapsource.cpp +++ b/src/asciimapsource.cpp @@ -60,7 +60,7 @@ namespace dkh { //Only look at the front. Besides a bug in spirit makes the other counts //invalid, see //http://boost.2283326.n4.nabble.com/Possible-bug-in-line-pos-iterator-td4636592.html - m_width = grammar.lengths.front(); - m_height = m_wholedata.size() / m_width; + m_mapSize.x() = grammar.lengths.front(); + m_mapSize.y() = m_wholedata.size() / m_mapSize.x(); } -} //namespace dk +} //namespace dkh