diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index da342695..85af2670 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -32,7 +32,7 @@ Map g_map; void Map::draw(const Rect& rect) { if(!m_framebuffer) - m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32)); + m_framebuffer = FrameBufferPtr(new FrameBuffer(NUM_VISIBLE_X_TILES * NUM_TILE_PIXELS, NUM_VISIBLE_Y_TILES * NUM_TILE_PIXELS)); g_graphics.bindColor(Fw::white); m_framebuffer->bind(); @@ -41,16 +41,25 @@ void Map::draw(const Rect& rect) int walkOffsetX = localPlayer->getWalkOffsetX(); int walkOffsetY = localPlayer->getWalkOffsetY(); - for(int z = NUM_Z_TILES - 1; z >= 0; --z) { - if(m_visibleTiles.size() == 0) + int zstart = getMaxVisibleFloor(); + for(int z = NUM_Z_TILES-1; z >= zstart; --z) { + if(z < zstart) continue; int zdif = m_centralPosition.z - z; - for(int step = 0; step < 2; ++step) { - for(const TilePtr& tile : m_visibleTiles[z]) { - int x = (7 + (tile->getPosition().x - m_centralPosition.x) - zdif) * NUM_TILE_PIXELS; - int y = (5 + (tile->getPosition().y - m_centralPosition.y) - zdif) * NUM_TILE_PIXELS; - tile->draw(x - walkOffsetX, y - walkOffsetY, step); + for(int y = 0; y < NUM_Y_TILES; ++y) { + for(int x = 0; x < NUM_X_TILES; ++x) { + Position tilePos(m_centralPosition.x + (x - 8), m_centralPosition.y + (y - 6), m_centralPosition.z); + tilePos.coveredUp(m_centralPosition.z - z); + if(const TilePtr& tile = m_tiles[tilePos]) { + // skip tiles that are behind another tile + if(z > zstart && isCompletlyCovered(tilePos, zstart)) + continue; + + int x = (7 + (tile->getPosition().x - m_centralPosition.x) - zdif) * NUM_TILE_PIXELS; + int y = (5 + (tile->getPosition().y - m_centralPosition.y) - zdif) * NUM_TILE_PIXELS; + tile->draw(x - walkOffsetX, y - walkOffsetY); + } } } } @@ -85,33 +94,7 @@ void Map::draw(const Rect& rect) y += creature->getWalkOffsetY() - walkOffsetY; } - creature->drawInformation(rect.x() + x*horizontalStretchFactor, rect.y() + y*verticalStretchFactor, isCovered(tilePos, m_zstart)); - } - } - } - } -} - -void Map::update() -{ - m_zstart = getMaxVisibleFloor(); - for(int z = 0; z < NUM_Z_TILES; ++z) { - auto& floorTiles = m_visibleTiles[z]; - floorTiles.clear(); - - if(z < m_zstart) - continue; - - for(int y = 0; y < NUM_Y_TILES; ++y) { - for(int x = 0; x < NUM_X_TILES; ++x) { - Position tilePos(m_centralPosition.x + (x - 8), m_centralPosition.y + (y - 6), m_centralPosition.z); - tilePos.coveredUp(m_centralPosition.z - z); - if(const TilePtr& tile = m_tiles[tilePos]) { - // skip tiles that are behind another tile - if(z > m_zstart && isCompletlyCovered(tilePos, m_zstart)) - continue; - - floorTiles.push_back(tile); + creature->drawInformation(rect.x() + x*horizontalStretchFactor, rect.y() + y*verticalStretchFactor, isCovered(tilePos, zstart)); } } } @@ -180,7 +163,6 @@ void Map::addThing(ThingPtr thing, int stackpos) TilePtr& tile = m_tiles[thing->getPosition()]; if(!tile) { tile = TilePtr(new Tile(thing->getPosition())); - update(); } tile->addThing(thing, stackpos); @@ -240,5 +222,4 @@ void Map::removeCreatureById(uint32 id) void Map::setCentralPosition(const Position& centralPosition) { m_centralPosition = centralPosition; - update(); } diff --git a/src/otclient/core/map.h b/src/otclient/core/map.h index b8d2028d..06772315 100644 --- a/src/otclient/core/map.h +++ b/src/otclient/core/map.h @@ -39,7 +39,6 @@ class Map public: void draw(const Rect& rect); - void update(); int getMaxVisibleFloor(); bool isCovered(const Position& pos, int maxFloor); @@ -65,8 +64,6 @@ public: private: std::unordered_map m_tiles; std::map m_creatures; - std::array, NUM_Z_TILES> m_visibleTiles; - int m_zstart; Light m_light; Position m_centralPosition; diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 3689d809..c6175e6b 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -34,61 +34,57 @@ Tile::Tile(const Position& position) m_position = position; } -void Tile::draw(int x, int y, int step) +void Tile::draw(int x, int y) { - if(step == 0) { - m_drawNextOffset = 0; + m_drawNextOffset = 0; - if(m_ground) - m_ground->draw(x, y); + if(m_ground) + m_ground->draw(x, y); - for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { - const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); + for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { + const ThingPtr& thing = *it; + const ThingAttributes& thingAttributes = thing->getAttributes(); - if(thingAttributes.alwaysOnTopOrder == 1) { - thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - m_drawNextOffset += thingAttributes.drawNextOffset; - } - } - - for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { - const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); - - if(thingAttributes.alwaysOnTopOrder == 2) { - thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - m_drawNextOffset += thingAttributes.drawNextOffset; - } - } - - for(auto it = m_itemsBottom.rbegin(), end = m_itemsBottom.rend(); it != end; ++it) { - const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); + if(thingAttributes.alwaysOnTopOrder == 1) { thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); m_drawNextOffset += thingAttributes.drawNextOffset; } + } - for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) { - const ThingPtr& thing = *it; + for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { + const ThingPtr& thing = *it; + const ThingAttributes& thingAttributes = thing->getAttributes(); + + if(thingAttributes.alwaysOnTopOrder == 2) { thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - } - - for(auto it = m_effects.rbegin(), end = m_effects.rend(); it != end; ++it) { - const ThingPtr& thing = *it; - thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - } - - for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { - const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); - - if(thingAttributes.alwaysOnTopOrder == 3) { - thing->draw(x, y); - } + m_drawNextOffset += thingAttributes.drawNextOffset; } } - else if(step == 1) { + + for(auto it = m_itemsBottom.rbegin(), end = m_itemsBottom.rend(); it != end; ++it) { + const ThingPtr& thing = *it; + const ThingAttributes& thingAttributes = thing->getAttributes(); + thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); + m_drawNextOffset += thingAttributes.drawNextOffset; + } + + for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) { + const ThingPtr& thing = *it; + thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); + } + + for(auto it = m_effects.rbegin(), end = m_effects.rend(); it != end; ++it) { + const ThingPtr& thing = *it; + thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); + } + + for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { + const ThingPtr& thing = *it; + const ThingAttributes& thingAttributes = thing->getAttributes(); + + if(thingAttributes.alwaysOnTopOrder == 3) { + thing->draw(x, y); + } } } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index a7e391db..b96d1cdc 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -31,7 +31,7 @@ class Tile : public LuaObject public: Tile(const Position& position); - void draw(int x, int y, int step); + void draw(int x, int y); void addThing(ThingPtr thing, int stackpos); ThingPtr getThing(unsigned int stackpos);