Make m_index uint16 again and replace magic -1 number.

This commit is contained in:
King_DuckZ 2016-10-30 23:41:14 +01:00
parent 5da4cef4a5
commit 458ec6bcce
2 changed files with 11 additions and 10 deletions

View file

@ -7,6 +7,7 @@
namespace curry { namespace curry {
namespace { namespace {
const uint16_t g_invalid_index = 0xFFFF;
vec2i first_col_starting_pixel (const vec2i& parViewportPos, const vec2i& parTileSize) a_pure; vec2i first_col_starting_pixel (const vec2i& parViewportPos, const vec2i& parTileSize) a_pure;
vec2i first_col_starting_pixel (const vec2i& parViewportPos, const vec2i& parTileSize) { vec2i first_col_starting_pixel (const vec2i& parViewportPos, const vec2i& parTileSize) {
@ -22,25 +23,25 @@ namespace curry {
TileIterator::TileIterator (WorldViewport* parViewport, bool parEnd) : TileIterator::TileIterator (WorldViewport* parViewport, bool parEnd) :
m_viewport(parViewport), m_viewport(parViewport),
m_index(parEnd ? -1 : 0) m_index(parEnd ? g_invalid_index : 0)
{ {
assert(m_viewport); assert(m_viewport);
m_pixel_pos = first_col_starting_pixel( m_pixel_pos = first_col_starting_pixel(
static_cast<vec2i>(m_viewport->position()), vector_cast<vec2i>(m_viewport->position()),
m_viewport->world()->tile_size() m_viewport->world()->tile_size()
); );
} }
void TileIterator::increment() { void TileIterator::increment() {
assert(m_index != vec2i(-1)); assert(m_index != vec2i(g_invalid_index));
const WorldGrid& world = *m_viewport->world(); const WorldGrid& world = *m_viewport->world();
vec2i tile_size(world.tile_size()); vec2i tile_size(world.tile_size());
auto first_tile_pos = first_col_starting_pixel( auto first_tile_pos = first_col_starting_pixel(
static_cast<vec2i>(m_viewport->position()), vector_cast<vec2i>(m_viewport->position()),
m_viewport->world()->tile_size() m_viewport->world()->tile_size()
); );
vec2i pos(tile_size * m_index + first_tile_pos); vec2i pos(tile_size * vector_cast<vec2i>(m_index) + first_tile_pos);
assert(pos.x() > -tile_size.x() and pos.x() < m_viewport->size().x()); assert(pos.x() > -tile_size.x() and pos.x() < m_viewport->size().x());
assert(pos.y() > -tile_size.y() and pos.y() < m_viewport->size().y()); assert(pos.y() > -tile_size.y() and pos.y() < m_viewport->size().y());
@ -55,15 +56,15 @@ namespace curry {
m_pixel_pos.y() += tile_size.y(); m_pixel_pos.y() += tile_size.y();
} }
else { else {
m_index = vec2i(-1); m_index = vec2us(g_invalid_index);
} }
//std::cout << "got index " << m_index << " pixel " << //std::cout << "got index " << m_index << " pixel " <<
//m_index * tile_size - m_viewport->position() << '\n'; //m_index * tile_size - m_viewport->position() << '\n';
m_pixel_pos = tile_size * m_index + first_tile_pos; m_pixel_pos = tile_size * vector_cast<vec2i>(m_index) + first_tile_pos;
} }
ScreenTile TileIterator::dereference() const { ScreenTile TileIterator::dereference() const {
auto index = static_cast<vec2us>(m_index); auto index = vector_cast<vec2us>(m_index);
return ScreenTile { return ScreenTile {
m_viewport->world()->tile(index), m_viewport->world()->tile(index),
m_pixel_pos m_pixel_pos

View file

@ -24,8 +24,8 @@ namespace curry {
void increment(); void increment();
bool equal (const TileIterator& parOther) const; bool equal (const TileIterator& parOther) const;
WorldViewport* m_viewport;
vec2i m_index;
vec2i m_pixel_pos; vec2i m_pixel_pos;
WorldViewport* m_viewport;
vec2us m_index;
}; };
} //namespace curry } //namespace curry