remvoe update cache since no much fps increase
This commit is contained in:
parent
8ca0500712
commit
8a179ea585
|
@ -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) {
|
||||||
|
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 > zstart && isCompletlyCovered(tilePos, zstart))
|
||||||
|
continue;
|
||||||
|
|
||||||
int x = (7 + (tile->getPosition().x - m_centralPosition.x) - zdif) * NUM_TILE_PIXELS;
|
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;
|
int y = (5 + (tile->getPosition().y - m_centralPosition.y) - zdif) * NUM_TILE_PIXELS;
|
||||||
tile->draw(x - walkOffsetX, y - walkOffsetY, step);
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -34,9 +34,8 @@ 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)
|
||||||
|
@ -88,9 +87,6 @@ void Tile::draw(int x, int y, int step)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(step == 1) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tile::addThing(ThingPtr thing, int stackpos)
|
void Tile::addThing(ThingPtr thing, int stackpos)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue