BaseMapSource doesn't need to know T. Only fetch() will need that.
This commit is contained in:
parent
49f7d15379
commit
ab6ef6c338
14 changed files with 42 additions and 40 deletions
|
@ -6,21 +6,27 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstddef>
|
||||
|
||||
namespace dk {
|
||||
template <typename T, uint32_t D>
|
||||
template <uint32_t D>
|
||||
class BaseMapSource {
|
||||
public:
|
||||
typedef dk::Vector<D> coords;
|
||||
BaseMapSource ( void ) = default;
|
||||
virtual ~BaseMapSource ( void ) noexcept = default;
|
||||
|
||||
virtual void fetch ( std::vector<T>& parOut, const coords& parFrom, const coords& parTo ) = 0;
|
||||
template <typename T>
|
||||
void fetch ( std::vector<T>& parOut, const coords& parFrom, const coords& parTo );
|
||||
|
||||
virtual const coords& mapSize ( void ) const = 0;
|
||||
virtual const coords& tileSize ( void ) const = 0;
|
||||
virtual MapTypes mapType ( void ) const = 0;
|
||||
virtual int layersCount ( void ) const = 0;
|
||||
virtual void chainedMaps ( std::vector<std::string>& parOut ) const = 0;
|
||||
|
||||
protected:
|
||||
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize ) = 0;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace dk {
|
|||
|
||||
Layer ( const Layer& ) = delete;
|
||||
Layer ( Layer&& ) = default;
|
||||
Layer ( const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource<T, D>* parTilemap );
|
||||
Layer ( const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource<D>* parTilemap );
|
||||
virtual ~Layer ( void ) noexcept = default;
|
||||
|
||||
Layer& operator= ( const Layer& ) = delete;
|
||||
|
@ -64,7 +64,7 @@ namespace dk {
|
|||
virtual void onPreload ( const coords& parFrom, const coords& parTo );
|
||||
|
||||
std::vector<T> m_tiles;
|
||||
BaseMapSource<T, D>* m_tilemap;
|
||||
BaseMapSource<D>* m_tilemap;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <cstdint>
|
||||
|
||||
namespace dk {
|
||||
template <typename T, uint32_t D>
|
||||
template <uint32_t D>
|
||||
class BaseMapSource;
|
||||
|
||||
template <uint32_t D>
|
||||
|
@ -29,9 +29,9 @@ namespace dk {
|
|||
const coords& map_size ( void ) const { return m_size; }
|
||||
|
||||
template <typename T>
|
||||
Layer<T, D>& push_layer ( BaseMapSource<T, D>* parTilemap );
|
||||
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap );
|
||||
template <typename T>
|
||||
Layer<T, D>& push_layer ( BaseMapSource<T, D>* parTilemap, const coords& parSubdiv );
|
||||
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap, const coords& parSubdiv );
|
||||
|
||||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace dk {
|
|||
typedef Tyler<2> Tyler2d;
|
||||
template <typename T> using Layer2d = Layer<T, 2>;
|
||||
typedef Viewport<2> Viewport2d;
|
||||
template <typename T> using BaseMapSource2d = BaseMapSource<T, 2>;
|
||||
typedef BaseMapSource<2> BaseMapSource2d;
|
||||
} //namespace dk
|
||||
|
||||
namespace dkh {
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace dkh {
|
|||
typedef int AsciiMapTileType;
|
||||
} //namespace implem
|
||||
|
||||
class AsciiMapSource : public dk::BaseMapSource<implem::AsciiMapTileType, 2> {
|
||||
class AsciiMapSource : public dk::BaseMapSource<2> {
|
||||
public:
|
||||
typedef dk::Vector<2> coords;
|
||||
typedef implem::AsciiMapTileType MapTileType;
|
||||
|
@ -29,18 +29,14 @@ namespace dkh {
|
|||
virtual ~AsciiMapSource ( void ) noexcept = default;
|
||||
|
||||
virtual const coords& mapSize ( void ) const;
|
||||
virtual void fetch ( std::vector<MapTileType>& parOut, const coords& parFrom, const coords& parTo );
|
||||
virtual dk::MapTypes mapType ( void ) const;
|
||||
virtual int layersCount ( void ) const;
|
||||
virtual const coords& tileSize ( void ) const;
|
||||
virtual void chainedMaps ( std::vector<std::string>& parOut ) const;
|
||||
|
||||
private:
|
||||
enum {
|
||||
DataSize = sizeof(MapTileType)
|
||||
};
|
||||
|
||||
void parse_map_data ( std::istream& parSrc );
|
||||
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize );
|
||||
|
||||
std::vector<MapTileType> m_wholedata;
|
||||
const coords m_mapSize;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace dkh {
|
||||
template <typename T, uint32_t D, typename C>
|
||||
struct MapLoaderPool {
|
||||
typedef std::unique_ptr<dk::BaseMapSource<T, D>> BaseMapSourceUPtr;
|
||||
typedef std::unique_ptr<dk::BaseMapSource<D>> BaseMapSourceUPtr;
|
||||
typedef std::map<std::string, BaseMapSourceUPtr> PoolMapType;
|
||||
|
||||
enum { dimensions = D };
|
||||
|
@ -24,7 +24,7 @@ namespace dkh {
|
|||
PoolMapType pool;
|
||||
C opener;
|
||||
|
||||
dk::BaseMapSource<T, D>* operator() ( const std::string& parName );
|
||||
dk::BaseMapSource<D>* operator() ( const std::string& parName );
|
||||
};
|
||||
|
||||
template <typename M>
|
||||
|
|
|
@ -17,11 +17,10 @@
|
|||
#endif
|
||||
|
||||
namespace dkh {
|
||||
template <typename T, uint32_t D>
|
||||
class TylerMapSource : public dk::BaseMapSource<T, D> {
|
||||
template <uint32_t D>
|
||||
class TylerMapSource : public dk::BaseMapSource<D> {
|
||||
public:
|
||||
typedef dk::Vector<D> coords;
|
||||
typedef T MapTileType;
|
||||
enum {
|
||||
MapDimensions = D
|
||||
};
|
||||
|
@ -36,13 +35,13 @@ namespace dkh {
|
|||
|
||||
virtual const coords& mapSize ( void ) const;
|
||||
virtual const coords& tileSize ( void ) const;
|
||||
virtual void fetch ( std::vector<MapTileType>& parOut, const coords& parFrom, const coords& parTo );
|
||||
virtual dk::MapTypes mapType ( void ) const;
|
||||
virtual int layersCount ( void ) const;
|
||||
virtual void chainedMaps ( std::vector<std::string>& parOut ) const;
|
||||
|
||||
private:
|
||||
void parse_map_data ( std::istream& parSrc );
|
||||
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize );
|
||||
|
||||
std::unique_ptr<std::istream> m_stream;
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, uint32_t D>
|
||||
Layer<T, D>::Layer (const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource<T, D>* parTilemap) :
|
||||
Layer<T, D>::Layer (const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource<D>* parTilemap) :
|
||||
LayerBase<D>(parTilemap->mapSize(), parTileSize, parMasterTileSize),
|
||||
m_tilemap(parTilemap)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
namespace dkh {
|
||||
template <typename T, uint32_t D, typename C>
|
||||
dk::Tyler<D> map_load (C& parFileOpener, const std::string& parOpen) {
|
||||
dk::BaseMapSource<T, D>* reader = parFileOpener(parOpen);
|
||||
dk::BaseMapSource<D>* reader = parFileOpener(parOpen);
|
||||
dk::Tyler<D> tyler(reader->tileSize());
|
||||
tyler.push_layer(reader);
|
||||
tyler.template push_layer<T>(reader);
|
||||
std::vector<std::string> submaps;
|
||||
reader->chainedMaps(submaps);
|
||||
for (const auto& name : submaps) {
|
||||
|
@ -19,7 +19,7 @@ namespace dkh {
|
|||
name_stack.push(parOpen);
|
||||
|
||||
do {
|
||||
dk::BaseMapSource<T, D>* reader = parFileOpener(name_stack.top());
|
||||
dk::BaseMapSource<D>* reader = parFileOpener(name_stack.top());
|
||||
name_stack.pop();
|
||||
|
||||
submaps.clear();
|
||||
|
@ -28,13 +28,13 @@ namespace dkh {
|
|||
name_stack.emplace(std::move(curr_name));
|
||||
}
|
||||
|
||||
parTyler.push_layer(reader);
|
||||
parTyler.template push_layer<T>(reader);
|
||||
} while (not name_stack.empty());
|
||||
return parTyler;
|
||||
}
|
||||
|
||||
template <typename T, uint32_t D, typename C>
|
||||
dk::BaseMapSource<T, D>* MapLoaderPool<T, D, C>::operator() (const std::string& parName) {
|
||||
dk::BaseMapSource<D>* MapLoaderPool<T, D, C>::operator() (const std::string& parName) {
|
||||
auto it_found = pool.find(parName);
|
||||
if (pool.end() != it_found) {
|
||||
return it_found->second.get();
|
||||
|
|
|
@ -23,15 +23,15 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
template <typename T>
|
||||
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<T, D>* parTilemap) {
|
||||
return push_layer(parTilemap, coords(static_cast<CoordinateScalarType>(1)));
|
||||
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<D>* parTilemap) {
|
||||
return push_layer<T>(parTilemap, coords(static_cast<CoordinateScalarType>(1)));
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
template <typename T>
|
||||
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<T, D>* parTilemap, const coords& parSubdiv) {
|
||||
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<D>* parTilemap, const coords& parSubdiv) {
|
||||
auto newLayer = new Layer<T, D>(m_tilesize / parSubdiv, m_tilesize, parTilemap);
|
||||
if (m_size == coords(0)) {
|
||||
m_size = newLayer->mapSize();
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
namespace dkh {
|
||||
template <typename T, uint32_t D>
|
||||
TylerMapSource<T, D>::TylerMapSource (const char* parFilename) :
|
||||
template <uint32_t D>
|
||||
TylerMapSource<D>::TylerMapSource (const char* parFilename) :
|
||||
m_stream(new std::ifstream(parFilename))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, uint32_t D>
|
||||
TylerMapSource<T, D>::TylerMapSource (const std::string& parFilename) :
|
||||
template <uint32_t D>
|
||||
TylerMapSource<D>::TylerMapSource (const std::string& parFilename) :
|
||||
m_stream(new std::ifstream(parFilename))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T, uint32_t D>
|
||||
TylerMapSource<T, D>::TylerMapSource (std::istream* parData) :
|
||||
template <uint32_t D>
|
||||
TylerMapSource<D>::TylerMapSource (std::istream* parData) :
|
||||
m_stream(parData)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue