BGE: memory leak in Random actuator + make actuator truly random when seed=0 in the UI. When running the game, seed 0 is replaced by a random seed accessible through Python in seed attribute of the actuator. Other seed value will be left unchanged and will generate fixed pseudo random series.

This commit is contained in:
Benoit Bolsee 2009-06-01 18:41:58 +00:00
parent 2a3627e338
commit 4c7a02f6a1
3 changed files with 14 additions and 2 deletions

@ -954,6 +954,11 @@ void BL_ConvertActuators(char* maggiename,
= (bRandomActuator *) bact->data;
unsigned long seedArg = randAct->seed;
if (seedArg == 0)
{
seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
seedArg ^= (intptr_t)randAct;
}
SCA_RandomActuator::KX_RANDOMACT_MODE modeArg
= SCA_RandomActuator::KX_RANDOMACT_NODEF;
SCA_RandomActuator *tmprandomact;

@ -58,7 +58,6 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
m_parameter2(para2),
m_distribution(mode)
{
// m_base is never deleted, probably a memory leak!
m_base = new SCA_RandomNumberGenerator(seed);
m_counter = 0;
enforceConstraints();
@ -68,7 +67,7 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
SCA_RandomActuator::~SCA_RandomActuator()
{
/* intentionally empty */
m_base->Release();
}
@ -81,6 +80,13 @@ CValue* SCA_RandomActuator::GetReplica()
return replica;
}
void SCA_RandomActuator::ProcessReplica()
{
SCA_IActuator::ProcessReplica();
// increment reference count so that we can release the generator at the end
m_base->AddRef();
}
bool SCA_RandomActuator::Update()

@ -91,6 +91,7 @@ class SCA_RandomActuator : public SCA_IActuator
virtual bool Update();
virtual CValue* GetReplica();
virtual void ProcessReplica();
/* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */