From 3a4bd506653d25d2df224e48449d8e97a09f3e17 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 1 Sep 2011 14:47:38 -0300 Subject: [PATCH] walk displacment --- src/otclient/core/effect.cpp | 3 +-- src/otclient/core/map.cpp | 1 + src/otclient/core/tile.cpp | 4 +++- src/otclient/net/protocolgameparse.cpp | 9 +++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 46a6c93a..e5d60bc6 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -41,8 +41,7 @@ void Effect::draw(int x, int y) if(m_animation+1 == type.animationPhases) { EffectPtr self = asEffect(); g_dispatcher.addEvent([self] { - TilePtr tile = g_map.getTile(self->getPosition()); - tile->removeEffect(self); + g_map.getTile(self->getPosition())->removeEffect(self); }); m_finished = true; } diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index 756d761d..ee098529 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -74,6 +74,7 @@ void Map::draw(const Rect& rect) float verticalStretchFactor = rect.height() / (float)(MAP_VISIBLE_HEIGHT * NUM_TILE_PIXELS); // draw player names and health bars + //TODO: this could be cached to improve framerate for(int x = 0; x < MAP_VISIBLE_WIDTH; ++x) { for(int y = 0; y < MAP_VISIBLE_HEIGHT; ++y) { Position tilePos = Position(m_centralPosition.x + (x - PLAYER_OFFSET_X + 1), m_centralPosition.y + (y - PLAYER_OFFSET_Y + 1), m_centralPosition.z); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 3c167c24..364e8e4c 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -63,10 +63,12 @@ void Tile::draw(int x, int y) } // we can render creatures in 3x3 range + //TODO: this algorithm is slowing down render too much, but it could be cached to improve framerate 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()) { - Rect creatureRect(x + xi*32 + creature->getWalkOffsetX(), y + yi*32 + creature->getWalkOffsetY(), 24, 24); + auto& type = creature->getType(); + Rect creatureRect(x + xi*32 + creature->getWalkOffsetX() - type.xDisplacment, y + yi*32 + creature->getWalkOffsetY() - type.yDisplacment, 32, 32); Rect thisTileRect(x, y, 32, 32); // only render creatures where bottom right is inside our rect diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 6e840f16..57acfc2c 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -35,7 +35,7 @@ void ProtocolGame::parseMessage(InputMessage& msg) { while(!msg.eof()) { uint8 opt = msg.getU8(); - //dump << "protocol id:" << std::hex << (int)opt; + //dump << "protocol id:" << (int)opt; switch(opt) { case Otc::GameServerInitGame: @@ -663,8 +663,8 @@ void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg) void ProtocolGame::parseCreatureSpeak(InputMessage& msg) { msg.getU32(); // unkSpeak - msg.getString(); // name - msg.getU16(); // level + std::string name = msg.getString(); // name + uint16 level = msg.getU16(); // level uint8 type = msg.getU8(); switch(type) { @@ -692,7 +692,8 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) break; } - msg.getString(); // message + std::string message = msg.getString(); // message + logDebug(name, "[", level, "]: ", message); } void ProtocolGame::parseChannelList(InputMessage& msg)