Skip to content

Commit

Permalink
UPBGE: Replace KX_GetActiveScene by KX_GameObject::GetScene when it's…
Browse files Browse the repository at this point in the history
… possible.
  • Loading branch information
panzergame committed Apr 12, 2016
1 parent 1883449 commit 3484d2f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 34 deletions.
7 changes: 3 additions & 4 deletions source/gameengine/Ketsji/KX_Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,7 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, setOnTop,
"setOnTop()\n"
"Sets this camera's viewport on top\n")
{
class KX_Scene* scene = KX_GetActiveScene();
scene->SetCameraOnTop(this);
GetScene()->SetCameraOnTop(this);
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -967,7 +966,7 @@ PyObject *KX_Camera::pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF
{ return PyLong_FromLong(INTERSECT); }


bool ConvertPythonToCamera(PyObject *value, KX_Camera **object, bool py_none_ok, const char *error_prefix)
bool ConvertPythonToCamera(KX_Scene *scene, PyObject *value, KX_Camera **object, bool py_none_ok, const char *error_prefix)
{
if (value==NULL) {
PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
Expand All @@ -988,7 +987,7 @@ bool ConvertPythonToCamera(PyObject *value, KX_Camera **object, bool py_none_ok,

if (PyUnicode_Check(value)) {
STR_String value_str = _PyUnicode_AsString(value);
*object = KX_GetActiveScene()->FindCamera(value_str);
*object = scene->FindCamera(value_str);

if (*object) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

#ifdef WITH_PYTHON
/* utility conversion function */
bool ConvertPythonToCamera(PyObject *value, KX_Camera **object, bool py_none_ok, const char *error_prefix);
bool ConvertPythonToCamera(KX_Scene *scene, PyObject *value, KX_Camera **object, bool py_none_ok, const char *error_prefix);
#endif

class KX_Camera : public KX_GameObject
Expand Down
37 changes: 13 additions & 24 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,9 @@ KX_GameObject::SetOccluder(
}
}

static void setDebug_recursive(SG_Node *node, bool debug)
static void setDebug_recursive(KX_Scene *scene, SG_Node *node, bool debug)
{
NodeList& children = node->GetSGChildren();
KX_Scene *scene = KX_GetActiveScene();

for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) {
SG_Node *childnode = (*childit);
Expand All @@ -999,13 +998,13 @@ static void setDebug_recursive(SG_Node *node, bool debug)

/* if the childobj is NULL then this may be an inverse parent link
* so a non recursive search should still look down this node. */
setDebug_recursive(childnode, debug);
setDebug_recursive(scene, childnode, debug);
}
}

void KX_GameObject::SetUseDebugProperties( bool debug, bool recursive )
{
KX_Scene *scene = KX_GetActiveScene();
KX_Scene *scene = GetScene();

if (debug) {
if (!scene->ObjectInDebugList(this))
Expand All @@ -1015,7 +1014,7 @@ void KX_GameObject::SetUseDebugProperties( bool debug, bool recursive )
scene->RemoveObjectDebugProperties(this);

if (recursive)
setDebug_recursive(GetSGNode(), debug);
setDebug_recursive(scene, GetSGNode(), debug);
}

void
Expand Down Expand Up @@ -2005,7 +2004,6 @@ PyAttributeDef KX_GameObject::Attributes[] = {

PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
{
KX_Scene *scene = KX_GetActiveScene();

PyObject *value;
int use_gfx= 1, use_phys= 0;
Expand All @@ -2017,18 +2015,15 @@ PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
if (!ConvertPythonToMesh(value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
return NULL;

scene->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys);
GetScene()->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys);
Py_RETURN_NONE;
}

PyObject *KX_GameObject::PyEndObject()
{
KX_Scene* scene = GetScene();

scene->DelayedRemoveObject(this);

Py_RETURN_NONE;
GetScene()->DelayedRemoveObject(this);

Py_RETURN_NONE;
}

PyObject *KX_GameObject::PyReinstancePhysicsMesh(PyObject *args)
Expand Down Expand Up @@ -3150,10 +3145,9 @@ PyObject *KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_

PyObject *KX_GameObject::pyattr_get_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_Scene *scene = KX_GetActiveScene();
KX_GameObject *self = static_cast<KX_GameObject*>(self_v);

return PyBool_FromLong(scene->ObjectInDebugList(self));
return PyBool_FromLong(self->GetScene()->ObjectInDebugList(self));
}

int KX_GameObject::pyattr_set_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
Expand All @@ -3173,10 +3167,9 @@ int KX_GameObject::pyattr_set_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attr

PyObject *KX_GameObject::pyattr_get_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_Scene *scene = KX_GetActiveScene();
KX_GameObject *self = static_cast<KX_GameObject*>(self_v);

return PyBool_FromLong(scene->ObjectInDebugList(self));
return PyBool_FromLong(self->GetScene()->ObjectInDebugList(self));
}

int KX_GameObject::pyattr_set_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
Expand Down Expand Up @@ -3395,7 +3388,6 @@ PyObject *KX_GameObject::PyDisableRigidBody()

PyObject *KX_GameObject::PySetParent(PyObject *args)
{
KX_Scene *scene = KX_GetActiveScene();
PyObject *pyobj;
KX_GameObject *obj;
int addToCompound=1, ghost=1;
Expand All @@ -3406,15 +3398,13 @@ PyObject *KX_GameObject::PySetParent(PyObject *args)
if (!ConvertPythonToGameObject(pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
return NULL;
if (obj)
this->SetParent(scene, obj, addToCompound, ghost);
this->SetParent(GetScene(), obj, addToCompound, ghost);
Py_RETURN_NONE;
}

PyObject *KX_GameObject::PyRemoveParent()
{
KX_Scene *scene = KX_GetActiveScene();

this->RemoveParent(scene);
this->RemoveParent(GetScene());
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -3920,15 +3910,14 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage,
"body = Message body (string)"
"to = Name of object to send the message to")
{
KX_Scene *scene = KX_GetActiveScene();
char* subject;
char* body = (char *)"";
char* to = (char *)"";

if (!PyArg_ParseTuple(args, "s|ss:sendMessage", &subject, &body, &to))
return NULL;

scene->GetNetworkMessageScene()->SendMessage(to, this, subject, body);
GetScene()->GetNetworkMessageScene()->SendMessage(to, this, subject, body);
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -4063,7 +4052,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, addDebugProperty,
"addDebugProperty(name, visible=1)\n"
"Added or remove a debug property to the debug list.\n")
{
KX_Scene *scene = KX_GetActiveScene();
KX_Scene *scene = GetScene();
char *name;
int visible = 1;

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_KetsjiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ void KX_KetsjiEngine::UpdateAnimations(KX_Scene *scene)
m_suspendeddelta = scene->getSuspendedDelta();
// Handle the animations independently of the logic time step
if (GetRestrictAnimationFPS()) {
double anim_timestep = 1.0 / KX_GetActiveScene()->GetAnimationFPS();
double anim_timestep = 1.0 / scene->GetAnimationFPS();
if (m_frameTime - m_previousAnimTime > anim_timestep || m_frameTime == m_previousAnimTime) {
// Sanity/debug print to make sure we're actually going at the fps we want (should be close to anim_timestep)
// printf("Anim fps: %f\n", 1.0/(m_frameTime - m_previousAnimTime));
Expand Down
3 changes: 1 addition & 2 deletions source/gameengine/Ketsji/KX_NavMeshObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ void KX_NavMeshObject::ProcessReplica()
std::cout << "Error in " << __func__ << ": unable to build navigation mesh" << std::endl;
return;
}
KX_Scene* scene = KX_GetActiveScene();
KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
KX_ObstacleSimulation* obssimulation = GetScene()->GetObstacleSimulation();
if (obssimulation)
obssimulation->AddObstaclesForNavMesh(this);
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ int KX_Scene::pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *a
KX_Scene* self = static_cast<KX_Scene*>(self_v);
KX_Camera *camOb;

if (!ConvertPythonToCamera(value, &camOb, false, "scene.active_camera = value: KX_Scene"))
if (!ConvertPythonToCamera(self, value, &camOb, false, "scene.active_camera = value: KX_Scene"))
return PY_SET_ATTR_FAIL;

self->SetActiveCamera(camOb);
Expand Down
3 changes: 2 additions & 1 deletion source/gameengine/Ketsji/KX_SceneActuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "KX_Scene.h"
#include "KX_Camera.h"
#include "KX_KetsjiEngine.h"
#include "KX_Globals.h"

/* ------------------------------------------------------------------------- */
/* Native functions */
Expand Down Expand Up @@ -244,7 +245,7 @@ int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_
KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
KX_Camera *camOb;

if (!ConvertPythonToCamera(value, &camOb, true, "actu.camera = value: KX_SceneActuator"))
if (!ConvertPythonToCamera(KX_GetActiveScene(), value, &camOb, true, "actu.camera = value: KX_SceneActuator"))
return PY_SET_ATTR_FAIL;

if (actuator->m_camera)
Expand Down

0 comments on commit 3484d2f

Please sign in to comment.