Decrease RAM usage by at least 200MB

This was quite ridiculous.

TILESTATE_LAST = 1 << 24

Basically we were creating 2^24 Color structures within the array, each
of them has 4 floats (16 bytes) resulting in about 256 MB of extra
wasted memory.
This commit is contained in:
Konrad Kuśnierz 2015-05-09 20:27:04 +02:00
parent e4cdb3834b
commit 53dbbd2ba3
2 changed files with 10 additions and 4 deletions

View File

@ -394,6 +394,14 @@ void Map::setZoneColor(tileflags_t zone, const Color& color)
m_zoneColors[zone] = color; m_zoneColors[zone] = color;
} }
Color Map::getZoneColor(tileflags_t flag)
{
auto it = m_zoneColors.find(flag);
if(it == m_zoneColors.end())
return Color::alpha;
return it->second;
}
void Map::setForceShowAnimations(bool force) void Map::setForceShowAnimations(bool force)
{ {
if(force) { if(force) {

View File

@ -196,7 +196,7 @@ public:
void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; } void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; }
float getZoneOpacity() { return m_zoneOpacity; } float getZoneOpacity() { return m_zoneOpacity; }
Color getZoneColor(tileflags_t flag) { return m_zoneColors[flag]; } Color getZoneColor(tileflags_t flag);
tileflags_t getZoneFlags() { return (tileflags_t)m_zoneFlags; } tileflags_t getZoneFlags() { return (tileflags_t)m_zoneFlags; }
bool showZones() { return m_zoneFlags != 0; } bool showZones() { return m_zoneFlags != 0; }
bool showZone(tileflags_t zone) { return (m_zoneFlags & zone) == zone; } bool showZone(tileflags_t zone) { return (m_zoneFlags & zone) == zone; }
@ -257,7 +257,7 @@ private:
uint8 m_animationFlags; uint8 m_animationFlags;
uint32 m_zoneFlags; uint32 m_zoneFlags;
std::array<Color, TILESTATE_LAST> m_zoneColors; std::map<uint32, Color> m_zoneColors;
float m_zoneOpacity; float m_zoneOpacity;
Light m_light; Light m_light;
@ -272,5 +272,3 @@ private:
extern Map g_map; extern Map g_map;
#endif #endif
/* vim: set ts=4 sw=4 et: */