Fix some asserts, get rid of subtiles params.
This commit is contained in:
parent
ccd00df6d8
commit
6a6dfd9225
12 changed files with 102 additions and 39 deletions
|
@ -29,6 +29,7 @@
|
|||
#if !defined(NDEBUG)
|
||||
#include <iostream>
|
||||
#endif
|
||||
#include <functional>
|
||||
|
||||
namespace dk {
|
||||
template <uint32_t D>
|
||||
|
@ -39,17 +40,15 @@ namespace dk {
|
|||
public:
|
||||
typedef Vector<D> coords;
|
||||
|
||||
LayerBase ( const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize );
|
||||
LayerBase ( const coords& parCount, const coords& parTileSize );
|
||||
virtual ~LayerBase ( void ) noexcept = default;
|
||||
|
||||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
coords count ( void ) const { return m_mastersize / m_tilesize * m_count; }
|
||||
const coords& mapSize ( void ) const { return m_count; }
|
||||
|
||||
protected:
|
||||
coords m_count;
|
||||
coords m_tilesize;
|
||||
coords m_mastersize;
|
||||
|
||||
private:
|
||||
virtual void onPreload ( const coords& parFrom, const coords& parTo ) = 0;
|
||||
|
@ -69,7 +68,7 @@ namespace dk {
|
|||
|
||||
Layer ( const Layer& ) = delete;
|
||||
Layer ( Layer&& ) = default;
|
||||
Layer ( const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource<D>* parTilemap );
|
||||
Layer ( const coords& parTileSize, BaseMapSource<D>* parTilemap );
|
||||
virtual ~Layer ( void ) noexcept = default;
|
||||
|
||||
Layer& operator= ( const Layer& ) = delete;
|
||||
|
@ -83,6 +82,11 @@ namespace dk {
|
|||
std::vector<T> m_tiles;
|
||||
BaseMapSource<D>* m_tilemap;
|
||||
};
|
||||
|
||||
namespace implem {
|
||||
template <uint32_t D, typename O>
|
||||
bool at_least_one ( const Vector<D>& parLeft, const Vector<D>& parRight, O parOp ) a_pure;
|
||||
} //namespace implem
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/layer.inl"
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace dk {
|
|||
|
||||
Tyler ( void ) = delete;
|
||||
Tyler ( Tyler&& ) = default;
|
||||
explicit Tyler ( const coords& parTileSize );
|
||||
Tyler ( const coords& parMapSize, const coords& parTileSize );
|
||||
~Tyler ( void ) noexcept = default;
|
||||
|
||||
typename coords::scalar_type tiles_count ( void ) const;
|
||||
|
@ -47,8 +47,6 @@ namespace dk {
|
|||
template <typename T>
|
||||
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap, int parIndex );
|
||||
template <typename T>
|
||||
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap, const coords& parSubdiv, int parIndex );
|
||||
template <typename T>
|
||||
void push_layer_void ( BaseMapSource<D>* parTilemap, int parIndex );
|
||||
|
||||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace dkh {
|
|||
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;
|
||||
coords m_mapSize;
|
||||
const dk::PixelConvSquare<2> m_pixel_conv;
|
||||
const dk::MapTypes m_mapType;
|
||||
};
|
||||
|
|
|
@ -16,24 +16,41 @@
|
|||
*/
|
||||
|
||||
namespace dk {
|
||||
namespace implem {
|
||||
///----------------------------------------------------------------------
|
||||
///----------------------------------------------------------------------
|
||||
template <uint32_t D, typename O>
|
||||
inline bool at_least_one (const Vector<D>& parLeft, const Vector<D>& parRight, O parOp) {
|
||||
for (uint32_t z = 0; z < D; ++z) {
|
||||
if (parOp(parLeft[z], parRight[z])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} //namespace implem
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
LayerBase<D>::LayerBase (const coords& parCount, const coords& parTileSize, const coords& parMasterTileSize) :
|
||||
m_count(parCount / (parMasterTileSize / parTileSize)),
|
||||
LayerBase<D>::LayerBase (const coords& parCount, const coords& parTileSize) :
|
||||
m_count(parCount),
|
||||
m_tilesize(parTileSize),
|
||||
m_mastersize(parMasterTileSize),
|
||||
m_haveFrom(0),
|
||||
m_haveTo(0)
|
||||
{
|
||||
DK_ASSERT((parMasterTileSize / parTileSize) * parTileSize == parMasterTileSize);
|
||||
DK_ASSERT(parCount > 0);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
void LayerBase<D>::preload (const coords& parFrom, const coords& parTo) {
|
||||
if (parFrom < m_haveFrom or parTo > m_haveTo) {
|
||||
using implem::at_least_one;
|
||||
using less = std::less<typename coords::scalar_type>;
|
||||
using greater = std::greater<typename coords::scalar_type>;
|
||||
|
||||
if (at_least_one<D>(parFrom, m_haveFrom, less()) or at_least_one<D>(parTo, m_haveTo, greater())) {
|
||||
this->onPreload(parFrom, parTo);
|
||||
m_haveFrom = parFrom;
|
||||
m_haveTo = parTo;
|
||||
|
@ -43,8 +60,8 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, uint32_t D>
|
||||
Layer<T, D>::Layer (const coords& parTileSize, const coords& parMasterTileSize, BaseMapSource<D>* parTilemap) :
|
||||
LayerBase<D>(parTilemap->mapSize(), parTileSize, parMasterTileSize),
|
||||
Layer<T, D>::Layer (const coords& parTileSize, BaseMapSource<D>* parTilemap) :
|
||||
LayerBase<D>(parTilemap->mapSize(), parTileSize),
|
||||
m_tilemap(parTilemap)
|
||||
{
|
||||
DK_ASSERT(m_tilemap);
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace dkh {
|
|||
template <uint32_t D, typename C>
|
||||
dk::Tyler<D> map_load (C& parFileOpener, const std::string& parOpen, const PushLayerMapType<D>& parPusher) {
|
||||
dk::BaseMapSource<D>* reader = parFileOpener(parOpen);
|
||||
dk::Tyler<D> tyler(reader->tileSize());
|
||||
dk::Tyler<D> tyler(reader->mapSize(), reader->tileSize());
|
||||
for (int z = 0; z < reader->layersCount(); ++z) {
|
||||
implem::call_push_layer<D>(tyler, parPusher, reader, z);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
Tyler<D>::Tyler (const coords& parTileSize) :
|
||||
m_size(0),
|
||||
Tyler<D>::Tyler (const coords& parMapSize, const coords& parTileSize) :
|
||||
m_size(parMapSize),
|
||||
m_tilesize(parTileSize)
|
||||
{
|
||||
}
|
||||
|
@ -41,18 +41,10 @@ namespace dk {
|
|||
template <uint32_t D>
|
||||
template <typename T>
|
||||
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<D>* parTilemap, int parIndex) {
|
||||
return push_layer<T>(parTilemap, coords(static_cast<CoordinateScalarType>(1)), parIndex);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
template <typename T>
|
||||
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<D>* parTilemap, const coords& parSubdiv, int parIndex) {
|
||||
//TODO: store the index
|
||||
(void)parIndex;
|
||||
|
||||
auto newLayer = new Layer<T, D>(m_tilesize / parSubdiv, m_tilesize, parTilemap);
|
||||
auto newLayer = new Layer<T, D>(m_tilesize, parTilemap);
|
||||
if (m_size == coords(0)) {
|
||||
m_size = newLayer->mapSize();
|
||||
}
|
||||
|
@ -62,7 +54,7 @@ namespace dk {
|
|||
throw SizeMismatchException();
|
||||
}
|
||||
}
|
||||
DK_ASSERT(newLayer->count() == m_size * parSubdiv);
|
||||
DK_ASSERT(newLayer->mapSize() == m_size);
|
||||
m_layers.push_back(LayerPtr(newLayer));
|
||||
return *newLayer;
|
||||
}
|
||||
|
|
|
@ -36,14 +36,14 @@ namespace dk {
|
|||
template <typename T>
|
||||
typename Layer<T, D>::iterator Viewport<D>::begin (Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_tyler.map_size() - 1);
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_view.upper());
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::iterator Viewport<D>::end (Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_view.upper()), make_past_end_coords<D>(m_view.upper()));
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
|
@ -62,14 +62,14 @@ namespace dk {
|
|||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::cbegin (const Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::const_iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_tyler.map_size() - 1);
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), m_view.position(), m_view.upper());
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
template <typename T>
|
||||
typename Layer<T, D>::const_iterator Viewport<D>::cend (const Layer<T, D>& parLayer) const {
|
||||
typedef typename Layer<T, D>::const_iterator IterType;
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_tyler.map_size() - 1), make_past_end_coords<D>(m_tyler.map_size() - 1));
|
||||
return IterType(&parLayer.m_tiles, parLayer.m_tilemap->pixel_conv(), make_past_end_coords<D>(m_view.upper()), make_past_end_coords<D>(m_view.upper()));
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
|
|
|
@ -81,17 +81,16 @@ namespace dkh {
|
|||
throw std::runtime_error("Invalid data: can't parse file");
|
||||
}
|
||||
|
||||
coords map_size;
|
||||
if (grammar.lengths.empty()) {
|
||||
map_size.x() = map_size.y() = 0;
|
||||
m_mapSize.x() = m_mapSize.y() = 0;
|
||||
throw std::runtime_error("Invalid data: can't guess map size");
|
||||
}
|
||||
|
||||
//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
|
||||
map_size.x() = grammar.lengths.front();
|
||||
map_size.y() = m_wholedata.size() / map_size.x();
|
||||
m_mapSize.x() = grammar.lengths.front();
|
||||
m_mapSize.y() = m_wholedata.size() / m_mapSize.x();
|
||||
}
|
||||
|
||||
const AsciiMapSource::coords& AsciiMapSource::mapSize() const {
|
||||
|
|
15
test.map
15
test.map
|
@ -1,3 +1,5 @@
|
|||
0000000000
|
||||
0000000000
|
||||
1101111001
|
||||
1101111001
|
||||
1110111100
|
||||
|
@ -6,3 +8,16 @@
|
|||
1111010111
|
||||
1111101111
|
||||
1111111111
|
||||
1111111111
|
||||
1101111001
|
||||
1101111001
|
||||
1110111100
|
||||
1110111000
|
||||
1111011011
|
||||
1111010111
|
||||
1111101111
|
||||
1111111111
|
||||
1111111111
|
||||
0000000000
|
||||
0000000000
|
||||
0000000000
|
||||
|
|
|
@ -87,7 +87,7 @@ int main() {
|
|||
&SDL_DestroyRenderer
|
||||
);
|
||||
|
||||
dk::Tyler<2> tiler(coords2(64));
|
||||
dk::Tyler<2> tiler(coords2(10, 23), coords2(64));
|
||||
|
||||
LayerWithData<AsciiMapSource, int> bottomLayer;
|
||||
addLayer(tiler, bottomLayer, DATA_PATH"/test.map");
|
||||
|
@ -113,7 +113,7 @@ int main() {
|
|||
//Main loop
|
||||
bool running = true;
|
||||
int y = 0;
|
||||
dk::Viewport<2> viewport(tiler, coords2(10, 6), coords2(0));
|
||||
dk::Viewport<2> viewport(tiler, tiler.map_size(), coords2(0));
|
||||
coords2 tile_size;
|
||||
SDL_QueryTexture(tile_0.get(), nullptr, nullptr, &tile_size.x(), &tile_size.y());
|
||||
do {
|
||||
|
|
|
@ -31,7 +31,7 @@ const dk::CoordinateScalarType asciimapsource::map_width = 10;
|
|||
const dk::CoordinateScalarType asciimapsource::map_height = 8;
|
||||
|
||||
asciimapsource::asciimapsource() :
|
||||
tiler(coords2(tile_size)),
|
||||
tiler(coords2(map_width, map_height), coords2(tile_size)),
|
||||
layer(nullptr)
|
||||
{
|
||||
std::istringstream iss((std::string(map_data)));
|
||||
|
|
|
@ -23,6 +23,38 @@ class TileCoordsPrinter:
|
|||
def display_hint(self):
|
||||
return "map";
|
||||
|
||||
class LayerBasePrinter:
|
||||
def __init__(self, parVal):
|
||||
self.val = parVal;
|
||||
|
||||
def to_string(self):
|
||||
m_haveFrom = self.val["m_haveFrom"];
|
||||
m_haveTo = self.val["m_haveTo"];
|
||||
return "{{have from-to = {0}-{1}}}".format(m_haveFrom, m_haveTo);
|
||||
|
||||
def display_hint(self):
|
||||
return "map";
|
||||
|
||||
class TylerPrinter:
|
||||
def __init__(self, parVal):
|
||||
self.val = parVal;
|
||||
|
||||
def to_string(self):
|
||||
m_size = str(self.val["m_size"]);
|
||||
m_tilesize = str(self.val["m_tilesize"]);
|
||||
start = self.val["m_layers"]["_M_impl"]["_M_start"];
|
||||
finish = self.val["m_layers"]["_M_impl"]["_M_finish"];
|
||||
end = self.val["m_layers"]["_M_impl"]["_M_end_of_storage"];
|
||||
layers_count = int(finish - start);
|
||||
m_layers = ", ".join(
|
||||
"{0}: {1}".format(str(self.val["m_layers"]["_M_impl"]["_M_start"][z]["_M_t"]["_M_head_impl"].type.target()), str(self.val["m_layers"]["_M_impl"]["_M_start"][z]["_M_t"]["_M_head_impl"].dereference())) for z in range(0, layers_count));
|
||||
capacity = int(end - start);
|
||||
|
||||
return "{{m_size = {0}, m_tilesize = {1}, m_layers ({2}/{3}) = {{{4}}}}}".format(m_size, m_tilesize, layers_count, capacity, m_layers);
|
||||
|
||||
def display_hint(self):
|
||||
return "map";
|
||||
|
||||
def vector_wrapper_match(parVal):
|
||||
tag_value = str(parVal.type.strip_typedefs().tag);
|
||||
if tag_value == None:
|
||||
|
@ -31,10 +63,16 @@ def vector_wrapper_match(parVal):
|
|||
reg_vecbase = re.compile("^vwr::implem::VecBase<.*>$");
|
||||
reg_vec = re.compile("^vwr::Vec<.*>$");
|
||||
reg_tilecoords = re.compile("^dk::TileCoords<.*>$");
|
||||
reg_tyler = re.compile("^dk::Tyler<.*>$");
|
||||
reg_layerbase = re.compile("^dk::LayerBase<.*>$");
|
||||
if reg_vecbase.match(tag_value) or reg_vec.match(tag_value):
|
||||
return VectorWrapperPrinter(parVal);
|
||||
elif reg_tilecoords.match(tag_value):
|
||||
return TileCoordsPrinter(parVal);
|
||||
elif reg_tyler.match(tag_value):
|
||||
return TylerPrinter(parVal);
|
||||
elif reg_layerbase.match(tag_value):
|
||||
return LayerBasePrinter(parVal);
|
||||
else:
|
||||
return None;
|
||||
|
||||
|
|
Loading…
Reference in a new issue