Fixed memory leak in cMobFamilyCollecter.
This commit is contained in:
parent
d8576a7953
commit
b6741865f2
@ -6,32 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cMobFamilyCollecter::tMobFamilyList cMobFamilyCollecter::InitMobFamilyBeforeCx11(void)
|
void cMobFamilyCollecter::CollectMob(cMonster & a_Monster)
|
||||||
{
|
|
||||||
std::set<cMonster::eFamily> toReturn;
|
|
||||||
toReturn.insert(cMonster::mfHostile);
|
|
||||||
toReturn.insert(cMonster::mfPassive);
|
|
||||||
toReturn.insert(cMonster::mfAmbient);
|
|
||||||
toReturn.insert(cMonster::mfWater);
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cMobFamilyCollecter::tMobFamilyList & cMobFamilyCollecter::m_AllFamilies(void)
|
|
||||||
{
|
|
||||||
// TODO: This memory is leaked:
|
|
||||||
static tMobFamilyList * AllFamilies = new tMobFamilyList(InitMobFamilyBeforeCx11());
|
|
||||||
return *AllFamilies;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMobFamilyCollecter::CollectMob(cMonster& a_Monster)
|
|
||||||
{
|
{
|
||||||
cMonster::eFamily MobFamily = a_Monster.GetMobFamily();
|
cMonster::eFamily MobFamily = a_Monster.GetMobFamily();
|
||||||
m_Mobs[MobFamily].insert(&a_Monster);
|
m_Mobs[MobFamily].insert(&a_Monster);
|
||||||
|
@ -16,16 +16,12 @@ class cChunk;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** This class is used to collect, for each Mob, what is it's family. It was first
|
/** This class is used to collect the list of mobs for each family
|
||||||
being designed to check the caps of the mobs (no more than ... hostile mob in the world)
|
|
||||||
|
|
||||||
as side effects : it also know what is the spawnrate of each family : MG TODO relocate
|
|
||||||
*/
|
*/
|
||||||
class cMobFamilyCollecter
|
class cMobFamilyCollecter
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
typedef const std::set<cMonster::eFamily> tMobFamilyList;
|
typedef const std::set<cMonster::eFamily> tMobFamilyList;
|
||||||
typedef const std::map<cMonster::eFamily,int> tMobSpawRate;
|
|
||||||
|
|
||||||
// collect a mob
|
// collect a mob
|
||||||
void CollectMob(cMonster & a_Monster);
|
void CollectMob(cMonster & a_Monster);
|
||||||
@ -33,15 +29,9 @@ public :
|
|||||||
// return the number of mobs for this family
|
// return the number of mobs for this family
|
||||||
int GetNumberOfCollectedMobs(cMonster::eFamily a_Family);
|
int GetNumberOfCollectedMobs(cMonster::eFamily a_Family);
|
||||||
|
|
||||||
static tMobFamilyList & m_AllFamilies(void);
|
|
||||||
|
|
||||||
static tMobSpawRate & m_SpawnRate(void);
|
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
std::map<cMonster::eFamily, std::set<cMonster*> > m_Mobs;
|
std::map<cMonster::eFamily, std::set<cMonster *> > m_Mobs;
|
||||||
|
|
||||||
static tMobFamilyList InitMobFamilyBeforeCx11(void);
|
|
||||||
static tMobSpawRate InitMobSpawnRateBeforeCx11(void);
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -736,38 +736,42 @@ void cWorld::TickWeather(float a_Dt)
|
|||||||
|
|
||||||
void cWorld::TickMobs(float a_Dt)
|
void cWorld::TickMobs(float a_Dt)
|
||||||
{
|
{
|
||||||
if (!m_bAnimals)
|
// before every Mob action, we have to count them depending on the distance to players, on their family ...
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// before every Mob action, we have to "counts" them depending on the distance to players, on their megatype ...
|
|
||||||
cMobCensus MobCensus;
|
cMobCensus MobCensus;
|
||||||
m_ChunkMap->CollectMobCensus(MobCensus);
|
m_ChunkMap->CollectMobCensus(MobCensus);
|
||||||
if (m_bAnimals)
|
if (m_bAnimals)
|
||||||
{
|
{
|
||||||
for (cMobFamilyCollecter::tMobFamilyList::const_iterator itr = cMobFamilyCollecter::m_AllFamilies().begin(); itr != cMobFamilyCollecter::m_AllFamilies().end(); itr++)
|
// Spawning is enabled, spawn now:
|
||||||
|
static const cMonster::eFamily AllFamilies[] =
|
||||||
{
|
{
|
||||||
int spawnrate = cMonster::GetSpawnRate(*itr);
|
cMonster::mfHostile,
|
||||||
|
cMonster::mfPassive,
|
||||||
|
cMonster::mfAmbient,
|
||||||
|
cMonster::mfWater,
|
||||||
|
} ;
|
||||||
|
for (int i = 0; i < ARRAYCOUNT(AllFamilies); i++)
|
||||||
|
{
|
||||||
|
cMonster::eFamily Family = AllFamilies[i];
|
||||||
|
int spawnrate = cMonster::GetSpawnRate(Family);
|
||||||
if (
|
if (
|
||||||
(m_LastSpawnMonster[*itr] > m_WorldAge - spawnrate) || // Not reached the needed tiks before the next round
|
(m_LastSpawnMonster[Family] > m_WorldAge - spawnrate) || // Not reached the needed tiks before the next round
|
||||||
MobCensus.IsCapped(*itr)
|
MobCensus.IsCapped(Family)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m_LastSpawnMonster[*itr] = m_WorldAge;
|
m_LastSpawnMonster[Family] = m_WorldAge;
|
||||||
cMobSpawner Spawner(*itr, m_AllowedMobs);
|
cMobSpawner Spawner(Family, m_AllowedMobs);
|
||||||
if (Spawner.CanSpawnAnything())
|
if (Spawner.CanSpawnAnything())
|
||||||
{
|
{
|
||||||
m_ChunkMap->SpawnMobs(Spawner);
|
m_ChunkMap->SpawnMobs(Spawner);
|
||||||
// do the spawn
|
// do the spawn
|
||||||
for(cMobSpawner::tSpawnedContainer::const_iterator itr2 = Spawner.getSpawned().begin(); itr2 != Spawner.getSpawned().end(); itr2++)
|
for (cMobSpawner::tSpawnedContainer::const_iterator itr2 = Spawner.getSpawned().begin(); itr2 != Spawner.getSpawned().end(); itr2++)
|
||||||
{
|
{
|
||||||
SpawnMobFinalize(*itr2);
|
SpawnMobFinalize(*itr2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // for itr - Families[]
|
} // for i - AllFamilies[]
|
||||||
} // if (Spawning enabled)
|
} // if (Spawning enabled)
|
||||||
|
|
||||||
// move close mobs
|
// move close mobs
|
||||||
|
Loading…
Reference in New Issue
Block a user