From 53dbbd2ba3d6670477946cf0169a7a4772315f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Ku=C5=9Bnierz?= Date: Sat, 9 May 2015 20:27:04 +0200 Subject: [PATCH] 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. --- src/client/map.cpp | 8 ++++++++ src/client/map.h | 6 ++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/map.cpp b/src/client/map.cpp index dc061ee8..343b0c2d 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -394,6 +394,14 @@ void Map::setZoneColor(tileflags_t zone, const Color& 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) { if(force) { diff --git a/src/client/map.h b/src/client/map.h index f25c9749..8dca1134 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -196,7 +196,7 @@ public: void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; } 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; } bool showZones() { return m_zoneFlags != 0; } bool showZone(tileflags_t zone) { return (m_zoneFlags & zone) == zone; } @@ -257,7 +257,7 @@ private: uint8 m_animationFlags; uint32 m_zoneFlags; - std::array m_zoneColors; + std::map m_zoneColors; float m_zoneOpacity; Light m_light; @@ -272,5 +272,3 @@ private: extern Map g_map; #endif - -/* vim: set ts=4 sw=4 et: */