[Bf-committers] GameEngine GetGameObject() Patch

maci_ray bf-committers@blender.org
Wed, 3 Sep 2003 14:29:36 +0200 (CEST)


--0-2009874974-1062592176=:58988
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Content-Id: 
Content-Disposition: inline

Hi Blenders,

attached a little patch, which enables a method GetGameObject()
in GameLogic module. It has the same functionality as the Object.Get()
Method from ExpPython.

Please check and commit if you like it.

Maci_Ray.


__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Logos und Klingeltöne fürs Handy bei http://sms.yahoo.de
--0-2009874974-1062592176=:58988
Content-Type: text/plain; name="KX_PythonInit.cpp.diff"
Content-Description: KX_PythonInit.cpp.diff
Content-Disposition: inline; filename="KX_PythonInit.cpp.diff"

Index: KX_PythonInit.cpp
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/gameengine/Ketsji/KX_PythonInit.cpp,v
retrieving revision 1.3
diff -r1.3 KX_PythonInit.cpp
46a47
> #include "KX_GameObject.h"
225a227,279
> // Inspired by http://www.elysiun.com/forum/viewtopic.php?t=3245 and
> // my own needs.
> // Based on EXPython Object.c/M_Object_Get() by Michel Selten.
> 
> static PyObject *gPyGetGameObject(PyObject *self, PyObject *args)
> {
> 	CListValue *kx_list = gp_KetsjiScene->GetObjectList();
>     char       *name = NULL;
> 
>     PyArg_ParseTuple(args, "|s", &name);
> 
>     if(name != NULL)
> 	{	// prepend with OB for internal identifier
> 		STR_String exp_name = "OB";
> 		exp_name += name;
> 
> 		KX_GameObject *game_object = 
> 			(KX_GameObject *)kx_list->FindValue(exp_name);
> 
>         if(game_object == NULL)
>         {	// No object exists with the name specified in the argument name.
>             return NULL;
>         }
> 		return game_object->AddRef();
>     }
>     else
>     {   // No argument has been given. Return a list of all objects.
>         PyObject *py_list;
>         py_list = PyList_New(kx_list->GetCount() );
> 
>         if(py_list == NULL)
>         {	return NULL;
>         }
> 
> 		// iterate through all KX_GameObjects and set list elements
> 		// (maybe a copy list would work also?)
> 		for(int index = 0; index < kx_list->GetCount(); ++index)
> 		{
> 			KX_GameObject *game_object = 
> 				(KX_GameObject *)kx_list->GetValue(index);
> 
>             PyList_SetItem(py_list, index, game_object->AddRef() );
> 		}
> 		return py_list;
>     }
> }
> 
> 
> 
> static char gPyGetGameObject_doc[] =
> "(name) - return the object with the name 'name', returns None if not found.\n\
> If 'name' is not specified, it returns a list of all gameobjects in the\n\
> current scene.";
231c285
< 	{"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator,
---
> 	{"addActiveActuator",(PyCFunction)SCA_PythonController::sPyAddActiveActuator,
235,237c289,292
< 	{"setGravity",(PyCFunction) gPySetGravity, METH_VARARGS,"set Gravitation"},
< 	{"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_VARARGS,"get audio spectrum"},
< 	{"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS,"stop using the audio dsp (for performance reasons)"},
---
> 	{"setGravity",(PyCFunction) gPySetGravity, METH_VARARGS, "set Gravitation"},
> 	{"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_VARARGS, "get audio spectrum"},
> 	{"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, "stop using the audio dsp (for performance reasons)"},
> 	{"GetGameObject",(PyCFunction) gPyGetGameObject, METH_VARARGS, gPyGetGameObject_doc},

--0-2009874974-1062592176=:58988--