86 lines
2.9 KiB
C++
86 lines
2.9 KiB
C++
#include "doorkeeper/doorkeeper.hpp"
|
|
#include "doorkeepertestConfig.h"
|
|
#include "platform.h"
|
|
#include "platformstrings.h"
|
|
#include "doorkeeper/helpers/asciimapsource.hpp"
|
|
#include "doorkeeper/mapreaders/mapstreamraw.hpp"
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <memory>
|
|
|
|
template <typename Device, typename Tile>
|
|
struct LayerWithData {
|
|
std::unique_ptr<dk::TileMapData<Tile, 2>> tilemap;
|
|
std::unique_ptr<Device> device;
|
|
dk::Layer<Tile, 2>* layer;
|
|
std::string path;
|
|
};
|
|
|
|
namespace {
|
|
template <typename Device, typename Tile>
|
|
void createLayer ( dk::Tyler<2>& parTiler, LayerWithData<Device, Tile>& parOut );
|
|
void printWelcome ( void );
|
|
void addLayer ( dk::Tyler<2>& parTiler, LayerWithData<dkh::AsciiMapSource, int>& parLayerInfo, const char* parPath );
|
|
void printViewport ( const dk::Viewport<2>& parView, const dk::Layer<int, 2>& parLayer );
|
|
} //unnamed namespace
|
|
|
|
int main() {
|
|
typedef dk::Tyler<2>::coords coords2;
|
|
using dk::TileMapData;
|
|
using dkh::AsciiMapSource;
|
|
|
|
printWelcome();
|
|
|
|
dk::Tyler<2> tiler(coords2(10, 6), coords2(64));
|
|
|
|
LayerWithData<AsciiMapSource, int> bottomLayer;
|
|
addLayer(tiler, bottomLayer, DATA_PATH"/test.map");
|
|
|
|
LayerWithData<AsciiMapSource, int> topLayer;
|
|
addLayer(tiler, topLayer, DATA_PATH"/test_2.map");
|
|
|
|
printViewport(dk::Viewport<2>(tiler, coords2(10, 6), coords2(0)), *bottomLayer.layer);
|
|
printViewport(dk::Viewport<2>(tiler, coords2(4, 4), coords2(0)), *bottomLayer.layer);
|
|
|
|
#if !defined(NDEBUG)
|
|
std::cout << "Map size: " << tiler.map_size() << '\n';
|
|
#endif
|
|
std::cout << "Total tiles: " << tiler.tiles_count() << '\n';
|
|
return 0;
|
|
}
|
|
|
|
namespace {
|
|
template <typename Device, typename Tile>
|
|
void createLayer (dk::Tyler<2>& parTiler, LayerWithData<Device, Tile>& parOut) {
|
|
}
|
|
|
|
void printWelcome() {
|
|
std::cout << "Welcome to " << APP_NAME << ' ' << DK_DEVICE_STRING << " version for " << DK_OS_STRING << ' ' << DK_ARCH_STRING << ' ' << DK_BIT_STRING;
|
|
#if defined(DK_ARM)
|
|
std::cout << ' ' << DK_ARM_FAMILY_STRING << ' ' << DK_ARM_ARCH_STRING;
|
|
#endif
|
|
std::cout << '\n';
|
|
}
|
|
|
|
void addLayer (dk::Tyler<2>& parTiler, LayerWithData<dkh::AsciiMapSource, int>& parLayerInfo, const char* parPath) {
|
|
parLayerInfo.path = parPath;
|
|
parLayerInfo.device = std::unique_ptr<dkh::AsciiMapSource>(new dkh::AsciiMapSource(parLayerInfo.path));
|
|
std::unique_ptr<dk::MapStreamRaw<int, 2>> stream(new dk::MapStreamRaw<int, 2>(*parLayerInfo.device));
|
|
parLayerInfo.tilemap = std::unique_ptr<dk::TileMapData<int, 2>>(new dk::TileMapData<int, 2>(std::move(stream)));
|
|
parLayerInfo.layer = &parTiler.push_layer(*parLayerInfo.tilemap);
|
|
}
|
|
|
|
void printViewport (const dk::Viewport<2>& parView, const dk::Layer<int, 2>& parLayer) {
|
|
int col = 0;
|
|
const auto tilecount = parView.count();
|
|
for (auto itTile = parView.begin(parLayer), itTileEND = parView.end(parLayer); itTile != itTileEND; ++itTile) {
|
|
std::cout << *itTile;
|
|
++col;
|
|
if (col == tilecount.x()) {
|
|
col = 0;
|
|
std::cout << '\n';
|
|
}
|
|
}
|
|
}
|
|
} //unnamed namespace
|