BGE: python API cleanup - using PyDoc_STRVAR instead of static char*

This commit is contained in:
2014-06-06 07:43:23 +01:00
parent 8060887089
commit d503f8a621
3 changed files with 152 additions and 99 deletions

View File

@@ -56,38 +56,75 @@
// if there is a better way (without global), please do so! // if there is a better way (without global), please do so!
static PHY_IPhysicsEnvironment* g_CurrentActivePhysicsEnvironment = NULL; static PHY_IPhysicsEnvironment* g_CurrentActivePhysicsEnvironment = NULL;
static char PhysicsConstraints_module_documentation[] =
"This is the Python API for the Physics Constraints";
PyDoc_STRVAR(PhysicsConstraints_module_documentation,
"This is the Python API for the Physics Constraints"
);
static char gPySetGravity__doc__[] = "setGravity(float x,float y,float z)"; PyDoc_STRVAR(gPySetGravity__doc__,
static char gPySetDebugMode__doc__[] = "setDebugMode(int mode)"; "setGravity(float x,float y,float z)\n"
"");
PyDoc_STRVAR(gPySetDebugMode__doc__,
"setDebugMode(int mode)\n"
"");
static char gPySetNumIterations__doc__[] = "setNumIterations(int numiter) This sets the number of iterations for an iterative constraint solver"; PyDoc_STRVAR(gPySetNumIterations__doc__,
static char gPySetNumTimeSubSteps__doc__[] = "setNumTimeSubSteps(int numsubstep) This sets the number of substeps for each physics proceed. Tradeoff quality for performance."; "setNumIterations(int numiter)\n"
"This sets the number of iterations for an iterative constraint solver");
PyDoc_STRVAR(gPySetNumTimeSubSteps__doc__,
"setNumTimeSubSteps(int numsubstep)\n"
"This sets the number of substeps for each physics proceed. Tradeoff quality for performance.");
PyDoc_STRVAR(gPySetDeactivationTime__doc__,
"setDeactivationTime(float time)\n"
"This sets the time after which a resting rigidbody gets deactived");
PyDoc_STRVAR(gPySetDeactivationLinearTreshold__doc__,
"setDeactivationLinearTreshold(float linearTreshold)\n"
"");
PyDoc_STRVAR(gPySetDeactivationAngularTreshold__doc__,
"setDeactivationAngularTreshold(float angularTreshold)\n"
"");
PyDoc_STRVAR(gPySetContactBreakingTreshold__doc__,
"setContactBreakingTreshold(float breakingTreshold)\n"
"Reasonable default is 0.02 (if units are meters)");
static char gPySetDeactivationTime__doc__[] = "setDeactivationTime(float time) This sets the time after which a resting rigidbody gets deactived"; PyDoc_STRVAR(gPySetCcdMode__doc__,
static char gPySetDeactivationLinearTreshold__doc__[] = "setDeactivationLinearTreshold(float linearTreshold)"; "setCcdMode(int ccdMode)\n"
static char gPySetDeactivationAngularTreshold__doc__[] = "setDeactivationAngularTreshold(float angularTreshold)"; "Very experimental, not recommended");
static char gPySetContactBreakingTreshold__doc__[] = "setContactBreakingTreshold(float breakingTreshold) Reasonable default is 0.02 (if units are meters)"; PyDoc_STRVAR(gPySetSorConstant__doc__,
"setSorConstant(float sor)\n"
static char gPySetCcdMode__doc__[] = "setCcdMode(int ccdMode) Very experimental, not recommended"; "Very experimental, not recommended");
static char gPySetSorConstant__doc__[] = "setSorConstant(float sor) Very experimental, not recommended"; PyDoc_STRVAR(gPySetSolverTau__doc__,
static char gPySetSolverTau__doc__[] = "setTau(float tau) Very experimental, not recommended"; "setTau(float tau)\n"
static char gPySetSolverDamping__doc__[] = "setDamping(float damping) Very experimental, not recommended"; "Very experimental, not recommended");
static char gPySetLinearAirDamping__doc__[] = "setLinearAirDamping(float damping) Very experimental, not recommended"; PyDoc_STRVAR(gPySetSolverDamping__doc__,
static char gPySetUseEpa__doc__[] = "setUseEpa(int epa) Very experimental, not recommended"; "setDamping(float damping)\n"
static char gPySetSolverType__doc__[] = "setSolverType(int solverType) Very experimental, not recommended"; "Very experimental, not recommended");
PyDoc_STRVAR(gPySetLinearAirDamping__doc__,
"setLinearAirDamping(float damping)\n"
static char gPyCreateConstraint__doc__[] = "createConstraint(ob1,ob2,float restLength,float restitution,float damping)"; "Very experimental, not recommended");
static char gPyGetVehicleConstraint__doc__[] = "getVehicleConstraint(int constraintId)"; PyDoc_STRVAR(gPySetUseEpa__doc__,
static char gPyGetCharacter__doc__[] = "getCharacter(KX_GameObject obj)"; "setUseEpa(int epa)\n"
static char gPyRemoveConstraint__doc__[] = "removeConstraint(int constraintId)"; "Very experimental, not recommended");
static char gPyGetAppliedImpulse__doc__[] = "getAppliedImpulse(int constraintId)"; PyDoc_STRVAR(gPySetSolverType__doc__,
"setSolverType(int solverType)\n"
"Very experimental, not recommended");
PyDoc_STRVAR(gPyCreateConstraint__doc__,
"createConstraint(ob1,ob2,float restLength,float restitution,float damping)\n"
"");
PyDoc_STRVAR(gPyGetVehicleConstraint__doc__,
"getVehicleConstraint(int constraintId)\n"
"");
PyDoc_STRVAR(gPyGetCharacter__doc__,
"getCharacter(KX_GameObject obj)\n"
"");
PyDoc_STRVAR(gPyRemoveConstraint__doc__,
"removeConstraint(int constraintId)\n"
"");
PyDoc_STRVAR(gPyGetAppliedImpulse__doc__,
"getAppliedImpulse(int constraintId)\n"
"");

View File

@@ -208,8 +208,11 @@ static PyObject *gp_OrigPythonSysModules= NULL;
// List of methods defined in the module // List of methods defined in the module
static PyObject *ErrorObject; static PyObject *ErrorObject;
static const char *gPyGetRandomFloat_doc="getRandomFloat returns a random floating point value in the range [0..1]";
PyDoc_STRVAR(gPyGetRandomFloat_doc,
"getRandomFloat()\n"
"returns a random floating point value in the range [0..1]"
);
static PyObject *gPyGetRandomFloat(PyObject *) static PyObject *gPyGetRandomFloat(PyObject *)
{ {
return PyFloat_FromDouble(MT_random()); return PyFloat_FromDouble(MT_random());
@@ -227,15 +230,15 @@ static PyObject *gPySetGravity(PyObject *, PyObject *value)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static char gPyExpandPath_doc[] = PyDoc_STRVAR(gPyExpandPath_doc,
"(path) - Converts a blender internal path into a proper file system path.\n\ "expandPath(path)\n"
path - the string path to convert.\n\n\ "Converts a blender internal path into a proper file system path.\n"
Use / as directory separator in path\n\ " path - the string path to convert.\n"
You can use '//' at the start of the string to define a relative path;\n\ "Use / as directory separator in path\n"
Blender replaces that string by the directory of the current .blend or runtime\n\ "You can use '//' at the start of the string to define a relative path."
file to make a full path name.\n\ "Blender replaces that string by the directory of the current .blend or runtime file to make a full path name.\n"
The function also converts the directory separator to the local file system format."; "The function also converts the directory separator to the local file system format."
);
static PyObject *gPyExpandPath(PyObject *, PyObject *args) static PyObject *gPyExpandPath(PyObject *, PyObject *args)
{ {
char expanded[FILE_MAX]; char expanded[FILE_MAX];
@@ -249,10 +252,10 @@ static PyObject *gPyExpandPath(PyObject *, PyObject *args)
return PyUnicode_DecodeFSDefault(expanded); return PyUnicode_DecodeFSDefault(expanded);
} }
static char gPyStartGame_doc[] = PyDoc_STRVAR(gPyStartGame_doc,
"startGame(blend)\n\ "startGame(blend)\n"
Loads the blend file"; "Loads the blend file"
);
static PyObject *gPyStartGame(PyObject *, PyObject *args) static PyObject *gPyStartGame(PyObject *, PyObject *args)
{ {
char* blendfile; char* blendfile;
@@ -266,10 +269,10 @@ static PyObject *gPyStartGame(PyObject *, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static char gPyEndGame_doc[] = PyDoc_STRVAR(gPyEndGame_doc,
"endGame()\n\ "endGame()\n"
Ends the current game"; "Ends the current game"
);
static PyObject *gPyEndGame(PyObject *) static PyObject *gPyEndGame(PyObject *)
{ {
gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME); gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
@@ -279,10 +282,10 @@ static PyObject *gPyEndGame(PyObject *)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static char gPyRestartGame_doc[] = PyDoc_STRVAR(gPyRestartGame_doc,
"restartGame()\n\ "restartGame()\n"
Restarts the current game by reloading the .blend file"; "Restarts the current game by reloading the .blend file"
);
static PyObject *gPyRestartGame(PyObject *) static PyObject *gPyRestartGame(PyObject *)
{ {
gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME); gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME);
@@ -291,10 +294,10 @@ static PyObject *gPyRestartGame(PyObject *)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static char gPySaveGlobalDict_doc[] = PyDoc_STRVAR(gPySaveGlobalDict_doc,
"saveGlobalDict()\n" "saveGlobalDict()\n"
"Saves bge.logic.globalDict to a file"; "Saves bge.logic.globalDict to a file"
);
static PyObject *gPySaveGlobalDict(PyObject *) static PyObject *gPySaveGlobalDict(PyObject *)
{ {
char marshal_path[512]; char marshal_path[512];
@@ -328,10 +331,10 @@ static PyObject *gPySaveGlobalDict(PyObject *)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static char gPyLoadGlobalDict_doc[] = PyDoc_STRVAR(gPyLoadGlobalDict_doc,
"LoadGlobalDict()\n" "LoadGlobalDict()\n"
"Loads bge.logic.globalDict from a file"; "Loads bge.logic.globalDict from a file"
);
static PyObject *gPyLoadGlobalDict(PyObject *) static PyObject *gPyLoadGlobalDict(PyObject *)
{ {
char marshal_path[512]; char marshal_path[512];
@@ -369,23 +372,23 @@ static PyObject *gPyLoadGlobalDict(PyObject *)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static char gPyGetProfileInfo_doc[] = PyDoc_STRVAR(gPyGetProfileInfo_doc,
"getProfileInfo()\n" "getProfileInfo()\n"
"returns a dictionary with profiling information"; "returns a dictionary with profiling information"
);
static PyObject *gPyGetProfileInfo(PyObject *) static PyObject *gPyGetProfileInfo(PyObject *)
{ {
return gp_KetsjiEngine->GetPyProfileDict(); return gp_KetsjiEngine->GetPyProfileDict();
} }
static char gPySendMessage_doc[] = PyDoc_STRVAR(gPySendMessage_doc,
"sendMessage(subject, [body, to, from])\n\ "sendMessage(subject, [body, to, from])\n"
sends a message in same manner as a message actuator\ "sends a message in same manner as a message actuator"
subject = Subject of the message\ " subject = Subject of the message"
body = Message body\ " body = Message body"
to = Name of object to send the message to\ " to = Name of object to send the message to"
from = Name of object to send the string from"; " from = Name of object to send the string from"
);
static PyObject *gPySendMessage(PyObject *, PyObject *args) static PyObject *gPySendMessage(PyObject *, PyObject *args)
{ {
char* subject; char* subject;
@@ -545,11 +548,12 @@ static PyObject *gPyGetBlendFileList(PyObject *, PyObject *args)
return list; return list;
} }
static char gPyAddScene_doc[] = PyDoc_STRVAR(gPyAddScene_doc,
"addScene(name, [overlay])\n\ "addScene(name, [overlay])\n"
adds a scene to the game engine\n\ "Adds a scene to the game engine.\n"
name = Name of the scene\n\ " name = Name of the scene\n"
overlay = Overlay or underlay"; " overlay = Overlay or underlay"
);
static PyObject *gPyAddScene(PyObject *, PyObject *args) static PyObject *gPyAddScene(PyObject *, PyObject *args)
{ {
char* name; char* name;
@@ -563,17 +567,19 @@ static PyObject *gPyAddScene(PyObject *, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static const char *gPyGetCurrentScene_doc = PyDoc_STRVAR(gPyGetCurrentScene_doc,
"getCurrentScene()\n" "getCurrentScene()\n"
"Gets a reference to the current scene.\n"; "Gets a reference to the current scene."
);
static PyObject *gPyGetCurrentScene(PyObject *self) static PyObject *gPyGetCurrentScene(PyObject *self)
{ {
return gp_KetsjiScene->GetProxy(); return gp_KetsjiScene->GetProxy();
} }
static const char *gPyGetSceneList_doc = PyDoc_STRVAR(gPyGetSceneList_doc,
"getSceneList()\n" "getSceneList()\n"
"Return a list of converted scenes.\n"; "Return a list of converted scenes."
);
static PyObject *gPyGetSceneList(PyObject *self) static PyObject *gPyGetSceneList(PyObject *self)
{ {
KX_KetsjiEngine* m_engine = KX_GetActiveEngine(); KX_KetsjiEngine* m_engine = KX_GetActiveEngine();
@@ -1388,6 +1394,11 @@ static PyObject *gPyGetVsync(PyObject *)
return PyLong_FromLong(gp_Canvas->GetSwapInterval()); return PyLong_FromLong(gp_Canvas->GetSwapInterval());
} }
PyDoc_STRVAR(Rasterizer_module_documentation,
"This is the Python API for the game engine of Rasterizer"
);
static struct PyMethodDef rasterizer_methods[] = { static struct PyMethodDef rasterizer_methods[] = {
{"getWindowWidth",(PyCFunction) gPyGetWindowWidth, {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
METH_VARARGS, "getWindowWidth doc"}, METH_VARARGS, "getWindowWidth doc"},
@@ -1438,15 +1449,11 @@ static struct PyMethodDef rasterizer_methods[] = {
{ NULL, (PyCFunction) NULL, 0, NULL } { NULL, (PyCFunction) NULL, 0, NULL }
}; };
// Initialization function for the module (*must* be called initGameLogic)
static char GameLogic_module_documentation[] =
"This is the Python API for the game engine of bge.logic"
;
static char Rasterizer_module_documentation[] = PyDoc_STRVAR(GameLogic_module_documentation,
"This is the Python API for the game engine of Rasterizer" "This is the Python API for the game engine of bge.logic"
; );
static struct PyModuleDef GameLogic_module_def = { static struct PyModuleDef GameLogic_module_def = {
{}, /* m_base */ {}, /* m_base */
@@ -1982,7 +1989,7 @@ PyObject *initGamePlayerPythonScripting(Main *maggie, int argc, char** argv)
* parse from the 'sysconfig' module which is used by 'site', * parse from the 'sysconfig' module which is used by 'site',
* so for now disable site. alternatively we could copy the file. */ * so for now disable site. alternatively we could copy the file. */
if (py_path_bundle != NULL) { if (py_path_bundle != NULL) {
Py_NoSiteFlag = 1; Py_NoSiteFlag = 1; /* inhibits the automatic importing of 'site' */
} }
#endif #endif
@@ -2181,6 +2188,7 @@ PyObject *initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
{ {
gp_Canvas = canvas; gp_Canvas = canvas;
gp_Rasterizer = rasty; gp_Rasterizer = rasty;
PyObject *m; PyObject *m;
PyObject *d; PyObject *d;
PyObject *item; PyObject *item;
@@ -2236,13 +2244,14 @@ PyObject *initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
/* GameKeys: symbolic constants for key mapping */ /* GameKeys: symbolic constants for key mapping */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static char GameKeys_module_documentation[] = PyDoc_STRVAR(GameKeys_module_documentation,
"This modules provides defines for key-codes" "This modules provides defines for key-codes"
; );
static char gPyEventToString_doc[] = PyDoc_STRVAR(gPyEventToString_doc,
"EventToString(event) - Take a valid event from the GameKeys module or Keyboard Sensor and return a name" "EventToString(event)\n"
; "Take a valid event from the GameKeys module or Keyboard Sensor and return a name"
);
static PyObject *gPyEventToString(PyObject *, PyObject *value) static PyObject *gPyEventToString(PyObject *, PyObject *value)
{ {
@@ -2270,9 +2279,11 @@ static PyObject *gPyEventToString(PyObject *, PyObject *value)
return ret; return ret;
} }
static char gPyEventToCharacter_doc[] =
"EventToCharacter(event, is_shift) - Take a valid event from the GameKeys module or Keyboard Sensor and return a character" PyDoc_STRVAR(gPyEventToCharacter_doc,
; "EventToCharacter(event, is_shift)\n"
"Take a valid event from the GameKeys module or Keyboard Sensor and return a character"
);
static PyObject *gPyEventToCharacter(PyObject *, PyObject *args) static PyObject *gPyEventToCharacter(PyObject *, PyObject *args)
{ {

View File

@@ -157,10 +157,15 @@ static void registerAllTypes(void)
pyFilterTypes.add(&FilterBGR24Type, "FilterBGR24"); pyFilterTypes.add(&FilterBGR24Type, "FilterBGR24");
} }
PyDoc_STRVAR(VideoTexture_module_documentation,
"\n"
"Module that allows to play video files on textures in GameBlender."
);
static struct PyModuleDef VideoTexture_module_def = { static struct PyModuleDef VideoTexture_module_def = {
{}, /* m_base */ {}, /* m_base */
"VideoTexture", /* m_name */ "VideoTexture", /* m_name */
"Module that allows to play video files on textures in GameBlender.", /* m_doc */ VideoTexture_module_documentation, /* m_doc */
0, /* m_size */ 0, /* m_size */
moduleMethods, /* m_methods */ moduleMethods, /* m_methods */
0, /* m_reload */ 0, /* m_reload */