Revision: 15388 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15388 Author: campbellbarton Date: 2008-06-29 23:52:23 +0200 (Sun, 29 Jun 2008)
Log Message: ----------- BGE python api addition, GameObject get/setState and Controller.getState() Also added a note in the tooltip for action priority when using more then 1 action at a time. Modified Paths: -------------- trunk/blender/source/blender/src/buttons_logic.c trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp trunk/blender/source/gameengine/GameLogic/SCA_PythonController.h trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp trunk/blender/source/gameengine/Ketsji/KX_GameObject.h trunk/blender/source/gameengine/PyDoc/KX_GameObject.py trunk/blender/source/gameengine/PyDoc/SCA_PythonController.py Modified: trunk/blender/source/blender/src/buttons_logic.c =================================================================== --- trunk/blender/source/blender/src/buttons_logic.c 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/blender/src/buttons_logic.c 2008-06-29 21:52:23 UTC (rev 15388) @@ -1703,7 +1703,7 @@ } uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-64, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending"); - uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers"); + uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding clannels must be lower in the stack"); uiDefBut(block, TEX, 0, "FrameProp: ",xco+30, yco-84, width-60, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number"); Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp =================================================================== --- trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp 2008-06-29 21:52:23 UTC (rev 15388) @@ -232,6 +232,7 @@ METH_VARARGS, SCA_PythonController::GetSensor_doc}, {"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_VARARGS}, {"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_VARARGS}, + {"getState", (PyCFunction) SCA_PythonController::sPyGetState, METH_VARARGS}, {NULL,NULL} //Sentinel }; @@ -442,4 +443,12 @@ Py_Return; } +/* 1. getScript */ +PyObject* SCA_PythonController::PyGetState(PyObject* self, + PyObject* args, + PyObject* kwds) +{ + return PyInt_FromLong(m_statemask); +} + /* eof */ Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonController.h =================================================================== --- trunk/blender/source/gameengine/GameLogic/SCA_PythonController.h 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/gameengine/GameLogic/SCA_PythonController.h 2008-06-29 21:52:23 UTC (rev 15388) @@ -81,6 +81,7 @@ KX_PYMETHOD_DOC(SCA_PythonController,GetActuators); KX_PYMETHOD(SCA_PythonController,SetScript); KX_PYMETHOD(SCA_PythonController,GetScript); + KX_PYMETHOD(SCA_PythonController,GetState); }; Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp =================================================================== --- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2008-06-29 21:52:23 UTC (rev 15388) @@ -804,6 +804,8 @@ PyMethodDef KX_GameObject::Methods[] = { {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS}, {"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_VARARGS}, + {"setState",(PyCFunction) KX_GameObject::sPySetState, METH_VARARGS}, + {"getState",(PyCFunction) KX_GameObject::sPyGetState, METH_VARARGS}, {"alignAxisToVect",(PyCFunction) KX_GameObject::sPyAlignAxisToVect, METH_VARARGS}, {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_VARARGS}, {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_VARARGS}, @@ -1117,7 +1119,40 @@ return PyInt_FromLong(m_bVisible); } +PyObject* KX_GameObject::PyGetState(PyObject* self, + PyObject* args, + PyObject* kwds) +{ + int state = 0; + state |= GetState(); + return PyInt_FromLong(state); +} +PyObject* KX_GameObject::PySetState(PyObject* self, + PyObject* args, + PyObject* kwds) +{ + int state_i; + unsigned int state = 0; + + if (PyArg_ParseTuple(args,"i",&state_i)) + { + state |= state_i; + if ((state & ((1<<30)-1)) == 0) { + PyErr_SetString(PyExc_AttributeError, "The state bitfield was not between 0 and 30 (1<<0 and 1<<29)"); + return NULL; + } + SetState(state); + } + else + { + return NULL; + } + Py_Return; +} + + + PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args, PyObject* kwds) Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h =================================================================== --- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2008-06-29 21:52:23 UTC (rev 15388) @@ -720,6 +720,8 @@ KX_PYMETHOD(KX_GameObject,SetOrientation); KX_PYMETHOD(KX_GameObject,GetVisible); KX_PYMETHOD(KX_GameObject,SetVisible); + KX_PYMETHOD(KX_GameObject,GetState); + KX_PYMETHOD(KX_GameObject,SetState); KX_PYMETHOD(KX_GameObject,AlignAxisToVect); KX_PYMETHOD(KX_GameObject,SuspendDynamics); KX_PYMETHOD(KX_GameObject,RestoreDynamics); Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py =================================================================== --- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2008-06-29 21:52:23 UTC (rev 15388) @@ -42,6 +42,20 @@ @type visible: boolean """ + def getState(): + """ + Gets the game object's state bitmask. + + @rtype: int + @return: the objects state. + """ + def setState(): + """ + Sets the game object's visible flag. + The bitmasks for states from 1 to 30 can be set with (1<<0, 1<<1, 1<<2 ... 1<<29) + + @type visible: boolean + """ def setPosition(pos): """ Sets the game object's position. Modified: trunk/blender/source/gameengine/PyDoc/SCA_PythonController.py =================================================================== --- trunk/blender/source/gameengine/PyDoc/SCA_PythonController.py 2008-06-29 21:51:27 UTC (rev 15387) +++ trunk/blender/source/gameengine/PyDoc/SCA_PythonController.py 2008-06-29 21:52:23 UTC (rev 15388) @@ -46,4 +46,12 @@ @type script: string. """ + def getState(): + """ + Get the controllers state bitmask, this can be used with the GameObject's state to test if the the controller is active. + This for instance will always be true however you could compare with a previous state to see when the state was activated. + GameLogic.getCurrentController().getState() & GameLogic.getCurrentController().getOwner().getState() + + @rtype: int + """ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs