Browse Source

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.
Konrad Kuśnierz 6 years ago
parent
commit
53dbbd2ba3
2 changed files with 10 additions and 4 deletions
  1. 8
    0
      src/client/map.cpp
  2. 2
    4
      src/client/map.h

+ 8
- 0
src/client/map.cpp View File

@@ -394,6 +394,14 @@ void Map::setZoneColor(tileflags_t zone, const Color& color)
394 394
         m_zoneColors[zone] = color;
395 395
 }
396 396
 
397
+Color Map::getZoneColor(tileflags_t flag)
398
+{
399
+    auto it = m_zoneColors.find(flag);
400
+    if(it == m_zoneColors.end())
401
+        return Color::alpha;
402
+    return it->second;
403
+}
404
+
397 405
 void Map::setForceShowAnimations(bool force)
398 406
 {
399 407
     if(force) {

+ 2
- 4
src/client/map.h View File

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

Loading…
Cancel
Save