Add a hash mechanism to BaseMapSource.

This is needed to recognize what type of tiles a layer contains.
Client code has to fill in a map of hash => add_layer<T>() pointers.
As a layer is loaded, the correct add_layer<T>() is called based
on the hash saved with the layer itself.
This commit is contained in:
King_DuckZ 2015-06-07 03:57:18 +02:00
parent d21a567fb7
commit fd8a1cbabc
20 changed files with 1647 additions and 40 deletions

View file

@ -9,13 +9,15 @@ int main() {
using dk::coords2;
using dk::Viewport2d;
using dk::Layer2d;
typedef dkh::MapLoaderPool2d<int, std::function<dk::BaseMapSource2d*(const std::string&)>> IntPoolType;
typedef dkh::MapLoaderPool2d<std::function<dk::BaseMapSource2d*(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)); };
Tyler2d tiler(dkh::call_map_load(pool, std::string("test_level.dk")));
dkh::PushLayerMapType<2> pushers;
pushers.insert(std::make_pair(dk::make_signature_hash<int, 2>(), &Tyler2d::push_layer_void<int>));
Tyler2d tiler(dkh::call_map_load(pool, std::string("test_level.dk"), pushers));
return 0;
}

View file

@ -3,6 +3,7 @@
#include "doorkeeper/implem/maptypes.hpp"
#include "doorkeeper/primitivetypes.hpp"
#include "doorkeeper/helpers/hashing.hpp"
#include "doorkeeper/implem/coords_utils.hpp"
#include <cstdint>
#include <vector>
@ -33,6 +34,7 @@ namespace dk {
virtual MapTypes mapType ( void ) const = 0;
virtual int layersCount ( void ) const = 0;
virtual void chainedMaps ( std::vector<std::string>& parOut ) const = 0;
virtual HashType layerTypeHash ( int parIndex ) const = 0;
protected:
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize ) = 0;

View file

@ -29,9 +29,11 @@ namespace dk {
const coords& map_size ( void ) const { return m_size; }
template <typename T>
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap );
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap, int parIndex );
template <typename T>
Layer<T, D>& push_layer ( BaseMapSource<D>* parTilemap, const coords& parSubdiv );
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 );

View file

@ -13,11 +13,11 @@ namespace dk {
} //namespace dk
namespace dkh {
template <typename T, uint32_t D, typename C>
template <uint32_t D, typename C>
struct MapLoaderPool;
template <typename T, typename C>
using MapLoaderPool2d = MapLoaderPool<T, 2, C>;
template <typename C>
using MapLoaderPool2d = MapLoaderPool<2, C>;
} //namespace dkh
#endif

View file

@ -33,6 +33,7 @@ namespace dkh {
virtual int layersCount ( void ) const;
virtual const coords& tileSize ( void ) const;
virtual void chainedMaps ( std::vector<std::string>& parOut ) const;
virtual dk::HashType layerTypeHash ( int parIndex ) const;
private:
void parse_map_data ( std::istream& parSrc );

View file

@ -0,0 +1,30 @@
#ifndef id4E5F8A0ABA6047BA988D512351B9DD2D
#define id4E5F8A0ABA6047BA988D512351B9DD2D
//#include "doorkeeper/implem/string_bt.hpp"
#include "doorkeeper/implem/compatibility.h"
#include <cstdint>
#include <ciso646>
namespace dk {
namespace implem {
struct HashType {
uint64_t a;
uint64_t b;
uint64_t c;
bool operator< ( const HashType& parOther ) const;
};
HashType hash_string ( const char* parString, std::size_t parLen ) a_pure;
} //namespace implem
typedef dk::implem::HashType HashType;
template <typename T, uint32_t D>
implem::HashType make_signature_hash ( void ) a_pure;
} //namespace dk
#include "doorkeeper/implem/hashing.inl"
#endif

View file

@ -3,6 +3,8 @@
#include "doorkeeper/components/tyler.hpp"
#include "doorkeeper/components/basemapsource.hpp"
#include "doorkeeper/helpers/hashing.hpp"
#include "doorkeeper/components/exception.hpp"
#include <cstdint>
#include <utility>
#include <string>
@ -12,14 +14,16 @@
#include <ciso646>
namespace dkh {
template <typename T, uint32_t D, typename C>
template <uint32_t D>
using PushLayerMapType = std::map<dk::HashType, void(dk::Tyler<D>::*)(dk::BaseMapSource<D>*,int)>;
template <uint32_t D, typename C>
struct MapLoaderPool {
typedef std::unique_ptr<dk::BaseMapSource<D>> BaseMapSourceUPtr;
typedef std::map<std::string, BaseMapSourceUPtr> PoolMapType;
enum { dimensions = D };
typedef C opener_type;
typedef T tile_type;
PoolMapType pool;
C opener;
@ -27,17 +31,25 @@ namespace dkh {
dk::BaseMapSource<D>* operator() ( const std::string& parName );
};
template <typename M>
dk::Tyler<M::dimensions> call_map_load ( M& parFileOpener, const std::string& parOpen );
class UnknownLayerTemplateException : public dk::DoorKeeperException {
};
template <typename M>
dk::Tyler<M::dimensions> call_map_load ( dk::Tyler<M::dimensions>& parTyler, M& parFileOpener, const std::string& parOpen );
dk::Tyler<M::dimensions> call_map_load ( M& parFileOpener, const std::string& parOpen, const PushLayerMapType<M::dimensions>& parPusher );
template <typename T, uint32_t D, typename C>
dk::Tyler<D> map_load ( C& parFileOpener, const std::string& parOpen );
template <typename M>
dk::Tyler<M::dimensions> call_map_load ( dk::Tyler<M::dimensions>& parTyler, M& parFileOpener, const std::string& parOpen, const PushLayerMapType<M::dimensions>& parPusher );
template <typename T, uint32_t D, typename C>
dk::Tyler<D>& map_load ( dk::Tyler<D>& parTyler, C& parFileOpener, const std::string& parOpen );
template <uint32_t D, typename C>
dk::Tyler<D> map_load ( C& parFileOpener, const std::string& parOpen, const PushLayerMapType<D>& parPusher );
template <uint32_t D, typename C>
dk::Tyler<D>& map_load ( dk::Tyler<D>& parTyler, C& parFileOpener, const std::string& parOpen, const PushLayerMapType<D>& parPusher );
namespace implem {
template <uint32_t D>
void call_push_layer ( dk::Tyler<D>& parTyler, const PushLayerMapType<D>& parPusher, dk::BaseMapSource<D>* parReader, int parIndex );
} //namespace implem
} //namespace dkh
#include "doorkeeper/implem/maploader.inl"

View file

@ -5,13 +5,13 @@
#include "doorkeeper/implem/vector.hpp"
#include "doorkeeper/components/basemapsource.hpp"
#include "doorkeeper/implem/maptypes.hpp"
#include "doorkeeper/components/exception.hpp"
#include <fstream>
#include <cstdint>
#include <memory>
#include <map>
#include <string>
#include <ciso646>
#include <exception>
#if !defined(NDEBUG) && !defined(WITH_TYLERMAP_WRITER)
# define WITH_TYLERMAP_WRITER
@ -40,14 +40,18 @@ namespace dkh {
virtual dk::MapTypes mapType ( void ) const;
virtual int layersCount ( void ) const;
virtual void chainedMaps ( std::vector<std::string>& parOut ) const;
virtual dk::HashType layerTypeHash ( int parIndex ) const;
private:
struct LayerInfo;
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;
std::map<std::string, std::string> m_comments;
std::vector<LayerInfo> m_layers_info;
coords m_map_size;
coords m_tile_size;
pos_type m_stream_start;
@ -70,9 +74,9 @@ namespace dkh {
};
#endif
class InvalidMapFileException : public std::exception {
class InvalidMapFileException : public dk::DoorKeeperException {
};
class InvalidMapDimensionsException : public std::exception {
class InvalidMapDimensionsException : public dk::DoorKeeperException {
};
namespace implem {
@ -83,7 +87,7 @@ namespace dkh {
uint16_t version_minor;
uint8_t layer_count;
uint8_t map_type;
uint8_t map_info_type;
uint8_t hashing_algorithm;
uint8_t dimensions;
uint32_t dimensions_start;
uint32_t comment_start;

View file

@ -28,6 +28,7 @@ typedef DK_COORD_SCALAR_TYPE MAKE_DK_NAME(CoordinateScalarType);
# include <cassert>
# define DK_ASSERT(a) assert(a)
# endif
# define DK_ASSERTIONS_ENABLED
#else
# if !defined(DK_ASSERT)
# define DK_ASSERT(a)

View file

@ -0,0 +1,15 @@
namespace dk {
template <typename T, uint32_t D>
HashType make_signature_hash() {
#if defined(__GNUC__)
//TODO: use bt::string if possible
const char* const pf = __PRETTY_FUNCTION__;
const std::size_t len = sizeof(__PRETTY_FUNCTION__) - 1;
//constexpr bt::string<sizeof(__PRETTY_FUNCTION__)-1> func_pretty(pf);
#else
# error "Unknown compiler"
#endif
//return implem::hash_string(func_pretty.data(), func_pretty.size());
return implem::hash_string(pf, len);
}
} //namespace dk

View file

@ -1,19 +1,21 @@
namespace dkh {
template <typename T, uint32_t D, typename C>
dk::Tyler<D> map_load (C& parFileOpener, const std::string& parOpen) {
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());
tyler.template push_layer<T>(reader);
for (int z = 0; z < reader->layersCount(); ++z) {
implem::call_push_layer<D>(tyler, parPusher, reader, z);
}
std::vector<std::string> submaps;
reader->chainedMaps(submaps);
for (const auto& name : submaps) {
map_load<T, D, C>(tyler, parFileOpener, name);
map_load<D, C>(tyler, parFileOpener, name, parPusher);
}
return std::move(tyler);
}
template <typename T, uint32_t D, typename C>
dk::Tyler<D>& map_load (dk::Tyler<D>& parTyler, C& parFileOpener, const std::string& parOpen) {
template <uint32_t D, typename C>
dk::Tyler<D>& map_load (dk::Tyler<D>& parTyler, C& parFileOpener, const std::string& parOpen, const PushLayerMapType<D>& parPusher) {
std::stack<std::string, std::vector<std::string>> name_stack;
std::vector<std::string> submaps;
name_stack.push(parOpen);
@ -28,13 +30,15 @@ namespace dkh {
name_stack.emplace(std::move(curr_name));
}
parTyler.template push_layer<T>(reader);
for (int z = 0; z < reader->layersCount(); ++z) {
implem::call_push_layer<D>(parTyler, parPusher, reader, z);
}
} while (not name_stack.empty());
return parTyler;
}
template <typename T, uint32_t D, typename C>
dk::BaseMapSource<D>* MapLoaderPool<T, D, C>::operator() (const std::string& parName) {
template <uint32_t D, typename C>
dk::BaseMapSource<D>* MapLoaderPool<D, C>::operator() (const std::string& parName) {
auto it_found = pool.find(parName);
if (pool.end() != it_found) {
return it_found->second.get();
@ -48,12 +52,23 @@ namespace dkh {
}
template <typename M>
dk::Tyler<M::dimensions> call_map_load (M& parFileOpener, const std::string& parOpen) {
return map_load<typename M::tile_type, M::dimensions, M>(parFileOpener, parOpen);
dk::Tyler<M::dimensions> call_map_load (M& parFileOpener, const std::string& parOpen, const PushLayerMapType<M::dimensions>& parPusher) {
return map_load<M::dimensions, M>(parFileOpener, parOpen, parPusher);
}
template <typename M>
dk::Tyler<M::dimensions> call_map_load (dk::Tyler<M::dimensions>& parTyler, M& parFileOpener, const std::string& parOpen) {
return map_load<typename M::tile_type, M::dimensions, M>(parTyler, parFileOpener, parOpen);
dk::Tyler<M::dimensions> call_map_load (dk::Tyler<M::dimensions>& parTyler, M& parFileOpener, const std::string& parOpen, const PushLayerMapType<M::dimensions>& parPusher) {
return map_load<M::dimensions, M>(parTyler, parFileOpener, parOpen, parPusher);
}
namespace implem {
template <uint32_t D>
void call_push_layer (dk::Tyler<D>& parTyler, const PushLayerMapType<D>& parPusher, dk::BaseMapSource<D>* parReader, int parLayerIndex) {
auto it_found = parPusher.find(parReader->layerTypeHash(parLayerIndex));
if (parPusher.end() == it_found)
throw UnknownLayerTemplateException();
(parTyler.*(it_found->second))(parReader, parLayerIndex);
}
} //namespace implem
} //namespace dkh

View file

@ -23,15 +23,18 @@ namespace dk {
///--------------------------------------------------------------------------
template <uint32_t D>
template <typename T>
Layer<T, D>& Tyler<D>::push_layer (BaseMapSource<D>* parTilemap) {
return push_layer<T>(parTilemap, coords(static_cast<CoordinateScalarType>(1)));
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) {
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);
if (m_size == coords(0)) {
m_size = newLayer->mapSize();
@ -47,6 +50,14 @@ namespace dk {
return *newLayer;
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <uint32_t D>
template <typename T>
void Tyler<D>::push_layer_void (BaseMapSource<D>* parTilemap, int parIndex) {
push_layer<T>(parTilemap, parIndex);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <uint32_t D>

View file

@ -1,4 +1,11 @@
namespace dkh {
template <uint32_t D>
struct TylerMapSource<D>::LayerInfo {
dk::HashType hash;
uint32_t data_start;
uint32_t data_length;
};
template <uint32_t D>
TylerMapSource<D>::TylerMapSource (const char* parFilename) :
m_stream(new std::ifstream(parFilename)),
@ -100,4 +107,11 @@ namespace dkh {
void TylerMapSource<D>::chainedMaps (std::vector<std::string>& parOut) const {
implem::extract_array_from_comments(parOut, "chained_map", m_comments);
}
template <uint32_t D>
dk::HashType TylerMapSource<D>::layerTypeHash (int parIndex) const {
DK_ASSERT(parIndex >= 0);
DK_ASSERT(static_cast<std::size_t>(parIndex) < m_layers_info.size());
return m_layers_info[parIndex].hash;
}
} //namespace dkh

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(doorkeeper CXX)
project(doorkeeper CXX C)
include_directories(
.
@ -8,4 +8,6 @@ include_directories(
add_library(${PROJECT_NAME}
asciimapsource.cpp
tylermapsource.cpp
tiger.c
hashing.cpp
)

View file

@ -1,5 +1,6 @@
#include "doorkeeper/helpers/asciimapsource.hpp"
#include "doorkeeper/implem/compatibility.h"
#include "doorkeeper/helpers/hashing.hpp"
#include "asciimap_parser.hpp"
#include <fstream>
#include <iomanip>
@ -107,4 +108,13 @@ namespace dkh {
void AsciiMapSource::chainedMaps (std::vector<std::string>&) const {
}
dk::HashType AsciiMapSource::layerTypeHash (int parIndex) const {
#if defined(DK_ASSERTIONS_ENABLED)
DK_ASSERT(0 == parIndex);
#else
(void)parIndex;
#endif
return dk::make_signature_hash<int, 2>();
}
} //namespace dkh

30
src/hashing.cpp Normal file
View file

@ -0,0 +1,30 @@
#include "doorkeeper/helpers/hashing.hpp"
#include "tiger.h"
namespace dk {
namespace {
enum {
TigerPaddingV2 = 0x80,
TigerPaddingV1 = 0x01
};
} //unnamed namespace
namespace implem {
HashType hash_string (const char* parString, std::size_t parLen) {
union {
HashType hash;
t_res array;
} retval;
tiger(parString, parLen, retval.array, TigerPaddingV2);
return retval.hash;
}
bool HashType::operator< (const HashType& parOther) const {
return a < parOther.a or
(a == parOther.a and b < parOther.b) or
(a == parOther.a and b == parOther.b and c < parOther.c)
;
}
} //namespace implem
} //namespace dk

1313
src/tiger.c Normal file

File diff suppressed because it is too large Load diff

139
src/tiger.h Normal file
View file

@ -0,0 +1,139 @@
/**
* Copyright (c) 2012 Francisco Blas Izquierdo Riera (klondike)
* The Tiger algorithm was written by Eli Biham and Ross Anderson and is
* available on the official Tiger algorithm page.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* the algorithm authorsip notice, this list of conditions and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* 4. If this license is not appropriate for you please write me at
* klondike ( a t ) klondike ( d o t ) es to negotiate another license.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
/**
* These are some implementations of tiger made without looking at the original
* reference code to ensure the resulting code can be published under a free
* license. The paper was looked though to know how did tiger work.
*/
/** Implementation details:
* * Here we assume char and unsigned char have size 1. If thats not the case in
* your compiler you may want to replace them by a type that does
*/
#ifndef TIGER_H
#define TIGER_H 1
#if !defined(_MSC_VER) || (_MSC_VER >= 1600)
#include <stdint.h>
#else
#if defined(__cplusplus)
extern "C" {
#endif
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#if defined(__cplusplus)
}
#endif
#endif
#if _M_IX86_FP >= 2
#define __SSE2__
#endif
#ifdef __linux
#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define IS_LITTLE_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
#define USE_BIG_ENDIAN
#elif __BYTE_ORDER == __PDP_ENDIAN
#error "If you feel like writting code for PDP endianess go ahead, I'm not doing that"
#else
#error "Unknown endianess"
#endif
#else
//Assume little endian if you know how to detect endianism well on other compilers state it.
#define IS_LITTLE_ENDIAN
#endif
#if defined(_WIN64) || defined(__x86_64__) || defined(__amd64__)
#define HASX64
#endif
#if defined(__cplusplus)
extern "C" {
#endif
/** A word in the tiger hash, 64 bits **/
typedef uint64_t t_word;
/** This one is provided as a commodity for people wanting an easy way to declare result variables **/
typedef t_word t_res[3];
/** Partial calculation as used by tigerp1 and tigerp2 **/
typedef struct {
t_res h; // Hash status
char r[128]; // SALT
t_word n; // Number of characters of r used
t_word hs; // Amount of total data hashed
} t_pres;
/** This one is provided as a commodity for people wanting an easy way to declare block variables **/
typedef t_word t_block[8];
/** Standard tiger calculation, put your string in str and the string length on length and get the result on res **/
void tiger(const char *str, t_word length, t_res res, char pad);
/** Similar to tiger but interleaving accesses to both equally sized strings to reduce overhead and pipeline stalls you get the result of str1 on res1 and the one of str2 on res2 **/
void tiger_2(const char *str1, const char *str2, t_word length, t_res res1, t_res res2);
#ifdef __SSE2__
/** This is equivalent to tiger_2 but uses SSE2 for the key schduling making it faster **/
void tiger_sse2(const char *str1, const char *str2, t_word length, t_res res1, t_res res2);
#endif
/** This function is optimized for use on TTHs just send the two concatenated hashes and you will get back the hash with a prepended 0x01 **/
void tiger_49(const char *str, t_res res);
/** This function is optimized for use on TTHs just send the 1024 sized block and you will get back the hash with a prepended 0x00 **/
void tiger_1025(const char *str, t_res res);
/** Interleaved version of tiger_49 you insert two hashes and get back two results **/
void tiger_2_49(const char *str1, const char *str2, t_res res1, t_res res2);
/** Interleaved version of tiger_1025 you insert two hashes and get back two results **/
void tiger_2_1025(const char *str1, const char *str2, t_res res1, t_res res2);
#ifdef __SSE2__
/** SSE2 version of tiger_49 you insert two hashes and get back two results **/
void tiger_sse2_49(const char *str1, const char *str2, t_res res1, t_res res2);
/** SSE2 version of tiger_1025 you insert two hashes and get back two results **/
void tiger_sse2_1025(const char *str1, const char *str2, t_res res1, t_res res2);
#endif
/** First stage of partial tiger calculation to improve password security during storage **/
void tigerp1(const char *password, t_word length, const char *salt, t_pres *pres);
/** Second stage of partial tiger calculation **/
void tigerp2(const t_pres *pres, const char *salt, t_word length, t_res res);
#if defined(__cplusplus)
}
#endif
#endif

View file

@ -38,6 +38,7 @@ namespace dkh {
const uint32_t g_signature = 0x52504B44; //DKPR
template <typename T> T lil_endian_to_machine ( T parIn ) a_pure;
template<> uint64_t lil_endian_to_machine ( uint64_t parIn ) a_pure;
template<> uint32_t lil_endian_to_machine ( uint32_t parIn ) a_pure;
template<> uint16_t lil_endian_to_machine ( uint16_t parIn ) a_pure;
template<> uint8_t lil_endian_to_machine ( uint8_t parIn ) a_pure;
@ -45,6 +46,7 @@ namespace dkh {
template<> implem::TylerMapLayerHeader lil_endian_to_machine ( implem::TylerMapLayerHeader parIn ) a_pure;
#if defined(WITH_TYLERMAP_WRITER)
template <typename T> T machine_to_lil_endian ( T parIn ) a_pure;
template<> uint64_t machine_to_lil_endian ( uint64_t parIn ) a_pure;
template<> uint32_t machine_to_lil_endian ( uint32_t parIn ) a_pure;
template<> uint16_t machine_to_lil_endian ( uint16_t parIn ) a_pure;
template<> uint8_t machine_to_lil_endian ( uint8_t parIn ) a_pure;
@ -52,6 +54,7 @@ namespace dkh {
template<> implem::TylerMapLayerHeader machine_to_lil_endian ( implem::TylerMapLayerHeader parIn ) a_pure;
#endif
template<> uint64_t lil_endian_to_machine (uint64_t parIn) { return le64toh(parIn); }
template<> uint32_t lil_endian_to_machine (uint32_t parIn) { return le32toh(parIn); }
template<> uint16_t lil_endian_to_machine (uint16_t parIn) { return le16toh(parIn); }
template<> uint8_t lil_endian_to_machine (uint8_t parIn) { return parIn; }
@ -65,7 +68,7 @@ namespace dkh {
parIn.version_minor = lil_endian_to_machine(parIn.version_minor);
parIn.layer_count = lil_endian_to_machine(parIn.layer_count);
parIn.map_type = lil_endian_to_machine(parIn.map_type);
parIn.map_info_type = lil_endian_to_machine(parIn.map_info_type);
parIn.hashing_algorithm = lil_endian_to_machine(parIn.hashing_algorithm);
parIn.dimensions = lil_endian_to_machine(parIn.dimensions);
parIn.dimensions_start = lil_endian_to_machine(parIn.dimensions_start);
parIn.comment_start = lil_endian_to_machine(parIn.comment_start);
@ -80,6 +83,7 @@ namespace dkh {
}
#if defined(WITH_TYLERMAP_WRITER)
template<> uint64_t machine_to_lil_endian (uint64_t parIn) { return htole64(parIn); }
template<> uint32_t machine_to_lil_endian (uint32_t parIn) { return htole32(parIn); }
template<> uint16_t machine_to_lil_endian (uint16_t parIn) { return htole16(parIn); }
template<> uint8_t machine_to_lil_endian (uint8_t parIn) { return parIn; }
@ -91,7 +95,7 @@ namespace dkh {
parIn.version_minor = machine_to_lil_endian(parIn.version_minor);
parIn.layer_count = machine_to_lil_endian(parIn.layer_count);
parIn.map_type = machine_to_lil_endian(parIn.map_type);
parIn.map_info_type = machine_to_lil_endian(parIn.map_info_type);
parIn.hashing_algorithm = machine_to_lil_endian(parIn.hashing_algorithm);
parIn.dimensions = machine_to_lil_endian(parIn.dimensions);
parIn.dimensions_start = machine_to_lil_endian(parIn.dimensions_start);
parIn.comment_start = machine_to_lil_endian(parIn.comment_start);

View file

@ -143,7 +143,7 @@ namespace {
parLayerInfo.path = parPath;
parLayerInfo.device.reset(new dkh::AsciiMapSource(parLayerInfo.path, coords(10, 8), dk::MapType_IsometricStaggered, coords(64, 64)));
parLayerInfo.layer = &parTiler.push_layer<int>(parLayerInfo.device.get());
parLayerInfo.layer = &parTiler.push_layer<int>(parLayerInfo.device.get(), 0);
}
void printViewport (const dk::Viewport<2>& parView, const dk::Layer<int, 2>& parLayer) {