From 0a268fc7d9caa43f7d2d00e1b35adabf1d4e8db7 Mon Sep 17 00:00:00 2001 From: Henrique Date: Fri, 12 Aug 2011 01:34:21 -0300 Subject: [PATCH] map draw improvements --- src/framework/core/engine.cpp | 8 +++---- src/item.cpp | 7 ++++-- src/map.cpp | 42 ++++++++++++++++++++++++----------- src/map.h | 4 ++-- src/tile.cpp | 18 +++++++++++++++ src/tile.h | 2 ++ 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/framework/core/engine.cpp b/src/framework/core/engine.cpp index 307160ea..115086d8 100644 --- a/src/framework/core/engine.cpp +++ b/src/framework/core/engine.cpp @@ -93,10 +93,6 @@ void Engine::run() rootContainer->render(); - // render fps - if(m_calculateFps) - defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10)); - // todo remove. render map g_game.getMap()->draw(0, 0); @@ -108,6 +104,10 @@ void Engine::run() } //item->draw(1, 1, 7); + // render fps + if(m_calculateFps) + defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10)); + g_graphics.endRender(); // swap buffers diff --git a/src/item.cpp b/src/item.cpp index a5049ff2..1533c045 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -86,8 +86,11 @@ void Item::draw(int x, int y, int z) TexturePtr data = g_tibiaSpr.getSprite(itemId); // todo verify this to draw in correct pos (screenX, screenY) - g_graphics.drawTexturedRect(Rect(x - xi*32 - z + 32, y - yi*32 - z + 32, 32, 32), data, Rect(0, 0, 32, 32)); - g_graphics.drawBoundingRect(Rect(x - xi*32 - z + 32, y - yi*32 - z + 32, 32, 32)); + g_graphics.drawTexturedRect(Rect(x - xi*32 - z, y - yi*32 - z, 32, 32), data, Rect(0, 0, 32, 32)); + + //g_graphics.drawBoundingRect(Rect(x - xi*32 - z, y - yi*32 - z, 32, 32), Color::green); + if(x/32 == 7 && y/32 == 5 && z/32+7 == 7) + g_graphics.drawBoundingRect(Rect(x - xi*32 - z, y - yi*32 - z, 32, 32), Color::red); } } } diff --git a/src/map.cpp b/src/map.cpp index e2b34023..3e41de84 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -5,23 +5,41 @@ void Map::draw(int x, int y) { if(!m_framebuffer) - m_framebuffer = FrameBufferPtr(new FrameBuffer(19*32, 15*32)); + m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32)); m_framebuffer->bind(); Position playerPos = g_game.getPlayer()->getPosition(); - for(int ix = 0; ix < 19; ++ix) { - for(int iy = 0; iy < 15; ++iy) { - if(playerPos.getZ() >= 7) { - for(int iz = 7; iz > 0; --iz) { - m_map[ix][iy][iz].draw(x+ix, y+iy, iz); - } + + // player is above 7 + if(playerPos.getZ() <= 7) { + + // player pos it 8-6. check if we can draw upper floors. + bool draw = true; + for(int jz = 6; jz >= 0; --jz) { + if(m_map[8+(6-jz)][6+(6-jz)][jz].getStackSize() > 0) { + draw = false; } } + + for(int iz = 7; iz > 0; --iz) { + + // +1 in draws cause 64x64 items may affect view. + for(int ix = 0; ix < 24; ++ix) { + for(int iy = 0; iy < 20; ++iy) { + m_map[ix+1][iy+1][iz].draw(ix, iy, iz); + } + } + + if(!draw) + break; + } + } + m_framebuffer->unbind(); - m_framebuffer->draw(0, 0, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height()); + m_framebuffer->draw(x, y, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height()); } void Map::addThing(Thing *thing, const Position& pos) @@ -29,12 +47,10 @@ void Map::addThing(Thing *thing, const Position& pos) Position playerPos = g_game.getPlayer()->getPosition(); Position relativePos = Position(pos.getX() - playerPos.getX() + 8, pos.getY() - playerPos.getY() + 6, pos.getZ()); - if(relativePos.getX() >= 18) - logDebug("relativePos is invalid."); - if(relativePos.getY() >= 14) - logDebug("relativePos is invalid."); - if(relativePos.getZ() >= 15) + if(relativePos.getX() >= 25 || relativePos.getY() >= 21 || relativePos.getZ() >= 15) { logDebug("relativePos is invalid."); + return; + } //logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ()); m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing); diff --git a/src/map.h b/src/map.h index a681fa95..01346b58 100644 --- a/src/map.h +++ b/src/map.h @@ -13,8 +13,8 @@ public: void draw(int x, int y); private: - // Visible tiles are 15x11, but we have a +3 value. We have 15 floors. - Tile m_map[20][16][15]; + // Visible tiles are 15x11, but we have a +7 value cause itens visible at other floors. We have 15 floors. + Tile m_map[25][21][15]; FrameBufferPtr m_framebuffer; }; diff --git a/src/tile.cpp b/src/tile.cpp index 8d99a86d..6f4c7ecf 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -47,3 +47,21 @@ void Tile::draw(int x, int y, int z) (*it)->draw(x, y, z); } + +bool Tile::hasGround() +{ + return m_ground != 0; +} + +int Tile::getStackSize() +{ + int ret = 0; + if(m_ground) + ret++; + + ret += m_itemsBot.size(); + ret += m_creatures.size(); + ret += m_itemsTop.size(); + + return ret; +} diff --git a/src/tile.h b/src/tile.h index 5fccc2ea..b1dac21a 100644 --- a/src/tile.h +++ b/src/tile.h @@ -12,6 +12,8 @@ public: void addThing(Thing *thing); void draw(int x, int y, int z); + bool hasGround(); + int getStackSize(); private: Item *m_ground;