BGE patch: Relink actuators with target within group when duplicating group; generalize protection against object deletion for all actuators that point to objects.
Certain actuators hold a pointer to an objects: Property, SceneCamera, AddObject, Camera, Parent, TractTo. When a group is duplicated, the actuators that point to objects within the group will be relinked to point to the replicated objects and not to the original objects. This helps to setup self-contained group with a camera following a character for example. This feature also works when adding a single object (and all its children) with the AddObject actuator. The second part of the patch extends the protection against object deletion to all the actuators of the above list (previously, only the TrackTo, AddObject and Property actuators were protected). In case the target object of these actuators is deleted, the BGE won't crash.
This commit is contained in:
@@ -61,6 +61,8 @@ typedef unsigned long uint_ptr;
|
||||
#include "KX_RayCast.h"
|
||||
#include "KX_PythonInit.h"
|
||||
#include "KX_PyMath.h"
|
||||
#include "SCA_IActuator.h"
|
||||
#include "SCA_ISensor.h"
|
||||
|
||||
// This file defines relationships between parents and children
|
||||
// in the game engine.
|
||||
@@ -1668,6 +1670,20 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
|
||||
* --------------------------------------------------------------------- */
|
||||
void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter)
|
||||
{
|
||||
/* intentionally empty ? */
|
||||
// we will relink the sensors and actuators that use object references
|
||||
// if the object is part of the replicated hierarchy, use the new
|
||||
// object reference instead
|
||||
SCA_SensorList& sensorlist = GetSensors();
|
||||
SCA_SensorList::iterator sit;
|
||||
for (sit=sensorlist.begin(); sit != sensorlist.end(); sit++)
|
||||
{
|
||||
(*sit)->Relink(map_parameter);
|
||||
}
|
||||
SCA_ActuatorList& actuatorlist = GetActuators();
|
||||
SCA_ActuatorList::iterator ait;
|
||||
for (ait=actuatorlist.begin(); ait != actuatorlist.end(); ait++)
|
||||
{
|
||||
(*ait)->Relink(map_parameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user