synched with trunk at revision 32129
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "GL/glew.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32) && !defined(FREE_WINDOWS)
|
||||
#pragma warning (disable : 4786)
|
||||
#endif //WIN32
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
|
||||
#include "py_capi_utils.h"
|
||||
#include "mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use.
|
||||
#include "geometry.h" // Blender.Geometry module copied here so the blenderlayer can use.
|
||||
#include "bgl.h"
|
||||
@@ -45,6 +46,10 @@ extern "C" {
|
||||
|
||||
#include "marshal.h" /* python header for loading/saving dicts */
|
||||
}
|
||||
|
||||
#define WITH_PYTHON
|
||||
#include "AUD_PyInit.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "KX_PythonInit.h"
|
||||
@@ -120,7 +125,7 @@ extern "C" {
|
||||
#include "KX_BlenderSceneConverter.h"
|
||||
#include "KX_MeshProxy.h" /* for creating a new library of mesh objects */
|
||||
extern "C" {
|
||||
#include "BLO_readfile.h"
|
||||
#include "BKE_idcode.h"
|
||||
}
|
||||
|
||||
#include "NG_NetworkScene.h" //Needed for sendMessage()
|
||||
@@ -271,8 +276,8 @@ static PyObject* gPyRestartGame(PyObject*)
|
||||
}
|
||||
|
||||
static char gPySaveGlobalDict_doc[] =
|
||||
"saveGlobalDict()\n\
|
||||
Saves GameLogic.globalDict to a file";
|
||||
"saveGlobalDict()\n"
|
||||
"Saves bge.logic.globalDict to a file";
|
||||
|
||||
static PyObject* gPySaveGlobalDict(PyObject*)
|
||||
{
|
||||
@@ -308,8 +313,8 @@ static PyObject* gPySaveGlobalDict(PyObject*)
|
||||
}
|
||||
|
||||
static char gPyLoadGlobalDict_doc[] =
|
||||
"LoadGlobalDict()\n\
|
||||
Loads GameLogic.globalDict from a file";
|
||||
"LoadGlobalDict()\n"
|
||||
"Loads bge.logic.globalDict from a file";
|
||||
|
||||
static PyObject* gPyLoadGlobalDict(PyObject*)
|
||||
{
|
||||
@@ -384,15 +389,6 @@ static PyObject* gPyGetSpectrum(PyObject*)
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
|
||||
static PyObject* gPyStopDSP(PyObject*, PyObject* args)
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "no audio device available");
|
||||
return NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* gPySetLogicTicRate(PyObject*, PyObject* args)
|
||||
{
|
||||
float ticrate;
|
||||
@@ -640,13 +636,28 @@ static PyObject *gLibLoad(PyObject*, PyObject* args)
|
||||
KX_Scene *kx_scene= gp_KetsjiScene;
|
||||
char *path;
|
||||
char *group;
|
||||
Py_buffer py_buffer;
|
||||
py_buffer.buf = NULL;
|
||||
char *err_str= NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"ss:LibLoad",&path, &group))
|
||||
if (!PyArg_ParseTuple(args,"ss|y*:LibLoad",&path, &group, &py_buffer))
|
||||
return NULL;
|
||||
|
||||
if(kx_scene->GetSceneConverter()->LinkBlendFile(path, group, kx_scene, &err_str)) {
|
||||
Py_RETURN_TRUE;
|
||||
if (!py_buffer.buf)
|
||||
{
|
||||
if(kx_scene->GetSceneConverter()->LinkBlendFilePath(path, group, kx_scene, &err_str)) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str)) {
|
||||
PyBuffer_Release(&py_buffer);
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
PyBuffer_Release(&py_buffer);
|
||||
}
|
||||
|
||||
if(err_str) {
|
||||
@@ -675,7 +686,7 @@ static PyObject *gLibNew(PyObject*, PyObject* args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idcode= BLO_idcode_from_name(group);
|
||||
idcode= BKE_idcode_from_name(group);
|
||||
if(idcode==0) {
|
||||
PyErr_Format(PyExc_ValueError, "invalid group given \"%s\"", group);
|
||||
return NULL;
|
||||
@@ -761,7 +772,6 @@ static struct PyMethodDef game_methods[] = {
|
||||
{"getRandomFloat",(PyCFunction) gPyGetRandomFloat, METH_NOARGS, (const char *)gPyGetRandomFloat_doc},
|
||||
{"setGravity",(PyCFunction) gPySetGravity, METH_O, (const char *)"set Gravitation"},
|
||||
{"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (const char *)"get audio spectrum"},
|
||||
{"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, (const char *)"stop using the audio dsp (for performance reasons)"},
|
||||
{"getMaxLogicFrame", (PyCFunction) gPyGetMaxLogicFrame, METH_NOARGS, (const char *)"Gets the max number of logic frame per render frame"},
|
||||
{"setMaxLogicFrame", (PyCFunction) gPySetMaxLogicFrame, METH_VARARGS, (const char *)"Sets the max number of logic frame per render frame"},
|
||||
{"getMaxPhysicsFrame", (PyCFunction) gPyGetMaxPhysicsFrame, METH_NOARGS, (const char *)"Gets the max number of physics frame per render frame"},
|
||||
@@ -944,7 +954,6 @@ static PyObject* gPyDisableMist(PyObject*)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyObject* gPySetMistStart(PyObject*, PyObject* args)
|
||||
{
|
||||
|
||||
@@ -1241,7 +1250,7 @@ static struct PyMethodDef rasterizer_methods[] = {
|
||||
// Initialization function for the module (*must* be called initGameLogic)
|
||||
|
||||
static char GameLogic_module_documentation[] =
|
||||
"This is the Python API for the game engine of GameLogic"
|
||||
"This is the Python API for the game engine of bge.logic"
|
||||
;
|
||||
|
||||
static char Rasterizer_module_documentation[] =
|
||||
@@ -1322,7 +1331,6 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
|
||||
KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
|
||||
|
||||
/* 3. Constraint actuator */
|
||||
/* XXX, TODO NXBGE, move constants names from KX_ACT_CONSTRAINT_foo to KX_CONSTRAINTACT_foo */
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
|
||||
@@ -1338,18 +1346,18 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL);
|
||||
KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL);
|
||||
KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH);
|
||||
|
||||
/* 4. Ipo actuator, simple part */
|
||||
KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY, KX_IpoActuator::KX_ACT_IPO_PLAY);
|
||||
@@ -1602,7 +1610,7 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
|
||||
// Check for errors
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
Py_FatalError("can't initialize module GameLogic");
|
||||
Py_FatalError("can't initialize module bge.logic");
|
||||
}
|
||||
|
||||
return m;
|
||||
@@ -1933,7 +1941,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur
|
||||
|
||||
PyObjectPlus::ClearDeprecationWarning();
|
||||
|
||||
return bpy_namespace_dict_new(NULL);
|
||||
return PyC_DefaultNameSpace(NULL);
|
||||
}
|
||||
|
||||
void exitGamePlayerPythonScripting()
|
||||
@@ -1969,7 +1977,7 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev
|
||||
|
||||
PyObjectPlus::NullDeprecationWarning();
|
||||
|
||||
return bpy_namespace_dict_new(NULL);
|
||||
return PyC_DefaultNameSpace(NULL);
|
||||
}
|
||||
|
||||
void exitGamePythonScripting()
|
||||
@@ -1999,7 +2007,6 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main *
|
||||
PyDict_SetItemString(PyModule_GetDict(*gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
|
||||
|
||||
*gameLogic_keys = PyDict_Keys(PyModule_GetDict(*gameLogic));
|
||||
PyDict_SetItemString(dictionaryobject, "GameLogic", *gameLogic); // Same as importing the module.
|
||||
|
||||
initGameKeys();
|
||||
initPythonConstraintBinding();
|
||||
@@ -2007,10 +2014,11 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main *
|
||||
initGeometry();
|
||||
initBGL();
|
||||
initBLF();
|
||||
AUD_initPython();
|
||||
initVideoTexture();
|
||||
|
||||
/* could be done a lot more nicely, but for now a quick way to get bge.* working */
|
||||
PyRun_SimpleString("__import__('sys').modules['bge']=[mod for mod in (type(__builtins__)('bge'), ) if mod.__dict__.update({'logic':__import__('GameLogic'), 'render':__import__('Rasterizer'), 'events':__import__('GameKeys'), 'constraints':__import__('PhysicsConstraints'), 'types':__import__('GameTypes')}) is None][0]");
|
||||
PyRun_SimpleString("sys = __import__('sys');mod = sys.modules['bge'] = type(sys)('bge');mod.__dict__.update({'logic':__import__('GameLogic'), 'render':__import__('Rasterizer'), 'events':__import__('GameKeys'), 'constraints':__import__('PhysicsConstraints'), 'types':__import__('GameTypes'), 'texture':__import__('VideoTexture')});");
|
||||
}
|
||||
|
||||
static struct PyModuleDef Rasterizer_module_def = {
|
||||
@@ -2358,15 +2366,15 @@ int saveGamePythonConfig( char **marshal_buffer)
|
||||
memcpy(*marshal_buffer, marshal_cstring, marshal_length);
|
||||
Py_DECREF(pyGlobalDictMarshal);
|
||||
} else {
|
||||
printf("Error, GameLogic.globalDict could not be marshal'd\n");
|
||||
printf("Error, bge.logic.globalDict could not be marshal'd\n");
|
||||
}
|
||||
} else {
|
||||
printf("Error, GameLogic.globalDict was removed\n");
|
||||
printf("Error, bge.logic.globalDict was removed\n");
|
||||
}
|
||||
Py_DECREF(gameLogic);
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n");
|
||||
printf("Error, bge.logic failed to import bge.logic.globalDict will be lost\n");
|
||||
}
|
||||
return marshal_length;
|
||||
}
|
||||
@@ -2398,7 +2406,7 @@ int loadGamePythonConfig(char *marshal_buffer, int marshal_length)
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n");
|
||||
printf("Error, bge.logic failed to import bge.logic.globalDict will be lost\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user