map draw improvements

This commit is contained in:
Henrique 2011-08-12 01:34:21 -03:00
parent 7cf188a67d
commit 0a268fc7d9
6 changed files with 60 additions and 21 deletions

View File

@ -93,10 +93,6 @@ void Engine::run()
rootContainer->render(); rootContainer->render();
// render fps
if(m_calculateFps)
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10));
// todo remove. render map // todo remove. render map
g_game.getMap()->draw(0, 0); g_game.getMap()->draw(0, 0);
@ -108,6 +104,10 @@ void Engine::run()
} }
//item->draw(1, 1, 7); //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(); g_graphics.endRender();
// swap buffers // swap buffers

View File

@ -86,8 +86,11 @@ void Item::draw(int x, int y, int z)
TexturePtr data = g_tibiaSpr.getSprite(itemId); TexturePtr data = g_tibiaSpr.getSprite(itemId);
// todo verify this to draw in correct pos (screenX, screenY) // 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.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 + 32, y - yi*32 - z + 32, 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);
} }
} }
} }

View File

@ -5,23 +5,41 @@
void Map::draw(int x, int y) void Map::draw(int x, int y)
{ {
if(!m_framebuffer) if(!m_framebuffer)
m_framebuffer = FrameBufferPtr(new FrameBuffer(19*32, 15*32)); m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32));
m_framebuffer->bind(); m_framebuffer->bind();
Position playerPos = g_game.getPlayer()->getPosition(); Position playerPos = g_game.getPlayer()->getPosition();
for(int ix = 0; ix < 19; ++ix) {
for(int iy = 0; iy < 15; ++iy) { // player is above 7
if(playerPos.getZ() >= 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) { for(int iz = 7; iz > 0; --iz) {
m_map[ix][iy][iz].draw(x+ix, y+iy, 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->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) 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 playerPos = g_game.getPlayer()->getPosition();
Position relativePos = Position(pos.getX() - playerPos.getX() + 8, pos.getY() - playerPos.getY() + 6, pos.getZ()); Position relativePos = Position(pos.getX() - playerPos.getX() + 8, pos.getY() - playerPos.getY() + 6, pos.getZ());
if(relativePos.getX() >= 18) if(relativePos.getX() >= 25 || relativePos.getY() >= 21 || relativePos.getZ() >= 15) {
logDebug("relativePos is invalid.");
if(relativePos.getY() >= 14)
logDebug("relativePos is invalid.");
if(relativePos.getZ() >= 15)
logDebug("relativePos is invalid."); logDebug("relativePos is invalid.");
return;
}
//logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ()); //logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ());
m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing); m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing);

View File

@ -13,8 +13,8 @@ public:
void draw(int x, int y); void draw(int x, int y);
private: private:
// Visible tiles are 15x11, but we have a +3 value. We have 15 floors. // Visible tiles are 15x11, but we have a +7 value cause itens visible at other floors. We have 15 floors.
Tile m_map[20][16][15]; Tile m_map[25][21][15];
FrameBufferPtr m_framebuffer; FrameBufferPtr m_framebuffer;
}; };

View File

@ -47,3 +47,21 @@ void Tile::draw(int x, int y, int z)
(*it)->draw(x, y, 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;
}

View File

@ -12,6 +12,8 @@ public:
void addThing(Thing *thing); void addThing(Thing *thing);
void draw(int x, int y, int z); void draw(int x, int y, int z);
bool hasGround();
int getStackSize();
private: private:
Item *m_ground; Item *m_ground;