diff --git a/src/framework/util/rect.h b/src/framework/util/rect.h index e6504163..c4c09ea4 100644 --- a/src/framework/util/rect.h +++ b/src/framework/util/rect.h @@ -244,10 +244,10 @@ public: b2 = r.y2; TRect tmp; - tmp.x1 = std::min(l1, l2); - tmp.x2 = std::max(r1, r2); - tmp.y1 = std::min(t1, t2); - tmp.y2 = std::max(b1, b2); + tmp.x1 = std::max(l1, l2); + tmp.x2 = std::min(r1, r2); + tmp.y1 = std::max(t1, t2); + tmp.y2 = std::min(b1, b2); return tmp; } diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 639cbace..eb2e8b70 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -75,6 +75,8 @@ public: int getWalkOffsetX() { return m_walkOffsetX; } int getWalkOffsetY() { return m_walkOffsetY; } + bool isWalking() { return m_walking; } + CreaturePtr asCreature() { return std::static_pointer_cast(shared_from_this()); } private: diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 6c8e9421..3c167c24 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -62,32 +62,16 @@ void Tile::draw(int x, int y) m_drawElevation = MAX_DRAW_ELEVATION; } - // creatures, check for walking creatures in 2x2 tiles - for(int xi = -1; xi <= 0; ++xi) { - for(int yi = -1; yi <= 0; ++yi) { - TilePtr tile = g_map.getTile(m_position + Position(xi, yi, 0)); + // we can render creatures in 3x3 range + for(int xi = -1; xi <= 1; ++xi) { + for(int yi = -1; yi <= 1; ++yi) { for(CreaturePtr creature : g_map.getTile(m_position + Position(xi, yi, 0))->getCreatures()) { - bool draw = false; - // own creature not walking - if(creature->getWalkOffsetX() == 0 && creature->getWalkOffsetY() == 0 && xi == 0 && yi == 0) - draw = true; - // own creature walking on any direction - else if(xi == 0 && yi == 0 && - creature->getWalkOffsetX() <= 8 && creature->getWalkOffsetY() <= 8 && - creature->getWalkOffsetX() > -24 && creature->getWalkOffsetY() > -24) - draw = true; - // creature walking north/south to neighbour tile - else if(xi == 0 && yi != 0 && (creature->getWalkOffsetY() > 8 || creature->getWalkOffsetY() <= -24) && creature->getWalkOffsetX() == 0) - draw = true; - // creature walking west/east to neighbour tile - else if(xi != 0 && yi == 0 && (creature->getWalkOffsetX() > 8 || creature->getWalkOffsetX() <= -24) && creature->getWalkOffsetY() == 0) - draw = true; - // creature walking in diagonal - else if(xi != 0 && yi != 0 && ((creature->getWalkOffsetY() > 8 || creature->getWalkOffsetY() <= -24) || - (creature->getWalkOffsetX() > 8 || creature->getWalkOffsetX() <= -24))) - draw = true; - if(draw) - creature->draw(x - m_drawElevation + xi*32, y - m_drawElevation + yi*32); + Rect creatureRect(x + xi*32 + creature->getWalkOffsetX(), y + yi*32 + creature->getWalkOffsetY(), 24, 24); + Rect thisTileRect(x, y, 32, 32); + + // only render creatures where bottom right is inside our rect + if(thisTileRect.contains(creatureRect.bottomRight())) + creature->draw(x + xi*32 - m_drawElevation, y + yi*32 - m_drawElevation); } } } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 62dde733..84340c38 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -50,6 +50,8 @@ public: ItemPtr getGround(); bool isFullyOpaque(); + TilePtr asTile() { return std::static_pointer_cast(shared_from_this()); } + private: std::vector m_effects; std::vector m_things;