improve minimap

This commit is contained in:
Eduardo Bart
2012-06-22 02:26:22 -03:00
parent aed779a2c8
commit d39cf361ab
20 changed files with 144 additions and 77 deletions

View File

@@ -60,7 +60,7 @@ void FrameBuffer::resize(const Size& size)
return;
m_texture = TexturePtr(new Texture(size));
m_texture->setSmooth(true);
m_texture->setSmooth(m_smooth);
m_texture->setUpsideDown(true);
if(m_fbo) {

View File

@@ -44,10 +44,12 @@ public:
void draw(const Rect& dest, const Rect& src);
void setBackuping(bool enabled) { m_backuping = enabled; }
void setSmooth(bool enabled) { m_smooth = enabled; }
TexturePtr getTexture() { return m_texture; }
Size getSize();
bool isBackuping() { return m_backuping; }
bool isSmooth() { return m_smooth; }
private:
void internalCreate();
@@ -60,6 +62,7 @@ private:
uint m_fbo;
uint m_prevBoundFbo;
Boolean<true> m_backuping;
Boolean<true> m_smooth;
static uint boundFbo;
};

View File

@@ -556,6 +556,9 @@ void Map::setCentralPosition(const Position& centralPosition)
g_game.processCreatureTeleport(localPlayer);
}
});
for(const MapViewPtr& mapView : m_mapViews)
mapView->onMapCenterChange(centralPosition);
}
std::vector<CreaturePtr> Map::getSpectators(const Position& centerPos, bool multiFloor)

View File

@@ -101,7 +101,11 @@ void MapView::draw(const Rect& rect)
if(!m_drawMinimapColors)
tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags);
else {
g_painter->setColor(tile->getMinimapColor());
uint8 c = tile->getMinimapColorByte();
if(c == 0)
continue;
g_painter->setColor(Color::from8bit(c));
g_painter->drawFilledRect(Rect(transformPositionTo2D(tilePos, cameraPosition), tileSize));
}
}
@@ -399,22 +403,28 @@ void MapView::updateVisibleTilesCache(int start)
void MapView::updateGeometry(const Size& visibleDimension, const Size& optimizedSize)
{
int possiblesTileSizes[] = {1,2,4,8,16,32};
int tileSize = 0;
Size bufferSize;
for(int candidateTileSize : possiblesTileSizes) {
bufferSize = (visibleDimension + Size(3,3)) * candidateTileSize;
if(bufferSize.width() > g_graphics.getMaxTextureSize() || bufferSize.height() > g_graphics.getMaxTextureSize())
break;
tileSize = candidateTileSize;
if(optimizedSize.width() < bufferSize.width() - 3*candidateTileSize && optimizedSize.height() < bufferSize.height() - 3*candidateTileSize)
break;
}
if(!m_drawMinimapColors) {
int possiblesTileSizes[] = {1,2,4,8,16,32};
for(int candidateTileSize : possiblesTileSizes) {
bufferSize = (visibleDimension + Size(3,3)) * candidateTileSize;
if(bufferSize.width() > g_graphics.getMaxTextureSize() || bufferSize.height() > g_graphics.getMaxTextureSize())
break;
if(tileSize == 0) {
g_logger.traceError("reached max zoom out");
return;
tileSize = candidateTileSize;
if(optimizedSize.width() < bufferSize.width() - 3*candidateTileSize && optimizedSize.height() < bufferSize.height() - 3*candidateTileSize)
break;
}
if(tileSize == 0) {
g_logger.traceError("reached max zoom out");
return;
}
} else {
tileSize = 1;
bufferSize = visibleDimension + Size(3,3);
}
Size drawDimension = visibleDimension + Size(3,3);
@@ -456,10 +466,15 @@ void MapView::updateGeometry(const Size& visibleDimension, const Size& optimized
void MapView::onTileUpdate(const Position& pos)
{
//if(m_viewMode <= FAR_VIEW)
if(!m_drawMinimapColors)
requestVisibleTilesCacheUpdate();
}
void MapView::onMapCenterChange(const Position& pos)
{
requestVisibleTilesCacheUpdate();
}
void MapView::lockFirstVisibleFloor(int firstVisibleFloor)
{
m_lockedFirstVisibleFloor = firstVisibleFloor;
@@ -656,3 +671,14 @@ TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect)
return tile;
}
void MapView::setDrawMinimapColors(bool enable)
{
if(m_drawMinimapColors == enable)
return;
m_drawMinimapColors = enable;
updateGeometry(m_visibleDimension, m_optimizedSize);
requestVisibleTilesCacheUpdate();
m_smooth = !enable;
m_framebuffer->setSmooth(m_smooth);
}

View File

@@ -61,6 +61,7 @@ private:
protected:
void onTileUpdate(const Position& pos);
void onMapCenterChange(const Position& pos);
friend class Map;
@@ -99,7 +100,7 @@ public:
void setDrawTexts(bool enable) { m_drawTexts = enable; }
bool isDrawingTexts() { return m_drawTexts; }
void setDrawMinimapColors(bool enable) { m_drawMinimapColors = enable; requestVisibleTilesCacheUpdate(); }
void setDrawMinimapColors(bool enable);
bool isDrawingMinimapColors() { return m_drawMinimapColors; }
void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); }
@@ -138,6 +139,7 @@ private:
Boolean<true> m_animated;
Boolean<true> m_autoViewMode;
Boolean<true> m_drawTexts;
Boolean<true> m_smooth;
Boolean<false> m_drawMinimapColors;
std::vector<TilePtr> m_cachedVisibleTiles;
std::vector<CreaturePtr> m_cachedFloorVisibleCreatures;

View File

@@ -34,6 +34,7 @@ Tile::Tile(const Position& position)
{
m_drawElevation = 0;
m_position = position;
m_minimapColorByte = 0;
}
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
@@ -192,6 +193,7 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos)
if(m_things.size() > MAX_THINGS)
removeThing(m_things[MAX_THINGS]);
update();
return oldObject;
}
@@ -217,10 +219,8 @@ bool Tile::removeThing(ThingPtr thing)
}
// reset values managed by this tile
if(removed) {
//thing->setDrawOffset(0);
//thing->setStackpos(0);
}
if(removed)
update();
return removed;
}
@@ -281,19 +281,6 @@ int Tile::getGroundSpeed()
return groundSpeed;
}
Color Tile::getMinimapColor()
{
Color color = Color::black;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())
break;
int c = thing->getMinimapColor();
if(c != 0)
color = Color::from8bit(c);
}
return color;
}
ThingPtr Tile::getTopLookThing()
{
if(isEmpty())
@@ -493,3 +480,14 @@ bool Tile::canErase()
return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty();
}
void Tile::update()
{
m_minimapColorByte = 0;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())
break;
uint8 c = thing->getMinimapColor();
if(c != 0)
m_minimapColorByte = c;
}
}

View File

@@ -82,7 +82,7 @@ public:
const std::vector<ThingPtr>& getThings() { return m_things; }
ItemPtr getGround();
int getGroundSpeed();
Color getMinimapColor();
uint8 getMinimapColorByte() { return m_minimapColorByte; }
int getThingCount() { return m_things.size() + m_effects.size(); }
bool isPathable();
bool isWalkable();
@@ -101,12 +101,15 @@ public:
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
private:
void update();
std::vector<CreaturePtr> m_walkingCreatures;
std::vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
std::vector<ThingPtr> m_things;
Position m_position;
uint8 m_drawElevation;
uint32 m_flags;
uint8 m_minimapColorByte;
};
#endif

View File

@@ -101,8 +101,10 @@ void UIMap::setVisibleDimension(const Size& visibleDimension)
{
m_mapView->setVisibleDimension(visibleDimension);
if(m_aspectRatio != 0.0f)
if(m_aspectRatio != 0.0f) {
m_aspectRatio = visibleDimension.ratio();
updateMapSize();
}
}
void UIMap::setKeepAspectRatio(bool enable)
@@ -111,6 +113,7 @@ void UIMap::setKeepAspectRatio(bool enable)
m_aspectRatio = getVisibleDimension().ratio();
else
m_aspectRatio = 0.0f;
updateMapSize();
}
TilePtr UIMap::getTile(const Point& mousePos)

View File

@@ -61,7 +61,7 @@ public:
bool isDrawingTexts() { return m_mapView->isDrawingTexts(); }
bool isDrawingMinimapColors() { return m_mapView->isDrawingMinimapColors(); }
bool isAnimating() { return m_mapView->isAnimating(); }
float isKeepAspectRatioEnabled() { return m_aspectRatio != 0.0f; }
bool isKeepAspectRatioEnabled() { return m_aspectRatio != 0.0f; }
Size getVisibleDimension() { return m_mapView->getVisibleDimension(); }
MapView::ViewMode getViewMode() { return m_mapView->getViewMode(); }