tibia-client/src/map.cpp

58 lines
1.7 KiB
C++
Raw Normal View History

2011-08-11 07:52:30 +02:00
#include "map.h"
#include "game.h"
2011-08-12 04:04:28 +02:00
#include <graphics/graphics.h>
2011-08-14 04:09:11 +02:00
#include <graphics/framebuffer.h>
2011-08-11 07:52:30 +02:00
2011-08-12 02:06:01 +02:00
void Map::draw(int x, int y)
2011-08-11 07:52:30 +02:00
{
2011-08-12 03:38:54 +02:00
if(!m_framebuffer)
2011-08-12 06:34:21 +02:00
m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32));
2011-08-12 03:38:54 +02:00
2011-08-14 20:13:33 +02:00
g_graphics.bindColor(Color::white);
2011-08-12 03:38:54 +02:00
m_framebuffer->bind();
2011-08-14 02:30:27 +02:00
Position *playerPos = g_game.getPlayer()->getPosition();
2011-08-12 06:34:21 +02:00
// player is above 7
2011-08-14 02:30:27 +02:00
if(playerPos->z <= 7) {
2011-08-12 06:34:21 +02:00
// player pos it 8-6. check if we can draw upper floors.
2011-08-14 02:30:27 +02:00
/*bool draw = true;
2011-08-12 06:34:21 +02:00
for(int jz = 6; jz >= 0; --jz) {
2011-08-14 02:30:27 +02:00
if(m_tiles[Position(8+(6-jz), 6+(6-jz), jz)]->getStackSize() > 0) {
2011-08-12 06:34:21 +02:00
draw = false;
}
2011-08-14 02:30:27 +02:00
}*/
2011-08-12 06:34:21 +02:00
for(int iz = 7; iz > 0; --iz) {
// +1 in draws cause 64x64 items may affect view.
2011-08-14 02:30:27 +02:00
for(int ix = - 8; ix < + 8; ++ix) {
for(int iy = - 6; iy < + 6; ++iy) {
Position relativePos = Position(playerPos->x + ix, playerPos->y + iy, iz);
//Position drawPos = Position(ix + 8, iy - playerPos->y + 6, iz);
//logDebug("x: ", relativePos.x, " y: ", relativePos.y, " z: ", (int)relativePos.z);
if(m_tiles.find(relativePos) != m_tiles.end())
m_tiles[relativePos]->draw(ix + 8, iy + 6, iz);
2011-08-11 07:52:30 +02:00
}
}
2011-08-12 06:34:21 +02:00
2011-08-14 02:30:27 +02:00
//if(!draw)
//break;
2011-08-11 07:52:30 +02:00
}
2011-08-12 06:34:21 +02:00
2011-08-11 07:52:30 +02:00
}
2011-08-12 06:34:21 +02:00
2011-08-12 03:38:54 +02:00
m_framebuffer->unbind();
2011-08-12 04:04:28 +02:00
2011-08-12 06:34:21 +02:00
m_framebuffer->draw(x, y, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height());
2011-08-11 07:52:30 +02:00
}
void Map::addThing(Thing *thing, const Position& pos)
{
2011-08-14 02:30:27 +02:00
if(m_tiles.find(pos) == m_tiles.end()) {
m_tiles[pos] = TilePtr(new Tile());
2011-08-12 06:34:21 +02:00
}
2011-08-14 02:30:27 +02:00
m_tiles[pos]->addThing(thing);
2011-08-11 07:52:30 +02:00
}