From e2273e0d14b620335fdbd46850a07ab49bbb1bfd Mon Sep 17 00:00:00 2001 From: Michele Santullo Date: Mon, 17 Aug 2015 13:37:17 +0200 Subject: [PATCH] Change Vec dimension type to uint32_t. --- CMakeLists.txt | 3 ++- include/doorkeeper/implem/tilecoords.inl | 18 ++++++++++-------- include/doorkeeper/implem/tyler.inl | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1710c80..82d7183 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -O3 -Wall -We add_definitions( -DWITH_VECTOR_IOSTREAM -DUSE_MANUAL_TYPENAMES + -DVWR_DIM_TYPE=uint32_t ) find_library(Boost 1.53.0 REQUIRED) @@ -27,7 +28,7 @@ target_include_directories(${PROJECT_NAME} #add_subdirectory(lib/sprout) add_subdirectory(src) -#add_subdirectory(test) +add_subdirectory(test) add_subdirectory(game) #add_subdirectory(tools/mapconv) add_subdirectory(test/gtest-1.7.0) diff --git a/include/doorkeeper/implem/tilecoords.inl b/include/doorkeeper/implem/tilecoords.inl index b3711f0..60021f2 100644 --- a/include/doorkeeper/implem/tilecoords.inl +++ b/include/doorkeeper/implem/tilecoords.inl @@ -43,9 +43,9 @@ namespace dk { template inline CoordinateDistType to_index (const Vector& parPos, const Vector& parUpper) { CoordinateDistType index = 0; - for (CoordinateDistType d = 0; d < D; ++d) { + for (uint32_t d = 0; d < D; ++d) { auto pos = static_cast(parPos[D - 1 - d]); - for (CoordinateDistType p = 0; p < D - 1 - d; ++p) { + for (uint32_t p = 0; p < D - 1 - d; ++p) { pos *= static_cast(parUpper[p] + 1); } @@ -86,15 +86,16 @@ namespace dk { template TileCoords& TileCoords::operator++ () { + static_assert(D > 0, "Dimention must be a positive number"); const coords lower(0); - for (std::size_t d = 0; d < static_cast(D - 1); ++d) { + for (uint32_t d = 0; d < D - 1; ++d) { ++m_pos[d]; if (m_pos[d] > m_size[d]) m_pos[d] = lower[d]; else return *this; } - ++m_pos[static_cast(D - 1)]; + ++m_pos[D - 1]; return *this; } @@ -107,8 +108,9 @@ namespace dk { template TileCoords& TileCoords::operator-- () { + static_assert(D > 0, "Dimention must be a positive number"); const coords lower(0); - for (std::size_t d = 0; d < static_cast(D); ++d) { + for (uint32_t d = 0; d < D; ++d) { if (m_pos[d] > lower[d]) { --m_pos[d]; return *this; @@ -117,7 +119,7 @@ namespace dk { m_pos[d] = m_size[d]; } } - ++m_pos[static_cast(D - 1)]; + ++m_pos[D - 1]; return *this; } @@ -130,7 +132,7 @@ namespace dk { template const TileCoords& TileCoords::operator-= (CoordinateScalarType parValue) { - std::size_t index = 0; + uint32_t index = 0; if (parValue > 0) { while (parValue) { const auto t = parValue % (m_size[index] + 1); @@ -158,7 +160,7 @@ namespace dk { template const TileCoords& TileCoords::operator+= (CoordinateScalarType parValue) { - std::size_t index = 0; + uint32_t index = 0; if (parValue > 0) { while (parValue) { //naïve implementation diff --git a/include/doorkeeper/implem/tyler.inl b/include/doorkeeper/implem/tyler.inl index 2e06939..e600f2f 100644 --- a/include/doorkeeper/implem/tyler.inl +++ b/include/doorkeeper/implem/tyler.inl @@ -12,8 +12,8 @@ namespace dk { ///-------------------------------------------------------------------------- template typename Tyler::coords::scalar_type Tyler::tiles_count() const { - typename coords::value_type retval = 1; - for (size_t d = 0; d < D; ++d) { + typename coords::scalar_type retval = 1; + for (uint32_t d = 0; d < D; ++d) { retval *= m_size[d]; } return retval;