Progress implementing TylerMapSource.
This commit is contained in:
parent
ab17e7a4d0
commit
d21a567fb7
4 changed files with 204 additions and 4 deletions
|
@ -1,5 +1,10 @@
|
|||
#include "doorkeeper/helpers/tylermapsource.hpp"
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <ciso646>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <iterator>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# include <endian.h>
|
||||
|
@ -37,18 +42,22 @@ namespace dkh {
|
|||
template<> uint16_t lil_endian_to_machine ( uint16_t parIn ) a_pure;
|
||||
template<> uint8_t lil_endian_to_machine ( uint8_t parIn ) a_pure;
|
||||
template<> implem::TylerMapHeader lil_endian_to_machine ( implem::TylerMapHeader parIn ) a_pure;
|
||||
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<> 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;
|
||||
template<> implem::TylerMapHeader machine_to_lil_endian ( implem::TylerMapHeader parIn ) a_pure;
|
||||
template<> implem::TylerMapLayerHeader machine_to_lil_endian ( implem::TylerMapLayerHeader parIn ) a_pure;
|
||||
#endif
|
||||
|
||||
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; }
|
||||
|
||||
bool isdigit (char parChar) a_pure a_flatten;
|
||||
|
||||
template<> implem::TylerMapHeader lil_endian_to_machine (implem::TylerMapHeader parIn) {
|
||||
parIn.signature = lil_endian_to_machine(parIn.signature);
|
||||
parIn.file_size = lil_endian_to_machine(parIn.file_size);
|
||||
|
@ -58,6 +67,15 @@ namespace dkh {
|
|||
parIn.map_type = lil_endian_to_machine(parIn.map_type);
|
||||
parIn.map_info_type = lil_endian_to_machine(parIn.map_info_type);
|
||||
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);
|
||||
parIn.layer_start = lil_endian_to_machine(parIn.layer_start);
|
||||
return parIn;
|
||||
}
|
||||
|
||||
template<> implem::TylerMapLayerHeader lil_endian_to_machine (implem::TylerMapLayerHeader parIn) {
|
||||
parIn.layer_length = lil_endian_to_machine(parIn.layer_length);
|
||||
parIn.layer_format = lil_endian_to_machine(parIn.layer_format);
|
||||
return parIn;
|
||||
}
|
||||
|
||||
|
@ -75,6 +93,15 @@ namespace dkh {
|
|||
parIn.map_type = machine_to_lil_endian(parIn.map_type);
|
||||
parIn.map_info_type = machine_to_lil_endian(parIn.map_info_type);
|
||||
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);
|
||||
parIn.layer_start = machine_to_lil_endian(parIn.layer_start);
|
||||
return parIn;
|
||||
}
|
||||
|
||||
template<> implem::TylerMapLayerHeader machine_to_lil_endian (implem::TylerMapLayerHeader parIn) {
|
||||
parIn.layer_length = machine_to_lil_endian(parIn.layer_length);
|
||||
parIn.layer_format = machine_to_lil_endian(parIn.layer_format);
|
||||
return parIn;
|
||||
}
|
||||
#endif
|
||||
|
@ -113,6 +140,10 @@ namespace dkh {
|
|||
parStream.write(parString.c_str(), parString.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isdigit (char parChar) {
|
||||
return std::isdigit(parChar);
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
namespace implem {
|
||||
|
@ -141,5 +172,64 @@ namespace dkh {
|
|||
parComments[full_string.substr(0, equal_pos)] = full_string.substr(equal_pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void read_layer_header (std::istream& parStream, TylerMapLayerHeader& parHeader) {
|
||||
parStream.read(reinterpret_cast<char*>(&parHeader), sizeof(TylerMapLayerHeader));
|
||||
parHeader = lil_endian_to_machine(parHeader);
|
||||
}
|
||||
|
||||
void read_dimensions (std::istream& parStream, uint32_t parDimensions, std::vector<uint32_t>& parMap, std::vector<uint16_t>& parTile) {
|
||||
parMap.reserve(parMap.size() + parDimensions);
|
||||
for (uint32_t z = 0; z < parDimensions; ++z) {
|
||||
const auto dim = read_int<uint32_t>(parStream);
|
||||
parMap.push_back(dim);
|
||||
}
|
||||
|
||||
parTile.reserve(parTile.size() + parDimensions);
|
||||
for (uint32_t z = 0; z < parDimensions; ++z) {
|
||||
const auto dim = read_int<uint16_t>(parStream);
|
||||
parTile.push_back(dim);
|
||||
}
|
||||
}
|
||||
|
||||
void extract_array_from_comments (std::vector<std::string>& parOut, const std::string& parPrefix, const std::map<std::string, std::string>& parMap) {
|
||||
typedef decltype(std::distance(parPrefix.begin(), parPrefix.end())) diff_type;
|
||||
using std::size_t;
|
||||
using boost::lexical_cast;
|
||||
|
||||
parOut.clear();
|
||||
for (const auto& itcurr : parMap) {
|
||||
const std::string& key = itcurr.first;
|
||||
if (parPrefix.size() + 3 > key.size())
|
||||
continue;
|
||||
|
||||
if (not std::equal(parPrefix.begin(), parPrefix.end(), key.begin()))
|
||||
continue;
|
||||
|
||||
if (key[parPrefix.size()] != '[')
|
||||
continue;
|
||||
|
||||
auto it_past_index = std::find_if_not(key.begin() + parPrefix.size() + 1, key.end(), &isdigit);
|
||||
if (it_past_index == key.end())
|
||||
continue;
|
||||
if (*it_past_index != ']')
|
||||
continue;
|
||||
|
||||
if (std::distance(key.begin(), it_past_index) + 1 != static_cast<diff_type>(key.size()))
|
||||
continue;
|
||||
|
||||
boost::string_ref index_part(key);
|
||||
const auto dist = std::distance(key.begin(), it_past_index);
|
||||
DK_ASSERT(dist > static_cast<diff_type>(parPrefix.size() + 1));
|
||||
index_part = index_part.substr(parPrefix.size() + 1, dist - parPrefix.size() - 1);
|
||||
const size_t index = lexical_cast<size_t>(index_part);
|
||||
if (index >= parMap.size())
|
||||
continue;
|
||||
|
||||
if (parOut.size() <= index)
|
||||
parOut.resize(index + 1);
|
||||
parOut[index] = itcurr.second;
|
||||
}
|
||||
}
|
||||
} //namespace implem
|
||||
} //namespace dkh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue