Make m_index uint16 again and replace magic -1 number.
This commit is contained in:
parent
5da4cef4a5
commit
458ec6bcce
2 changed files with 11 additions and 10 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace curry {
|
||||
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) {
|
||||
|
@ -22,25 +23,25 @@ namespace curry {
|
|||
|
||||
TileIterator::TileIterator (WorldViewport* parViewport, bool parEnd) :
|
||||
m_viewport(parViewport),
|
||||
m_index(parEnd ? -1 : 0)
|
||||
m_index(parEnd ? g_invalid_index : 0)
|
||||
{
|
||||
assert(m_viewport);
|
||||
m_pixel_pos = first_col_starting_pixel(
|
||||
static_cast<vec2i>(m_viewport->position()),
|
||||
vector_cast<vec2i>(m_viewport->position()),
|
||||
m_viewport->world()->tile_size()
|
||||
);
|
||||
}
|
||||
|
||||
void TileIterator::increment() {
|
||||
assert(m_index != vec2i(-1));
|
||||
assert(m_index != vec2i(g_invalid_index));
|
||||
|
||||
const WorldGrid& world = *m_viewport->world();
|
||||
vec2i tile_size(world.tile_size());
|
||||
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()
|
||||
);
|
||||
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.y() > -tile_size.y() and pos.y() < m_viewport->size().y());
|
||||
|
@ -55,15 +56,15 @@ namespace curry {
|
|||
m_pixel_pos.y() += tile_size.y();
|
||||
}
|
||||
else {
|
||||
m_index = vec2i(-1);
|
||||
m_index = vec2us(g_invalid_index);
|
||||
}
|
||||
//std::cout << "got index " << m_index << " pixel " <<
|
||||
//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 {
|
||||
auto index = static_cast<vec2us>(m_index);
|
||||
auto index = vector_cast<vec2us>(m_index);
|
||||
return ScreenTile {
|
||||
m_viewport->world()->tile(index),
|
||||
m_pixel_pos
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace curry {
|
|||
void increment();
|
||||
bool equal (const TileIterator& parOther) const;
|
||||
|
||||
WorldViewport* m_viewport;
|
||||
vec2i m_index;
|
||||
vec2i m_pixel_pos;
|
||||
WorldViewport* m_viewport;
|
||||
vec2us m_index;
|
||||
};
|
||||
} //namespace curry
|
||||
|
|
Loading…
Add table
Reference in a new issue