remvoe update cache since no much fps increase

This commit is contained in:
Eduardo Bart 2011-08-30 21:28:06 -03:00
parent 8ca0500712
commit 8a179ea585
4 changed files with 59 additions and 85 deletions

View File

@ -32,7 +32,7 @@ Map g_map;
void Map::draw(const Rect& rect) void Map::draw(const Rect& rect)
{ {
if(!m_framebuffer) 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); g_graphics.bindColor(Fw::white);
m_framebuffer->bind(); m_framebuffer->bind();
@ -41,16 +41,25 @@ void Map::draw(const Rect& rect)
int walkOffsetX = localPlayer->getWalkOffsetX(); int walkOffsetX = localPlayer->getWalkOffsetX();
int walkOffsetY = localPlayer->getWalkOffsetY(); int walkOffsetY = localPlayer->getWalkOffsetY();
for(int z = NUM_Z_TILES - 1; z >= 0; --z) { int zstart = getMaxVisibleFloor();
if(m_visibleTiles.size() == 0) for(int z = NUM_Z_TILES-1; z >= zstart; --z) {
if(z < zstart)
continue; continue;
int zdif = m_centralPosition.z - z; int zdif = m_centralPosition.z - z;
for(int step = 0; step < 2; ++step) { for(int y = 0; y < NUM_Y_TILES; ++y) {
for(const TilePtr& tile : m_visibleTiles[z]) { for(int x = 0; x < NUM_X_TILES; ++x) {
int x = (7 + (tile->getPosition().x - m_centralPosition.x) - zdif) * NUM_TILE_PIXELS; Position tilePos(m_centralPosition.x + (x - 8), m_centralPosition.y + (y - 6), m_centralPosition.z);
int y = (5 + (tile->getPosition().y - m_centralPosition.y) - zdif) * NUM_TILE_PIXELS; tilePos.coveredUp(m_centralPosition.z - z);
tile->draw(x - walkOffsetX, y - walkOffsetY, step); 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; y += creature->getWalkOffsetY() - walkOffsetY;
} }
creature->drawInformation(rect.x() + x*horizontalStretchFactor, rect.y() + y*verticalStretchFactor, isCovered(tilePos, m_zstart)); creature->drawInformation(rect.x() + x*horizontalStretchFactor, rect.y() + y*verticalStretchFactor, isCovered(tilePos, 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);
} }
} }
} }
@ -180,7 +163,6 @@ void Map::addThing(ThingPtr thing, int stackpos)
TilePtr& tile = m_tiles[thing->getPosition()]; TilePtr& tile = m_tiles[thing->getPosition()];
if(!tile) { if(!tile) {
tile = TilePtr(new Tile(thing->getPosition())); tile = TilePtr(new Tile(thing->getPosition()));
update();
} }
tile->addThing(thing, stackpos); tile->addThing(thing, stackpos);
@ -240,5 +222,4 @@ void Map::removeCreatureById(uint32 id)
void Map::setCentralPosition(const Position& centralPosition) void Map::setCentralPosition(const Position& centralPosition)
{ {
m_centralPosition = centralPosition; m_centralPosition = centralPosition;
update();
} }

View File

@ -39,7 +39,6 @@ class Map
public: public:
void draw(const Rect& rect); void draw(const Rect& rect);
void update();
int getMaxVisibleFloor(); int getMaxVisibleFloor();
bool isCovered(const Position& pos, int maxFloor); bool isCovered(const Position& pos, int maxFloor);
@ -65,8 +64,6 @@ public:
private: private:
std::unordered_map<Position, TilePtr, PositionHasher> m_tiles; std::unordered_map<Position, TilePtr, PositionHasher> m_tiles;
std::map<uint32, CreaturePtr> m_creatures; std::map<uint32, CreaturePtr> m_creatures;
std::array<std::vector<TilePtr>, NUM_Z_TILES> m_visibleTiles;
int m_zstart;
Light m_light; Light m_light;
Position m_centralPosition; Position m_centralPosition;

View File

@ -34,61 +34,57 @@ Tile::Tile(const Position& position)
m_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) if(m_ground)
m_ground->draw(x, y); m_ground->draw(x, y);
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it; const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes(); const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 1) { 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();
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
m_drawNextOffset += thingAttributes.drawNextOffset; m_drawNextOffset += thingAttributes.drawNextOffset;
} }
}
for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) { for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it; const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 2) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
} m_drawNextOffset += thingAttributes.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);
}
} }
} }
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);
}
} }
} }

View File

@ -31,7 +31,7 @@ class Tile : public LuaObject
public: public:
Tile(const Position& position); Tile(const Position& position);
void draw(int x, int y, int step); void draw(int x, int y);
void addThing(ThingPtr thing, int stackpos); void addThing(ThingPtr thing, int stackpos);
ThingPtr getThing(unsigned int stackpos); ThingPtr getThing(unsigned int stackpos);