diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2012-12-22 09:38:32 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2012-12-22 09:38:32 +0400 |
commit | 84966c3d0ae2d39fa4e691ed0131d8b94f8785e4 (patch) | |
tree | 96f1fbaac1e4b2f151c7726c90b8491a718666c1 /source/gameengine/Ketsji/KX_PythonInit.cpp | |
parent | 8062bcd16f9e91d76dbd074f32b889ce2e0cba84 (diff) |
BGE: Committing async LibLoad from Swiss. This does the lib loading in a separate thread to keep the BGE from freezing. Here is an example from the docs:
# Print a message when an async LibLoad is done
import bge
def finished_cb(status):
print("Library (%s) loaded in %.2fms." % (status.libraryName, status.timeTaken))
bge.logic.LibLoad('myblend.blend', 'Scene', async=True).onFinish = finished_cb
LibLoad() now returns a KX_LibLoadStatus object for information on the library loading. LibNew() and LibFree() are unaffected by this commit. In other words, the async option only works for LibLoad(). Furthermore it only works for Scenes, not Actions or Meshes.
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index df8f6eb44e8..0d39eb844b5 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -136,6 +136,7 @@ extern "C" { /* for converting new scenes */ #include "KX_BlenderSceneConverter.h" +#include "KX_LibLoadStatus.h" #include "KX_MeshProxy.h" /* for creating a new library of mesh objects */ extern "C" { #include "BKE_idcode.h" @@ -670,14 +671,15 @@ static PyObject *gLibLoad(PyObject *, PyObject *args, PyObject *kwds) Py_buffer py_buffer; py_buffer.buf = NULL; char *err_str= NULL; + KX_LibLoadStatus *status = NULL; short options=0; - int load_actions=0, verbose=0, load_scripts=1; + int load_actions=0, verbose=0, load_scripts=1, async=0; - static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", NULL}; + static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", "async", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iii:LibLoad", const_cast<char**>(kwlist), - &path, &group, &py_buffer, &load_actions, &verbose, &load_scripts)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iiIi:LibLoad", const_cast<char**>(kwlist), + &path, &group, &py_buffer, &load_actions, &verbose, &load_scripts, &async)) return NULL; /* setup options */ @@ -687,6 +689,8 @@ static PyObject *gLibLoad(PyObject *, PyObject *args, PyObject *kwds) options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE; if (load_scripts != 0) options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_SCRIPTS; + if (async != 0) + options |= KX_BlenderSceneConverter::LIB_LOAD_ASYNC; if (!py_buffer.buf) { @@ -695,16 +699,16 @@ static PyObject *gLibLoad(PyObject *, PyObject *args, PyObject *kwds) BLI_strncpy(abs_path, path, sizeof(abs_path)); BLI_path_abs(abs_path, gp_GamePythonPath); - if (kx_scene->GetSceneConverter()->LinkBlendFilePath(abs_path, group, kx_scene, &err_str, options)) { - Py_RETURN_TRUE; + if ((status=kx_scene->GetSceneConverter()->LinkBlendFilePath(abs_path, group, kx_scene, &err_str, options))) { + return status->GetProxy(); } } else { - if (kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str, options)) { + if ((status=kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str, options))) { PyBuffer_Release(&py_buffer); - Py_RETURN_TRUE; + return status->GetProxy(); } PyBuffer_Release(&py_buffer); |