map draw improvements
This commit is contained in:
parent
7cf188a67d
commit
0a268fc7d9
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
38
src/map.cpp
38
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) {
|
||||
|
||||
// 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) {
|
||||
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->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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
18
src/tile.cpp
18
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue