King_DuckZ
701366bf86
This fixes the build on 64-bit machines, where size_t and uint32_t from vector.hpp would mismatch.
74 lines
3.5 KiB
C++
74 lines
3.5 KiB
C++
namespace dk {
|
|
namespace implem {
|
|
///---------------------------------------------------------------------
|
|
///Only enabled if Device::MapDimensions is defined and is the same
|
|
///as D. The function's name is set to give a hint to the user as to
|
|
///why the error has occurred (they are trying to construct a
|
|
///TileMapData with a set dimension that is different from the one
|
|
///hardcoded in the device being passed in). The actual name could be
|
|
///something like get_device_dimensions().
|
|
///---------------------------------------------------------------------
|
|
template <uint32_t D, typename Device>
|
|
inline
|
|
typename std::enable_if<Device::MapDimensions == D, uint32_t>::type err_mismatching_dimension (const Device*) noexcept {
|
|
return Device::MapDimensions;
|
|
}
|
|
|
|
///---------------------------------------------------------------------
|
|
///Only enabled if Device::MapDimensions is not defined. The function's
|
|
///name is set to give a hint to the user as to why the error has
|
|
///occurred (they are trying to construct a TileMapData with a set
|
|
///dimension that is different from the one hardcoded in the device
|
|
///being passed in). The actual name could be something like
|
|
///get_device_dimensions().
|
|
///---------------------------------------------------------------------
|
|
template <uint32_t D, typename Device>
|
|
inline
|
|
typename std::enable_if<HasMapDimensions<Device>::result == false, uint32_t>::type err_mismatching_dimension (const Device*) noexcept {
|
|
return 0;
|
|
}
|
|
|
|
///---------------------------------------------------------------------
|
|
///---------------------------------------------------------------------
|
|
template <uint32_t D, typename Device>
|
|
inline
|
|
typename std::enable_if<Device::MapDimensions == D, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device (Device* parDevice) {
|
|
return parDevice->mapSize();
|
|
}
|
|
|
|
///---------------------------------------------------------------------
|
|
///---------------------------------------------------------------------
|
|
template <uint32_t D, typename Device>
|
|
inline
|
|
typename std::enable_if<HasMapDimensions<Device>::result == false, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device (Device* parDevice) {
|
|
return get_map_size_from_device<D>(parDevice);
|
|
}
|
|
} //namespace implem
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, uint32_t D>
|
|
template <typename Device>
|
|
MapStreamRaw<T, D>::MapStreamRaw (Device& parDevice) :
|
|
MapStreamBase<D>(implem::retrieve_map_size_from_device<D>(&parDevice)),
|
|
m_istream(&parDevice),
|
|
m_deviceHasDim(D == implem::err_mismatching_dimension<D>(&parDevice))
|
|
{
|
|
}
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, uint32_t D>
|
|
std::size_t MapStreamRaw<T, D>::dataBlockRequested (char* parOut, std::size_t parOutSize, const coords& parFrom, const coords& parTo) {
|
|
DK_ASSERT(parOut);
|
|
|
|
const std::size_t totalBlocks = implem::area(parTo - parFrom);
|
|
const std::size_t storableBlocks = parOutSize / sizeof(T);
|
|
const std::size_t readMem = sizeof(T) * std::min(storableBlocks, totalBlocks);
|
|
|
|
const std::streamoff readPos = static_cast<std::streamoff>(implem::area(parFrom));
|
|
m_istream.seekg(readPos, std::ios_base::beg);
|
|
m_istream.read(parOut, readMem);
|
|
return readMem;
|
|
}
|
|
} //namespace dk
|