diff --git a/game/main.cpp b/game/main.cpp
index b7e765d..0626a58 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -15,7 +15,7 @@
* along with DoorKeeper. If not, see .
*/
-#include "doorkeeper/doorkeeper2d.hpp"
+#include "doorkeeper/doorkeeper.hpp"
#include "doorkeeper/helpers/maploader.hpp"
#include "doorkeeper/helpers/asciimapsource.hpp"
#include "doorkeeper/helpers/typename_native.hpp"
@@ -23,17 +23,18 @@
#include
int main() {
- using dk::Tyler2d;
- using dk::coords2;
- using dk::Viewport2d;
- using dk::Layer2d;
- typedef dkh::MapLoaderPool2d> IntPoolType;
+ using PixelConvType = dk::PixelConvSquare<2>;
+ using Tyler2d = dk::Tyler;
+ using coords2 = Tyler2d::coords;
+ //using Viewport2d = dk::Viewport;
+ //using Layer2d = dk::Layer;
+ typedef dkh::MapLoaderPool*(const std::string&)>> IntPoolType;
std::cout << "Welcome to " GAME_NAME " v" << GAME_VER_MAJOR << '.' << GAME_VER_MINOR << '.' << GAME_VER_PATCH << '\n';
IntPoolType pool;
pool.opener = [](const std::string& parName) { std::cout << "Opening " << parName << std::endl; return new dkh::AsciiMapSource(parName, coords2(10, 8), dk::MapType_IsometricStaggered, coords2(64, 64)); };
- dkh::PushLayerMapType<2> pushers;
+ dkh::PushLayerMapType pushers;
pushers.insert(std::make_pair(dk::type_name_hash(), &Tyler2d::push_layer_void));
Tyler2d tiler(dkh::call_map_load(pool, std::string("test_level.dk"), pushers));
diff --git a/include/doorkeeper/components/layer.hpp b/include/doorkeeper/components/layer.hpp
index c271ac6..2f44669 100644
--- a/include/doorkeeper/components/layer.hpp
+++ b/include/doorkeeper/components/layer.hpp
@@ -31,7 +31,7 @@
#endif
namespace dk {
- template
+ template
class Viewport;
template
@@ -58,18 +58,22 @@ namespace dk {
coords m_haveTo;
};
- template
- class Layer : public LayerBase {
- friend class Viewport;
+ template
+ class Layer : public LayerBase {
+ friend class Viewport;
public:
- typedef typename LayerBase::coords coords;
- typedef TileIterator iterator;
- typedef TileIterator const_iterator;
+ enum {
+ dimensions = PixConv::dimensions
+ };
+
+ typedef typename LayerBase::coords coords;
+ typedef TileIterator iterator;
+ typedef TileIterator const_iterator;
Layer ( const Layer& ) = delete;
Layer ( Layer&& ) = default;
- Layer ( const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource* parTilemap );
+ Layer ( const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource* parTilemap );
virtual ~Layer ( void ) noexcept = default;
Layer& operator= ( const Layer& ) = delete;
@@ -81,7 +85,7 @@ namespace dk {
virtual void onPreload ( const coords& parFrom, const coords& parTo );
std::vector m_tiles;
- BaseMapSource* m_tilemap;
+ BaseMapSource* m_tilemap;
};
} //namespace dk
diff --git a/include/doorkeeper/components/pixelconv.hpp b/include/doorkeeper/components/pixelconv.hpp
index 53d3811..917293e 100644
--- a/include/doorkeeper/components/pixelconv.hpp
+++ b/include/doorkeeper/components/pixelconv.hpp
@@ -27,6 +27,10 @@ namespace dk {
template
class PixelConv {
public:
+ enum {
+ dimensions = D
+ };
+
typedef Vector coords;
PixelConv ( MapTypes parType, const coords& parTileSize );
@@ -55,20 +59,19 @@ namespace dk {
virtual coords pick_tile ( const coords& parPixelPoint ) const;
};
+ template
class PixelConvDiamond : public PixelConv<2> {
public:
using base_class = PixelConv<2>;
using base_class::coords;
PixelConvDiamond ( const coords& parTileSize, bool parStaggered, bool parFirstReentrant );
- PixelConvDiamond ( const coords& parTileSize, bool parStaggered, bool parFirstReentrant, const coords& parRatio );
virtual ~PixelConvDiamond ( void ) noexcept = default;
virtual coords to_pixel ( const coords& parFrom ) const;
virtual coords pick_tile ( const coords& parPixelPoint ) const;
protected:
- const coords m_ratio;
const CoordinateScalarType m_first_reentr;
const bool m_staggered;
};
diff --git a/include/doorkeeper/components/tyler.hpp b/include/doorkeeper/components/tyler.hpp
index 23b4fa1..a6070f4 100644
--- a/include/doorkeeper/components/tyler.hpp
+++ b/include/doorkeeper/components/tyler.hpp
@@ -29,12 +29,16 @@ namespace dk {
template
class BaseMapSource;
- template
+ template
class Tyler {
- typedef std::unique_ptr> LayerPtr;
+ typedef std::unique_ptr> LayerPtr;
typedef std::vector LayerList;
public:
- typedef typename LayerBase::coords coords;
+ enum {
+ dimensions = PixConv::dimensions
+ };
+
+ typedef typename LayerBase::coords coords;
Tyler ( void ) = delete;
Tyler ( Tyler&& ) = default;
@@ -45,11 +49,11 @@ namespace dk {
const coords& map_size ( void ) const { return m_size; }
template
- Layer& push_layer ( BaseMapSource* parTilemap, int parIndex );
+ Layer& push_layer ( BaseMapSource* parTilemap, int parIndex );
template
- Layer& push_layer ( BaseMapSource* parTilemap, const coords& parSubdiv, int parIndex );
+ Layer& push_layer ( BaseMapSource* parTilemap, const coords& parSubdiv, int parIndex );
template
- void push_layer_void ( BaseMapSource* parTilemap, int parIndex );
+ void push_layer_void ( BaseMapSource* parTilemap, int parIndex );
void preload ( const coords& parFrom, const coords& parTo );
diff --git a/include/doorkeeper/components/viewport.hpp b/include/doorkeeper/components/viewport.hpp
index 70e3760..702077a 100644
--- a/include/doorkeeper/components/viewport.hpp
+++ b/include/doorkeeper/components/viewport.hpp
@@ -24,20 +24,24 @@
#include
namespace dk {
- template
+ template
class Tyler;
- template
+ template
class Layer;
- template
+ template
class Viewport {
public:
- typedef Vector coords;
+ enum {
+ dimensions = PixConv::dimensions
+ };
+
+ typedef Vector coords;
Viewport ( const Viewport& parOther ) = default;
- explicit Viewport ( Tyler& parTyler );
- Viewport ( Tyler& parTyler, const coords& parSize, const coords& parPos );
+ explicit Viewport ( Tyler& parTyler );
+ Viewport ( Tyler& parTyler, const coords& parSize, const coords& parPos );
~Viewport ( void ) noexcept = default;
Viewport& operator= ( const Viewport& ) = default;
@@ -48,22 +52,22 @@ namespace dk {
const coords& count ( void ) const { return m_size; }
template
- typename Layer::iterator begin ( Layer& parLayer ) const;
+ typename Layer::iterator begin ( Layer& parLayer ) const;
template
- typename Layer::iterator end ( Layer& parLayer ) const;
+ typename Layer::iterator end ( Layer& parLayer ) const;
template inline
- typename Layer::const_iterator begin ( const Layer& parLayer ) const a_always_inline;
+ typename Layer::const_iterator begin ( const Layer& parLayer ) const a_always_inline;
template inline
- typename Layer::const_iterator end ( const Layer& parLayer ) const a_always_inline;
+ typename Layer::const_iterator end ( const Layer& parLayer ) const a_always_inline;
template
- typename Layer::const_iterator cbegin ( const Layer& parLayer ) const;
+ typename Layer::const_iterator cbegin ( const Layer& parLayer ) const;
template
- typename Layer::const_iterator cend ( const Layer& parLayer ) const;
+ typename Layer::const_iterator cend ( const Layer& parLayer ) const;
private:
coords m_size;
coords m_position;
- Tyler& m_tyler;
+ Tyler& m_tyler;
};
} //namespace dk
diff --git a/include/doorkeeper/doorkeeper.hpp b/include/doorkeeper/doorkeeper.hpp
index 057e8fb..2b9e737 100644
--- a/include/doorkeeper/doorkeeper.hpp
+++ b/include/doorkeeper/doorkeeper.hpp
@@ -22,5 +22,6 @@
#include "components/tyler.hpp"
#include "components/viewport.hpp"
#include "components/layer.hpp"
+#include "components/pixelconv.hpp"
#endif
diff --git a/include/doorkeeper/doorkeeper2d.hpp b/include/doorkeeper/doorkeeper2d.hpp
deleted file mode 100644
index 5b61a24..0000000
--- a/include/doorkeeper/doorkeeper2d.hpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright 2015, Michele Santullo
- * This file is part of DoorKeeper.
- *
- * DoorKeeper is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * DoorKeeper is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with DoorKeeper. If not, see .
- */
-
-#ifndef id6327FA76CFB44F65A459C69096EC65D5
-#define id6327FA76CFB44F65A459C69096EC65D5
-
-#include "doorkeeper.hpp"
-#include
-
-namespace dk {
- typedef Tyler<2>::coords coords2;
- typedef Tyler<2> Tyler2d;
- template using Layer2d = Layer;
- typedef Viewport<2> Viewport2d;
- typedef BaseMapSource<2> BaseMapSource2d;
-} //namespace dk
-
-namespace dkh {
- template
- struct MapLoaderPool;
-
- template
- using MapLoaderPool2d = MapLoaderPool<2, C>;
-} //namespace dkh
-
-#endif
diff --git a/include/doorkeeper/helpers/maploader.hpp b/include/doorkeeper/helpers/maploader.hpp
index f1c5b67..7c029f3 100644
--- a/include/doorkeeper/helpers/maploader.hpp
+++ b/include/doorkeeper/helpers/maploader.hpp
@@ -22,7 +22,6 @@
#include "doorkeeper/components/basemapsource.hpp"
#include "doorkeeper/helpers/typename.hpp"
#include "doorkeeper/components/exception.hpp"
-#include
#include
#include
#include
@@ -31,41 +30,42 @@
#include
namespace dkh {
- template
- using PushLayerMapType = std::map::*)(dk::BaseMapSource*,int)>;
+ template
+ using PushLayerMapType = std::map::*)(dk::BaseMapSource*,int)>;
- template
+ template
struct MapLoaderPool {
- typedef std::unique_ptr> BaseMapSourceUPtr;
+ enum { dimensions = PixConv::dimensions };
+ typedef std::unique_ptr> BaseMapSourceUPtr;
typedef std::map PoolMapType;
+ typedef PixConv PixelConvType;
- enum { dimensions = D };
typedef C opener_type;
PoolMapType pool;
C opener;
- dk::BaseMapSource* operator() ( const std::string& parName );
+ dk::BaseMapSource* operator() ( const std::string& parName );
};
class UnknownLayerTemplateException : public dk::DoorKeeperException {
};
template
- dk::Tyler call_map_load ( M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
+ dk::Tyler call_map_load ( M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
template
- dk::Tyler call_map_load ( dk::Tyler& parTyler, M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
+ dk::Tyler call_map_load ( dk::Tyler& parTyler, M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
- template
- dk::Tyler map_load ( C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
+ template
+ dk::Tyler map_load ( C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
- template
- dk::Tyler& map_load ( dk::Tyler& parTyler, C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
+ template
+ dk::Tyler& map_load ( dk::Tyler& parTyler, C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher );
namespace implem {
- template
- void call_push_layer ( dk::Tyler& parTyler, const PushLayerMapType& parPusher, dk::BaseMapSource* parReader, int parIndex );
+ template
+ void call_push_layer ( dk::Tyler& parTyler, const PushLayerMapType& parPusher, dk::BaseMapSource* parReader, int parIndex );
} //namespace implem
} //namespace dkh
diff --git a/include/doorkeeper/implem/layer.inl b/include/doorkeeper/implem/layer.inl
index a590382..98093f2 100644
--- a/include/doorkeeper/implem/layer.inl
+++ b/include/doorkeeper/implem/layer.inl
@@ -42,9 +42,9 @@ namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
- template
- Layer::Layer (const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource* parTilemap) :
- LayerBase(parTilemap->mapSize(), parTileSize, parMasterTileSize),
+ template
+ Layer::Layer (const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource* parTilemap) :
+ LayerBase(parTilemap->mapSize(), parTileSize, parMasterTileSize),
m_tilemap(parTilemap)
{
DK_ASSERT(m_tilemap);
@@ -52,22 +52,22 @@ namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
- template
- typename Layer::iterator Layer::begin() {
+ template
+ typename Layer::iterator Layer::begin() {
return iterator(&m_tiles, m_tilemap->pixel_conv(), coords(0), this->m_count);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
- template
- typename Layer::iterator Layer::end() {
- return iterator(&m_tiles, m_tilemap->pixel_conv(), make_past_end_coords(this->m_count - 1), make_past_end_coords(this->m_count - 1));
+ template
+ typename Layer::iterator Layer::end() {
+ return iterator(&m_tiles, m_tilemap->pixel_conv(), make_past_end_coords(this->m_count - 1), make_past_end_coords(this->m_count - 1));
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
- template
- void Layer::onPreload (const coords& parFrom, const coords& parTo) {
+ template
+ void Layer::onPreload (const coords& parFrom, const coords& parTo) {
m_tiles.clear();
m_tilemap->fetch(m_tiles, parFrom, parTo);
#if !defined(NDEBUG)
diff --git a/include/doorkeeper/implem/maploader.inl b/include/doorkeeper/implem/maploader.inl
index c17979c..15635c6 100644
--- a/include/doorkeeper/implem/maploader.inl
+++ b/include/doorkeeper/implem/maploader.inl
@@ -16,29 +16,31 @@
*/
namespace dkh {
- template
- dk::Tyler map_load (C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
- dk::BaseMapSource* reader = parFileOpener(parOpen);
- dk::Tyler tyler(reader->tileSize());
+ template
+ dk::Tyler map_load (C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
+ constexpr uint32_t dimensions = PixConv::dimensions;
+ dk::BaseMapSource* reader = parFileOpener(parOpen);
+ dk::Tyler tyler(reader->tileSize());
for (int z = 0; z < reader->layersCount(); ++z) {
- implem::call_push_layer(tyler, parPusher, reader, z);
+ implem::call_push_layer(tyler, parPusher, reader, z);
}
std::vector submaps;
reader->chainedMaps(submaps);
for (const auto& name : submaps) {
- map_load(tyler, parFileOpener, name, parPusher);
+ map_load(tyler, parFileOpener, name, parPusher);
}
return std::move(tyler);
}
- template
- dk::Tyler& map_load (dk::Tyler& parTyler, C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
+ template
+ dk::Tyler& map_load (dk::Tyler& parTyler, C& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
+ constexpr uint32_t dimensions = PixConv::dimensions;
std::stack> name_stack;
std::vector submaps;
name_stack.push(parOpen);
do {
- dk::BaseMapSource* reader = parFileOpener(name_stack.top());
+ dk::BaseMapSource* reader = parFileOpener(name_stack.top());
name_stack.pop();
submaps.clear();
@@ -48,14 +50,14 @@ namespace dkh {
}
for (int z = 0; z < reader->layersCount(); ++z) {
- implem::call_push_layer(parTyler, parPusher, reader, z);
+ implem::call_push_layer(parTyler, parPusher, reader, z);
}
} while (not name_stack.empty());
return parTyler;
}
- template
- dk::BaseMapSource* MapLoaderPool::operator() (const std::string& parName) {
+ template
+ auto MapLoaderPool::operator() (const std::string& parName) -> dk::BaseMapSource* {
auto it_found = pool.find(parName);
if (pool.end() != it_found) {
return it_found->second.get();
@@ -69,18 +71,18 @@ namespace dkh {
}
template
- dk::Tyler call_map_load (M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
- return map_load(parFileOpener, parOpen, parPusher);
+ dk::Tyler call_map_load (M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
+ return map_load(parFileOpener, parOpen, parPusher);
}
template
- dk::Tyler call_map_load (dk::Tyler& parTyler, M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
- return map_load(parTyler, parFileOpener, parOpen, parPusher);
+ dk::Tyler call_map_load (dk::Tyler& parTyler, M& parFileOpener, const std::string& parOpen, const PushLayerMapType& parPusher) {
+ return map_load(parTyler, parFileOpener, parOpen, parPusher);
}
namespace implem {
- template
- void call_push_layer (dk::Tyler& parTyler, const PushLayerMapType& parPusher, dk::BaseMapSource* parReader, int parLayerIndex) {
+ template
+ void call_push_layer (dk::Tyler& parTyler, const PushLayerMapType& parPusher, dk::BaseMapSource* parReader, int parLayerIndex) {
auto it_found = parPusher.find(parReader->layerTypeHash(parLayerIndex));
if (parPusher.end() == it_found)
throw UnknownLayerTemplateException();
diff --git a/include/doorkeeper/implem/pixelconv.inl b/include/doorkeeper/implem/pixelconv.inl
index 1fa06ea..98678aa 100644
--- a/include/doorkeeper/implem/pixelconv.inl
+++ b/include/doorkeeper/implem/pixelconv.inl
@@ -16,6 +16,36 @@
*/
namespace dk {
+ template
+ PixelConvDiamond::PixelConvDiamond (const coords& parTileSize, bool parStaggered, bool parFirstReentrant) :
+ base_class(parStaggered ? MapType_IsometricStaggered : MapType_Isometric, parTileSize),
+ m_first_reentr(parFirstReentrant ? 1 : 0),
+ m_staggered(parStaggered)
+ {
+ }
+
+ template
+ auto PixelConvDiamond::to_pixel (const coords& parFrom) const -> coords {
+ if (m_staggered) {
+ const auto from(parFrom);
+ const CoordinateScalarType xoffs = m_first_reentr xor (from.y() bitand 1);
+ const auto& tile_size = this->tile_size();
+
+ const auto retval(from * tile_size + coords(xoffs * tile_size.x() / 2, 0));
+ return coords(retval.x() / DivX, retval.y() / DivY);
+ }
+ else {
+ DK_ASSERT(false); //not implemented
+ return coords(0);
+ }
+ }
+
+ template
+ auto PixelConvDiamond::pick_tile (const coords& parPixelPoint) const -> coords {
+ DK_ASSERT(false); //not implemented
+ return coords(0);
+ }
+
template
PixelConv::PixelConv (MapTypes parType, const coords& parTileSize) :
m_tile_size(parTileSize),
diff --git a/include/doorkeeper/implem/tyler.inl b/include/doorkeeper/implem/tyler.inl
index 7d7ff84..73031ce 100644
--- a/include/doorkeeper/implem/tyler.inl
+++ b/include/doorkeeper/implem/tyler.inl
@@ -18,8 +18,8 @@
namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
- template
- Tyler::Tyler (const coords& parTileSize) :
+ template
+ Tyler::Tyler (const coords& parTileSize) :
m_size(0),
m_tilesize(parTileSize)
{
@@ -27,10 +27,10 @@ namespace dk {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
- template
- typename Tyler::coords::scalar_type Tyler