DELEME
This commit is contained in:
parent
163d4e0e13
commit
9ccbe880a4
8 changed files with 108 additions and 44 deletions
|
@ -44,7 +44,8 @@ namespace dk {
|
|||
virtual ~LayerBase ( void ) noexcept = default;
|
||||
|
||||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
const coords& mapSize ( void ) const { return m_count; }
|
||||
const coords& map_size ( void ) const { return m_count; }
|
||||
const coords& tile_size ( void ) const { return m_tilesize; }
|
||||
|
||||
protected:
|
||||
coords m_count;
|
||||
|
@ -68,7 +69,7 @@ namespace dk {
|
|||
|
||||
Layer ( const Layer& ) = delete;
|
||||
Layer ( Layer&& ) = default;
|
||||
Layer ( const coords& parTileSize, BaseMapSource<D>* parTilemap );
|
||||
explicit Layer ( BaseMapSource<D>* parTilemap );
|
||||
virtual ~Layer ( void ) noexcept = default;
|
||||
|
||||
Layer& operator= ( const Layer& ) = delete;
|
||||
|
|
49
include/doorkeeper/components/layeredviewport.hpp
Normal file
49
include/doorkeeper/components/layeredviewport.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef id83407244096746CDBFF64D23F0B1701A
|
||||
#define id83407244096746CDBFF64D23F0B1701A
|
||||
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/components/viewport.hpp"
|
||||
#include "doorkeeper/components/tyler.hpp"
|
||||
#include "doorkeeper/components/layer.hpp"
|
||||
|
||||
namespace dk {
|
||||
template <uint32_t D>
|
||||
class LayeredViewport {
|
||||
public:
|
||||
typedef VectorT<CoordinateAccumType, D> coords_f;
|
||||
|
||||
explicit LayeredViewport ( Tyler<D>& parTyler );
|
||||
~LayeredViewport ( void ) noexcept;
|
||||
|
||||
LayeredViewport<D>& operator+= ( const coords_f& parValue );
|
||||
LayeredViewport<D>& operator-= ( const coords_f& parValue );
|
||||
|
||||
void on_layer_added ( const LayerBase<D>* parLayer );
|
||||
void on_layer_removed ( const LayerBase<D>* parLayer );
|
||||
|
||||
private:
|
||||
typedef std::vector<Viewport<D>> ViewportList;
|
||||
Tyler<D>& m_tyler;
|
||||
};
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/layeredviewport.inl"
|
||||
|
||||
#endif
|
|
@ -36,15 +36,10 @@ namespace dk {
|
|||
public:
|
||||
typedef typename LayerBase<D>::coords coords;
|
||||
|
||||
Tyler ( void ) = delete;
|
||||
Tyler ( void );
|
||||
Tyler ( Tyler&& ) = default;
|
||||
Tyler ( const coords& parMapSize, const coords& parTileSize );
|
||||
~Tyler ( void ) noexcept = default;
|
||||
|
||||
typename coords::scalar_type tiles_count ( void ) const;
|
||||
const coords& map_size ( void ) const { return m_size; }
|
||||
const coords& tile_size ( void ) const { return m_tilesize; }
|
||||
|
||||
template <typename T>
|
||||
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap, int parIndex );
|
||||
template <typename T>
|
||||
|
@ -53,8 +48,6 @@ namespace dk {
|
|||
void preload ( const coords& parFrom, const coords& parTo );
|
||||
|
||||
private:
|
||||
coords m_size;
|
||||
const coords m_tilesize;
|
||||
LayerList m_layers;
|
||||
};
|
||||
} //namespace dk
|
||||
|
|
|
@ -60,8 +60,8 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, uint32_t D>
|
||||
Layer<T, D>::Layer (const coords& parTileSize, BaseMapSource<D>* parTilemap) :
|
||||
LayerBase<D>(parTilemap->mapSize(), parTileSize),
|
||||
Layer<T, D>::Layer (BaseMapSource<D>* parTilemap) :
|
||||
LayerBase<D>(parTilemap->mapSize(), parTilemap->tileSize()),
|
||||
m_tilemap(parTilemap)
|
||||
{
|
||||
DK_ASSERT(m_tilemap);
|
||||
|
|
46
include/doorkeeper/implem/layeredviewport.inl
Normal file
46
include/doorkeeper/implem/layeredviewport.inl
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace dk {
|
||||
template <uint32_t D>
|
||||
LayeredViewport<D>::LayeredViewport (Tyler<D>& parTyler) :
|
||||
m_tyler(parTyler)
|
||||
{
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
LayeredViewport<D>::~LayeredViewport() {
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
LayeredViewport<D>& LayeredViewport<D>::operator+= (const coords_f& parValue) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
LayeredViewport<D>& LayeredViewport<D>::operator-= (const coords_f& parValue) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
void LayeredViewport<D>::on_layer_added (const LayerBase<D>* parLayer) {
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
void LayeredViewport<D>::on_layer_removed (const LayerBase<D>* parLayer) {
|
||||
}
|
||||
} //namespace dk
|
|
@ -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->mapSize(), reader->tileSize());
|
||||
dk::Tyler<D> tyler;
|
||||
for (int z = 0; z < reader->layersCount(); ++z) {
|
||||
implem::call_push_layer<D>(tyler, parPusher, reader, z);
|
||||
}
|
||||
|
|
|
@ -19,21 +19,7 @@ namespace dk {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
Tyler<D>::Tyler (const coords& parMapSize, const coords& parTileSize) :
|
||||
m_size(parMapSize),
|
||||
m_tilesize(parTileSize)
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <uint32_t D>
|
||||
typename Tyler<D>::coords::scalar_type Tyler<D>::tiles_count() const {
|
||||
typename coords::scalar_type retval = 1;
|
||||
for (uint32_t d = 0; d < D; ++d) {
|
||||
retval *= m_size[d];
|
||||
}
|
||||
return retval;
|
||||
Tyler<D>::Tyler() {
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
@ -44,17 +30,7 @@ namespace dk {
|
|||
//TODO: store the index
|
||||
(void)parIndex;
|
||||
|
||||
auto newLayer = new Layer<T, D>(m_tilesize, parTilemap);
|
||||
if (m_size == coords(0)) {
|
||||
m_size = newLayer->mapSize();
|
||||
}
|
||||
else {
|
||||
DK_ASSERT(newLayer->mapSize() == m_size);
|
||||
if (newLayer->mapSize() != m_size) {
|
||||
throw SizeMismatchException();
|
||||
}
|
||||
}
|
||||
DK_ASSERT(newLayer->mapSize() == m_size);
|
||||
auto newLayer = new Layer<T, D>(parTilemap);
|
||||
m_layers.push_back(LayerPtr(newLayer));
|
||||
return *newLayer;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ int main() {
|
|||
&SDL_DestroyRenderer
|
||||
);
|
||||
|
||||
dk::Tyler<2> tiler(coords2(10, 23), coords2(64));
|
||||
dk::Tyler<2> tiler;
|
||||
|
||||
LayerWithData<AsciiMapSource, int> bottomLayer;
|
||||
addLayer(tiler, bottomLayer, DATA_PATH"/test.map");
|
||||
|
@ -99,9 +99,8 @@ int main() {
|
|||
printViewport(dk::Viewport<2>(tiler, coords2(4, 4), coords2(0)), *bottomLayer.layer);
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
std::cout << "Map size: " << tiler.map_size() << '\n';
|
||||
std::cout << "Map size: " << bottomLayer.layer->map_size() << '\n';
|
||||
#endif
|
||||
std::cout << "Total tiles: " << tiler.tiles_count() << '\n';
|
||||
|
||||
//Load resources
|
||||
SDLTextureUPtr tile_0(nullptr, &SDL_DestroyTexture), tile_1(nullptr, &SDL_DestroyTexture);
|
||||
|
@ -113,7 +112,7 @@ int main() {
|
|||
//Main loop
|
||||
bool running = true;
|
||||
int y = 0;
|
||||
dk::Viewport<2> viewport(tiler, tiler.map_size(), coords2(0));
|
||||
dk::Viewport<2> viewport(tiler, bottomLayer.layer->map_size(), coords2(0));
|
||||
coords2 tile_size;
|
||||
SDL_QueryTexture(tile_0.get(), nullptr, nullptr, &tile_size.x(), &tile_size.y());
|
||||
do {
|
||||
|
@ -121,7 +120,7 @@ int main() {
|
|||
viewport.setFrom(coords2(0, y / tile_size.y()));
|
||||
draw_tiles(sdl_renderer.get(), tile_0.get(), tile_1.get(), viewport, *bottomLayer.layer, -(y % tile_size.y()));
|
||||
//++y;
|
||||
if (tile_size.y() * bottomLayer.layer->mapSize().y() == y)
|
||||
if (tile_size.y() * bottomLayer.layer->map_size().y() == y)
|
||||
y = 0;
|
||||
SDL_RenderPresent(sdl_renderer.get());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue