diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 17:41:00 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:18:11 +0300 |
commit | d140e70c496122915eb5c05aba83153e2e0d7998 (patch) | |
tree | 1e589247d69da64aa7b0e7802319237ec050b5d6 /source/gameengine/Ketsji/KX_PythonInit.cpp | |
parent | 147bd16ed1bb3415b30408b0eab110d0854eadd2 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-experimentstemp-ghash-experiments
Note that 'store hash' feature was removed for now - to complex to maintain (conflicts)
and relatively easy to re-add if we ever really want this one day.
Conflicts:
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/hash_mm2a.c
source/blender/bmesh/tools/bmesh_region_match.c
tests/gtests/blenlib/BLI_ghash_performance_test.cc
tests/gtests/blenlib/BLI_ghash_test.cc
tests/gtests/blenlib/CMakeLists.txt
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 245 |
1 files changed, 133 insertions, 112 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index d7dd3fe5253..a5fb2dede72 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -51,6 +51,8 @@ # include <Python.h> extern "C" { + # include "BLI_utildefines.h" + # include "python_utildefines.h" # 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" // 'mathutils' module copied here so the blenderlayer can use. @@ -136,6 +138,7 @@ extern "C" { #include "BKE_global.h" #include "BKE_library.h" #include "BKE_appdir.h" +#include "BKE_blender.h" #include "BLI_blenlib.h" #include "GPU_material.h" #include "MEM_guardedalloc.h" @@ -354,7 +357,7 @@ static PyObject *gPyLoadGlobalDict(PyObject *) { char marshal_path[512]; char *marshal_buffer = NULL; - size_t marshal_length; + int marshal_length; FILE *fp = NULL; int result; @@ -365,7 +368,12 @@ static PyObject *gPyLoadGlobalDict(PyObject *) if (fp) { // obtain file size: fseek (fp, 0, SEEK_END); - marshal_length = (size_t)ftell(fp); + marshal_length = ftell(fp); + if (marshal_length == -1) { + printf("Warning: could not read position of '%s'\n", marshal_path); + fclose(fp); + Py_RETURN_NONE; + } rewind(fp); marshal_buffer = (char*)malloc (sizeof(char)*marshal_length); @@ -1029,109 +1037,22 @@ static PyObject *gPyGetStereoEye(PyObject *, PyObject *, PyObject *) static PyObject *gPySetBackgroundColor(PyObject *, PyObject *value) { - MT_Vector4 vec; if (!PyVecTo(value, vec)) return NULL; - - if (gp_Canvas) - { - gp_Rasterizer->SetBackColor((float)vec[0], (float)vec[1], (float)vec[2], (float)vec[3]); - } KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo(); - if (wi->hasWorld()) - wi->setBackColor((float)vec[0], (float)vec[1], (float)vec[2]); - - Py_RETURN_NONE; -} - - - -static PyObject *gPySetMistColor(PyObject *, PyObject *value) -{ - - MT_Vector3 vec; - if (!PyVecTo(value, vec)) - return NULL; - - if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistColor(color), Rasterizer not available"); + if (!wi->hasWorld()) { + PyErr_SetString(PyExc_RuntimeError, "bge.render.SetBackgroundColor(color), World not available"); return NULL; } - gp_Rasterizer->SetFogColor((float)vec[0], (float)vec[1], (float)vec[2]); - - Py_RETURN_NONE; -} -static PyObject *gPyDisableMist(PyObject *) -{ - - if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistColor(color), Rasterizer not available"); - return NULL; - } - gp_Rasterizer->DisableFog(); - - Py_RETURN_NONE; -} + ShowDeprecationWarning("setBackgroundColor()", "KX_WorldInfo.background_color"); + wi->setBackColor((float)vec[0], (float)vec[1], (float)vec[2]); -static PyObject *gPySetMistStart(PyObject *, PyObject *args) -{ - - float miststart; - if (!PyArg_ParseTuple(args,"f:setMistStart",&miststart)) - return NULL; - - if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistStart(float), Rasterizer not available"); - return NULL; - } - - gp_Rasterizer->SetFogStart(miststart); - - Py_RETURN_NONE; -} - - - -static PyObject *gPySetMistEnd(PyObject *, PyObject *args) -{ - - float mistend; - if (!PyArg_ParseTuple(args,"f:setMistEnd",&mistend)) - return NULL; - - if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistEnd(float), Rasterizer not available"); - return NULL; - } - - gp_Rasterizer->SetFogEnd(mistend); - - Py_RETURN_NONE; -} - - -static PyObject *gPySetAmbientColor(PyObject *, PyObject *value) -{ - - MT_Vector3 vec; - if (!PyVecTo(value, vec)) - return NULL; - - if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setAmbientColor(color), Rasterizer not available"); - return NULL; - } - gp_Rasterizer->SetAmbientColor((float)vec[0], (float)vec[1], (float)vec[2]); - Py_RETURN_NONE; } - - - static PyObject *gPyMakeScreenshot(PyObject *, PyObject *args) { char* filename; @@ -1490,6 +1411,21 @@ static PyObject *gPyClearDebugList(PyObject *) Py_RETURN_NONE; } +static PyObject *gPyGetDisplayDimensions(PyObject *) +{ + PyObject *result; + int width, height; + + gp_Canvas->GetDisplayDimensions(width, height); + + result = PyTuple_New(2); + PyTuple_SET_ITEMS(result, + PyLong_FromLong(width), + PyLong_FromLong(height)); + + return result; +} + PyDoc_STRVAR(Rasterizer_module_documentation, "This is the Python API for the game engine of Rasterizer" ); @@ -1508,11 +1444,6 @@ static struct PyMethodDef rasterizer_methods[] = { {"setMousePosition",(PyCFunction) gPySetMousePosition, METH_VARARGS, "setMousePosition(int x,int y)"}, {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_O,"set Background Color (rgb)"}, - {"setAmbientColor",(PyCFunction)gPySetAmbientColor,METH_O,"set Ambient Color (rgb)"}, - {"disableMist",(PyCFunction)gPyDisableMist,METH_NOARGS,"turn off mist"}, - {"setMistColor",(PyCFunction)gPySetMistColor,METH_O,"set Mist Color (rgb)"}, - {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start(rgb)"}, - {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End(rgb)"}, {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"}, {"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_NOARGS,"disable motion blur"}, @@ -1538,6 +1469,8 @@ static struct PyMethodDef rasterizer_methods[] = { {"setWindowSize", (PyCFunction) gPySetWindowSize, METH_VARARGS, ""}, {"setFullScreen", (PyCFunction) gPySetFullScreen, METH_O, ""}, {"getFullScreen", (PyCFunction) gPyGetFullScreen, METH_NOARGS, ""}, + {"getDisplayDimensions", (PyCFunction) gPyGetDisplayDimensions, METH_NOARGS, + "Get the actual dimensions, in pixels, of the physical display (e.g., the monitor)."}, {"setMipmapping", (PyCFunction) gPySetMipmapping, METH_VARARGS, ""}, {"getMipmapping", (PyCFunction) gPyGetMipmapping, METH_NOARGS, ""}, {"setVsync", (PyCFunction) gPySetVsync, METH_VARARGS, ""}, @@ -2088,33 +2021,50 @@ PyMODINIT_FUNC initBGE(void) PyObject *mod; PyObject *submodule; PyObject *sys_modules = PyThreadState_GET()->interp->modules; + const char *mod_full; mod = PyModule_Create(&BGE_module_def); - PyModule_AddObject(mod, "constraints", (submodule = initConstraintPythonBinding())); - PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + /* skip "bge." */ +#define SUBMOD (mod_full + 4) + + mod_full = "bge.app"; + PyModule_AddObject(mod, SUBMOD, (submodule = initApplicationPythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); + Py_INCREF(submodule); + + mod_full = "bge.constraints"; + PyModule_AddObject(mod, SUBMOD, (submodule = initConstraintPythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); Py_INCREF(submodule); - PyModule_AddObject(mod, "events", (submodule = initGameKeysPythonBinding())); - PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + mod_full = "bge.events"; + PyModule_AddObject(mod, SUBMOD, (submodule = initGameKeysPythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); Py_INCREF(submodule); - PyModule_AddObject(mod, "logic", (submodule = initGameLogicPythonBinding())); - PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + mod_full = "bge.logic"; + PyModule_AddObject(mod, SUBMOD, (submodule = initGameLogicPythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); Py_INCREF(submodule); - PyModule_AddObject(mod, "render", (submodule = initRasterizerPythonBinding())); - PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + mod_full = "bge.render"; + PyModule_AddObject(mod, SUBMOD, (submodule = initRasterizerPythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); Py_INCREF(submodule); - PyModule_AddObject(mod, "texture", (submodule = initVideoTexturePythonBinding())); - PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + mod_full = "bge.texture"; + PyModule_AddObject(mod, SUBMOD, (submodule = initVideoTexturePythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); Py_INCREF(submodule); - PyModule_AddObject(mod, "types", (submodule = initGameTypesPythonBinding())); - PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + mod_full = "bge.types"; + PyModule_AddObject(mod, SUBMOD, (submodule = initGameTypesPythonBinding())); + PyDict_SetItemString(sys_modules, mod_full, submodule); Py_INCREF(submodule); +#undef SUBMOD + return mod; } @@ -2149,14 +2099,14 @@ PyObject *initGamePlayerPythonScripting(Main *maggie, int argc, char** argv) Py_SetProgramName(program_path_wchar); /* Update, Py3.3 resolves attempting to parse non-existing header */ - #if 0 +#if 0 /* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to * parse from the 'sysconfig' module which is used by 'site', * so for now disable site. alternatively we could copy the file. */ if (py_path_bundle != NULL) { Py_NoSiteFlag = 1; /* inhibits the automatic importing of 'site' */ } - #endif +#endif Py_FrozenFlag = 1; @@ -2606,6 +2556,77 @@ PyMODINIT_FUNC initGameKeysPythonBinding() return m; } + + +/* ------------------------------------------------------------------------- */ +/* Application: application values that remain unchanged during runtime */ +/* ------------------------------------------------------------------------- */ + +PyDoc_STRVAR(Application_module_documentation, + "This module contains application values that remain unchanged during runtime." + ); + +static struct PyModuleDef Application_module_def = { + PyModuleDef_HEAD_INIT, + "bge.app", /* m_name */ + Application_module_documentation, /* m_doc */ + 0, /* m_size */ + NULL, /* m_methods */ + 0, /* m_reload */ + 0, /* m_traverse */ + 0, /* m_clear */ + 0, /* m_free */ +}; + +PyMODINIT_FUNC initApplicationPythonBinding() +{ + PyObject *m; + PyObject *d; + + m = PyModule_Create(&Application_module_def); + + // Add some symbolic constants to the module + d = PyModule_GetDict(m); + + PyDict_SetItemString(d, "version", Py_BuildValue("(iii)", + BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION)); + PyDict_SetItemString(d, "version_string", PyUnicode_FromFormat("%d.%02d (sub %d)", + BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION)); + PyDict_SetItemString(d, "version_char", PyUnicode_FromString( + STRINGIFY(BLENDER_VERSION_CHAR))); + + PyDict_SetItemString(d, "has_texture_ffmpeg", +#ifdef WITH_FFMPEG + Py_True +#else + Py_False +#endif + ); + PyDict_SetItemString(d, "has_joystick", +#ifdef WITH_SDL + Py_True +#else + Py_False +#endif + ); + PyDict_SetItemString(d, "has_physics", +#ifdef WITH_BULLET + Py_True +#else + Py_False +#endif + ); + + // Check for errors + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + + return m; +} + + // utility function for loading and saving the globalDict int saveGamePythonConfig( char **marshal_buffer) { |