BGE performance: use inline function as much as possible in scenegraph and logic to avoid function call.

This commit is contained in:
Benoit Bolsee 2009-05-03 21:51:57 +00:00
parent 20888482ae
commit 2aa3c932d0
9 changed files with 81 additions and 140 deletions

@ -453,50 +453,12 @@ double* CValue::GetVector3(bool bGetTransformedVec)
/*---------------------------------------------------------------------------------------------------------------------
Reference Counting
---------------------------------------------------------------------------------------------------------------------*/
//
// Add a reference to this value
//
CValue *CValue::AddRef()
{
// Increase global reference count, used to see at the end of the program
// if all CValue-derived classes have been dereferenced to 0
//debug(gRefCountValue++);
#ifdef _DEBUG
//gRefCountValue++;
#endif
m_refcount++;
return this;
}
//
// Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
//
int CValue::Release()
{
// Decrease global reference count, used to see at the end of the program
// if all CValue-derived classes have been dereferenced to 0
//debug(gRefCountValue--);
#ifdef _DEBUG
//gRefCountValue--;
#endif
// Decrease local reference count, if it reaches 0 the object should be freed
if (--m_refcount > 0)
{
// Reference count normal, return new reference count
return m_refcount;
}
else
{
// Reference count reached 0, delete ourselves and return 0
// MT_assert(m_refcount==0, "Reference count reached sub-zero, object released too much");
delete this;
return 0;
}
}

@ -259,9 +259,48 @@ public:
};
/// Reference Counting
int GetRefCount() { return m_refcount; }
virtual CValue* AddRef(); // Add a reference to this value
virtual int Release(); // Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
int GetRefCount()
{
return m_refcount;
}
// Add a reference to this value
CValue* AddRef()
{
// Increase global reference count, used to see at the end of the program
// if all CValue-derived classes have been dereferenced to 0
//debug(gRefCountValue++);
#ifdef _DEBUG
//gRefCountValue++;
#endif
m_refcount++;
return this;
}
// Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
int Release()
{
// Decrease global reference count, used to see at the end of the program
// if all CValue-derived classes have been dereferenced to 0
//debug(gRefCountValue--);
#ifdef _DEBUG
//gRefCountValue--;
#endif
// Decrease local reference count, if it reaches 0 the object should be freed
if (--m_refcount > 0)
{
// Reference count normal, return new reference count
return m_refcount;
}
else
{
// Reference count reached 0, delete ourselves and return 0
// MT_assert(m_refcount==0, "Reference count reached sub-zero, object released too much");
delete this;
return 0;
}
}
/// Property Management

@ -44,13 +44,6 @@ SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj,
void SCA_IActuator::AddEvent(CValue* event)
{
m_events.push_back(event);
}
void SCA_IActuator::RemoveAllEvents()
{ // remove event queue!
for (vector<CValue*>::iterator i=m_events.begin(); !(i==m_events.end());i++)

@ -75,7 +75,11 @@ public:
/**
* Add an event to an actuator.
*/
void AddEvent(CValue* event);
void AddEvent(CValue* event)
{
m_events.push_back(event);
}
virtual void ProcessReplica();
/**

@ -71,13 +71,6 @@ void SCA_ILogicBrick::SetUeberExecutePriority(int execute_Priority)
SCA_IObject* SCA_ILogicBrick::GetParent()
{
return m_gameobj;
}
void SCA_ILogicBrick::ReParent(SCA_IObject* parent)
{
m_gameobj = parent;
@ -142,14 +135,6 @@ void SCA_ILogicBrick::SetName(STR_String name)
m_name = name;
}
bool SCA_ILogicBrick::IsActive()
{
return m_bActive;
}
bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other)
{
return (this->m_Execute_Ueber_Priority < other->m_Execute_Ueber_Priority)
@ -157,22 +142,6 @@ bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other)
(this->m_Execute_Priority < other->m_Execute_Priority));
}
void SCA_ILogicBrick::SetActive(bool active)
{
m_bActive=active;
if (active)
{
//m_gameobj->SetDebugColor(GetDrawColor());
} else
{
//m_gameobj->ResetDebugColor();
}
}
void SCA_ILogicBrick::RegisterEvent(CValue* eventval)
{
if (m_eventval)

@ -59,7 +59,8 @@ public:
void SetExecutePriority(int execute_Priority);
void SetUeberExecutePriority(int execute_Priority);
SCA_IObject* GetParent();
SCA_IObject* GetParent() { return m_gameobj; }
virtual void ReParent(SCA_IObject* parent);
virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
virtual void Delete() { Release(); }
@ -73,8 +74,16 @@ public:
virtual STR_String GetName();
virtual void SetName(STR_String name);
bool IsActive();
void SetActive(bool active) ;
bool IsActive()
{
return m_bActive;
}
void SetActive(bool active)
{
m_bActive=active;
}
virtual bool LessComparedTo(SCA_ILogicBrick* other);

@ -79,29 +79,6 @@ SCA_IObject::~SCA_IObject()
//}
}
SCA_ControllerList& SCA_IObject::GetControllers()
{
return m_controllers;
}
SCA_SensorList& SCA_IObject::GetSensors()
{
return m_sensors;
}
SCA_ActuatorList& SCA_IObject::GetActuators()
{
return m_actuators;
}
void SCA_IObject::AddSensor(SCA_ISensor* act)
{
act->AddRef();
@ -143,20 +120,6 @@ void SCA_IObject::UnregisterActuator(SCA_IActuator* act)
}
}
void SCA_IObject::SetIgnoreActivityCulling(bool b)
{
m_ignore_activity_culling = b;
}
bool SCA_IObject::GetIgnoreActivityCulling()
{
return m_ignore_activity_culling;
}
void SCA_IObject::ReParentLogic()
{
SCA_ActuatorList& oldactuators = GetActuators();
@ -256,14 +219,6 @@ SCA_IActuator* SCA_IObject::FindActuator(const STR_String& actuatorname)
void SCA_IObject::SetCurrentTime(float currentTime) {
//T_InterpolatorList::iterator i;
//for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
// (*i)->Execute(currentTime);
//}
}
#if 0
const MT_Point3& SCA_IObject::ConvertPythonPylist(PyObject* pylist)
{

@ -83,9 +83,18 @@ public:
SCA_IObject(PyTypeObject* T=&Type);
virtual ~SCA_IObject();
SCA_ControllerList& GetControllers();
SCA_SensorList& GetSensors();
SCA_ActuatorList& GetActuators();
SCA_ControllerList& GetControllers()
{
return m_controllers;
}
SCA_SensorList& GetSensors()
{
return m_sensors;
}
SCA_ActuatorList& GetActuators()
{
return m_actuators;
}
void AddSensor(SCA_ISensor* act);
void AddController(SCA_IController* act);
@ -97,20 +106,26 @@ public:
SCA_IActuator* FindActuator(const STR_String& actuatorname);
SCA_IController* FindController(const STR_String& controllername);
void SetCurrentTime(float currentTime);
void SetCurrentTime(float currentTime) {}
void ReParentLogic();
/**
* Set whether or not to ignore activity culling requests
*/
void SetIgnoreActivityCulling(bool b);
void SetIgnoreActivityCulling(bool b)
{
m_ignore_activity_culling = b;
}
/**
* Set whether or not this object wants to ignore activity culling
* requests
*/
bool GetIgnoreActivityCulling();
bool GetIgnoreActivityCulling()
{
return m_ignore_activity_culling;
}
/**
* Suspend all progress.

@ -192,11 +192,6 @@ public:
~KX_GameObject(
);
CValue*
AddRef() {
/* temporarily to find memleaks */ return CValue::AddRef();
}
/**
* @section Stuff which is here due to poor design.
* Inherited from CValue and needs an implementation.