Allow viewport to move past the top-left edge of the map.
This commit is contained in:
parent
86bf492507
commit
7e8657b9d8
1 changed files with 19 additions and 7 deletions
|
@ -1,19 +1,31 @@
|
||||||
#include "tileiterator.hpp"
|
#include "tileiterator.hpp"
|
||||||
#include "worldviewport.hpp"
|
#include "worldviewport.hpp"
|
||||||
#include "worldgrid.hpp"
|
#include "worldgrid.hpp"
|
||||||
|
#include "compatibility.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
|
||||||
namespace curry {
|
namespace curry {
|
||||||
|
namespace {
|
||||||
|
vec2i first_col_starting_pixel (const vec2i& parViewportPos, const vec2i& parTileSize) a_pure;
|
||||||
|
|
||||||
|
vec2i first_col_starting_pixel (const vec2i& parViewportPos, const vec2i& parTileSize) {
|
||||||
|
const auto& pos = parViewportPos;
|
||||||
|
const auto& ts = parTileSize;
|
||||||
|
|
||||||
|
return vec2i(
|
||||||
|
(pos.x() > 0 ? -pos.x() % ts.x() : -pos.x()),
|
||||||
|
(pos.y() > 0 ? -pos.y() % ts.y() : -pos.y())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} //unnamed namespace
|
||||||
|
|
||||||
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 ? -1 : 0)
|
||||||
{
|
{
|
||||||
assert(m_viewport);
|
assert(m_viewport);
|
||||||
m_pixel_pos = vec2i(
|
m_pixel_pos = first_col_starting_pixel(m_viewport->position(), m_viewport->world()->tile_size());
|
||||||
-m_viewport->position().x() % m_viewport->world()->tile_size().x(),
|
|
||||||
-m_viewport->position().y() % m_viewport->world()->tile_size().y()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileIterator::increment() {
|
void TileIterator::increment() {
|
||||||
|
@ -21,9 +33,9 @@ namespace curry {
|
||||||
|
|
||||||
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 = vec2i(
|
auto first_tile_pos = first_col_starting_pixel(
|
||||||
-m_viewport->position().x() % tile_size.x(),
|
m_viewport->position(),
|
||||||
-m_viewport->position().y() % tile_size.y()
|
m_viewport->world()->tile_size()
|
||||||
);
|
);
|
||||||
vec2i pos(tile_size * m_index + first_tile_pos);
|
vec2i pos(tile_size * m_index + first_tile_pos);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue