Permalink
Browse files

Do not use unnecessary memory on atmosphere effects when no atmospher…

…e effects are in use.

Based on patch by wolftrak in ticket:4079, closes ticket:4079
  • Loading branch information...
1 parent feb2ae5 commit b57d0688d0d81fa5ac5e0fd853efa4136d67f7cc @perim perim committed Sep 28, 2013
Showing with 15 additions and 16 deletions.
  1. +13 −16 src/atmos.cpp
  2. +2 −0 src/init.cpp
View
@@ -53,27 +53,24 @@ enum AP_TYPE
enum AP_STATUS
{
- APS_ACTIVE,
- APS_INACTIVE
+ APS_INACTIVE,
+ APS_ACTIVE
};
-static ATPART asAtmosParts[MAX_ATMOS_PARTICLES];
+static ATPART *asAtmosParts = NULL;
static UDWORD freeParticle;
-static UDWORD weather;
+static WT_CLASS weather = WT_NONE;
/* Setup all the particles */
void atmosInitSystem()
{
- for (int i = 0; i < MAX_ATMOS_PARTICLES; i++)
+ if (!asAtmosParts && weather != WT_NONE)
{
- /* None are being used initially */
- asAtmosParts[i].status = APS_INACTIVE;
+ // calloc sets all to APS_INACTIVE initially
+ asAtmosParts = (ATPART *)calloc(MAX_ATMOS_PARTICLES, sizeof(*asAtmosParts));
}
/* Start at the beginning */
freeParticle = 0;
-
- /* No weather to start with */
- weather = WT_NONE;
}
/* Makes a particle wrap around - if it goes off the grid, then it returns
@@ -287,8 +284,6 @@ void atmosUpdateSystem()
break;
case WT_NONE:
break;
- default:
- break;
}
}
}
@@ -341,17 +336,19 @@ void renderParticle(ATPART *psPart)
void atmosSetWeatherType(WT_CLASS type)
{
- if (type == WT_NONE)
+ if (type != weather)
{
+ weather = type;
atmosInitSystem();
}
- else
+ if (type == WT_NONE && asAtmosParts)
{
- weather = type;
+ free(asAtmosParts);
+ asAtmosParts = NULL;
}
}
WT_CLASS atmosGetWeatherType()
{
- return (WT_CLASS)weather;
+ return weather;
}
View
@@ -930,6 +930,8 @@ bool stageOneShutDown(void)
{
debug(LOG_WZ, "== stageOneShutDown ==");
+ atmosSetWeatherType(WT_NONE); // reset weather and free its data
+
pie_FreeShaders();
if ( audio_Disabled() == false )

0 comments on commit b57d068

Please sign in to comment.