[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23511] branches/ge_dyn_load/source/ gameengine: cleanup, removed unused code.
Campbell Barton
ideasman42 at gmail.com
Sun Sep 27 16:04:46 CEST 2009
Revision: 23511
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23511
Author: campbellbarton
Date: 2009-09-27 16:04:46 +0200 (Sun, 27 Sep 2009)
Log Message:
-----------
cleanup, removed unused code.
Modified Paths:
--------------
branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.h
branches/ge_dyn_load/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
branches/ge_dyn_load/source/gameengine/Ketsji/KX_KetsjiEngine.h
branches/ge_dyn_load/source/gameengine/Ketsji/KX_PythonInit.cpp
branches/ge_dyn_load/source/gameengine/Ketsji/KX_Scene.cpp
Modified: branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
===================================================================
--- branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.cpp 2009-09-27 13:47:04 UTC (rev 23510)
+++ branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.cpp 2009-09-27 14:04:46 UTC (rev 23511)
@@ -983,263 +983,95 @@
return NULL;
}
-bool KX_BlenderSceneConverter::LinkBlendFile(const char *path)
+bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str)
{
+ bContext *C;
+ Main *main_newlib; /* stored as a dynamic 'main' until we free it */
+ Main *main_tmp= NULL; /* created only for linking, then freed */
+ LinkNode *names = NULL;
+ BlendHandle *bpy_openlib = NULL; /* ptr to the open .blend file */
+ int idcode= BLO_idcode_from_name(group);
+ short flag= 0; /* dont need any special options */
+ ReportList reports;
+ static char err_local[255];
+
+ /* only scene and mesh supported right now */
+ if(idcode==0 && idcode!=ID_SCE && idcode!=ID_ME) {
+ snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group);
+ return false;
+ }
+
if(GetMainDynamicPath(path)) {
- printf( "blend file alredy open \"%s\"\n", path);
+ snprintf(err_local, sizeof(err_local), "blend file alredy open \"%s\"\n", path);
+ *err_str= err_local;
return false;
}
- BlendHandle *bpy_openlib = NULL; /* ptr to the open .blend file */
bpy_openlib = BLO_blendhandle_from_file( (char *)path );
- ReportList reports;
-
if(bpy_openlib==NULL) {
- printf( "could not open blendfile\n");
+ snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path);
+ *err_str= err_local;
return false;
}
-
- // XXX - new untested code!!! - after merge
- LinkNode *l, *n, *names = NULL;
- int blocktype = 0;
- Main *maggie= (Main *)MEM_callocN( sizeof(Main), "BgeMain");
- GetMainDynamic().push_back(maggie);
- // --
- bContext *C= CTX_create();
+ C= CTX_create();
CTX_data_main_set(C, m_maggie);
-
- Main *mainl= 0;
- char group[GROUP_MAX];
- int idcode;
- short flag;
-
+ BKE_reports_init(&reports, RPT_STORE);
- idcode = BLO_idcode_from_name(group);
+ main_newlib= (Main *)MEM_callocN( sizeof(Main), "BgeMain");
/* here appending/linking starts */
- mainl = BLO_library_append_begin(C, &bpy_openlib, (char *)path);
- {
- BKE_reports_init(&reports, RPT_STORE);
+ main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path);
- LinkNode *groups = BLO_blendhandle_get_linkable_groups( bpy_openlib );
- for( l = groups; l; l = l->next ) {
- blocktype = BLO_idcode_from_name((char *)l->link);
+ names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode);
-//if(ID_ME==blocktype) {
-if(ID_SCE==blocktype) {
-
- names = BLO_blendhandle_get_datablock_names( bpy_openlib, blocktype);
-
- int i= 0;
- for(n= names; n; n= n->next, i++) {
- BLO_library_append_named_part(C, mainl, &bpy_openlib, (char *)n->link, idcode, 0);
- }
-
- BLI_linklist_free(names, free); /* free linklist *and* each node's data */
-}
- }
- BLI_linklist_free(groups, free); /* free linklist *and* each node's data */
-
- BKE_reports_clear(&reports);
+ int i=0;
+ LinkNode *n= names;
+ while(n) {
+ BLO_library_append_named_part(C, main_tmp, &bpy_openlib, (char *)n->link, idcode, 0);
+ n= (LinkNode *)n->next;
+ i++;
}
- BLO_library_append_end(C, mainl, &bpy_openlib, idcode, flag);
+ BLI_linklist_free(names, free); /* free linklist *and* each node's data */
+ BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag);
BLO_blendhandle_close(bpy_openlib);
CTX_free(C);
+ BKE_reports_clear(&reports);
+ /* done linking */
/* needed for lookups*/
- strncpy(maggie->name, path, sizeof(maggie->name));
+ GetMainDynamic().push_back(main_newlib);
+ strncpy(main_newlib->name, path, sizeof(main_newlib->name));
- BKE_reports_clear(&reports);
-
-#if 0
- ID* mesh;
- KX_Scene *kx_scene= m_currentScene;
-
- for(mesh= (ID *)maggie->mesh.first; mesh; mesh= (ID *)mesh->next ) {
-
- RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, kx_scene, this);
- kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
-
- /*
- KX_MeshProxy* meshproxy = new KX_MeshProxy(meshobj);
- PyObject *item= meshproxy->NewProxy(true);
- PyList_Append(ret, item);
- Py_DECREF(item);
- */
- }
-#endif
-
-
-
- {
-
- ID *scene;
-
- for(scene= (ID *)maggie->scene.first; scene; scene= (ID *)scene->next ) {
- //KX_Scene *kx_scene_new = m_ketsjiEngine->CreateScene(scene);
-
- printf("ES: %s\n", scene->name);
-
- /*GetBlenderSceneForName looks up the m_maggie_dyn now */
-
- if (0) {
- m_ketsjiEngine->ConvertAndAddScene(scene->name+2, true);
- }
- else if(0) { // WORSK NICE BUT USES HACK
- KX_Scene *kx_scene= m_ketsjiEngine->CurrentScenes()->at(0); //XXX hack
-
- PHY_IPhysicsEnvironment *physEnv = kx_scene->GetPhysicsEnvironment();
-
- KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene, physEnv);
-
- kx_scene->MergeScene(other);
-
- other->SetPhysicsEnvironment(NULL);
- //
- other= NULL;
- }
- else {
- // m_ketsjiEngine->AddScene();
-
- /* attempt propper merge */
- KX_Scene *kx_scene= m_ketsjiEngine->CurrentScenes()->at(0); //XXX hack
- KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene);
-
- kx_scene->MergeScene(other);
-
- // RemoveScene(other); // Dont run this, it frees the entire scene converter data.
- // just delete the scene
-
- delete other;
- }
+ if(idcode==ID_ME) {
+ /* Convert all new meshes into BGE meshes */
+ ID* mesh;
+ KX_Scene *kx_scene= m_currentScene;
+
+ for(mesh= (ID *)main_newlib->mesh.first; mesh; mesh= (ID *)mesh->next ) {
+ RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this);
+ kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
}
}
-
- BLO_blendhandle_close( bpy_openlib );
- // free_main(maggie); // keep as long as the scene is loaded.
-
-
-#if 0
- PyObject *callback= NULL;
-
- if (!PyArg_ParseTuple(args,"s|O:LoadLibrary",&path, &callback))
- return NULL;
-
- if(callback && !PyCallable_Check(callback)) {
- PyErr_SetString(PyExc_TypeError, "expected a callable second arg");
- return NULL;
- }
-
- BlendHandle *bpy_openlib = NULL; /* ptr to the open .blend file */
- bpy_openlib = BLO_blendhandle_from_file( path );
-
- if(bpy_openlib==NULL) {
- PyErr_SetString(PyExc_TypeError, "could not open blendfile");
- return NULL;
- }
-
- /* Create args from library data */
- PyObject *dict_arg= PyDict_New();
-
-
- char *group, *name;
- int blocktype = 0;
- LinkNode *l, *n, *names = NULL;
- PyObject *list = NULL;
-
- LinkNode *groups = BLO_blendhandle_get_linkable_groups( bpy_openlib );
- for( l = groups; l; l = l->next ) {
- blocktype = BLO_idcode_from_name((char *)l->next);
- names = BLO_blendhandle_get_datablock_names( bpy_openlib, blocktype);
-
- list= PyList_New(BLI_linklist_length(names));
- PyDict_SetItemString(dict_arg, (char*)l->link, list);
-
- int i= 0;
- for(n= names; n; n= n->next, i++)
- PyList_SET_ITEM( list, i, PyUnicode_FromString((char *)n->link));
-
- BLI_linklist_free(names, free); /* free linklist *and* each node's data */
-
- }
- BLI_linklist_free(groups, free); /* free linklist *and* each node's data */
-
- PyObject *ret = PyObject_CallFunction(callback, "N", dict_arg);
- if(ret==NULL) {
- return NULL;
- }
- else {
- Py_DECREF(ret);
- }
-
-
- Scene *scene= NULL; /* scene CAN be null, its ok! */
- Main maggie;
- ReportList *reports;
-
- memset(&maggie, 0, sizeof(maggie));
-
-
-
- PyObject *key, *value;
- Py_ssize_t pos = 0;
-
- while (PyDict_Next(dict_arg, &pos, &key, &value)) {
- group= _PyUnicode_AsString(key);
- if(group==NULL) { /* user added a non string, idiot!, can safely ignore */
- PyErr_Clear();
+ else if(idcode==ID_SCE) {
+ /* Merge all new linked in scene into the existing one */
+ ID *scene;
+ for(scene= (ID *)main_newlib->scene.first; scene; scene= (ID *)scene->next ) {
+ // printf("SceneName: %s\n", scene->name);
+
+ /* merge into the base scene */
+ KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene);
+ scene_merge->MergeScene(other);
+
+ // RemoveScene(other); // Dont run this, it frees the entire scene converter data, just delete the scene
+ delete other;
}
- else if((blocktype = BLO_idcode_from_name(group)) && PyList_Check(value)) {
- int len= PyList_GET_SIZE(value);
-
- for(int i=0; i<len; i++) {
- name=_PyUnicode_AsString(PyList_GET_ITEM(value, i));
- if(name==NULL) {
- PyErr_Clear();
- }
- else {
- BLO_script_library_append(&bpy_openlib, path, name, blocktype, FILE_LINK, &maggie, scene, reports);
-
- if(bpy_openlib==NULL)
- break;
- }
- }
-
- if(bpy_openlib==NULL)
- break;
- }
}
-
- Py_DECREF(dict_arg);
+
BLO_blendhandle_close( bpy_openlib );
-
-
- {
- ret= PyList_New(0);
- ID* mesh;
- KX_Scene *kx_scene= gp_KetsjiScene;
-
- for(mesh= (ID *)maggie.mesh.first; mesh; mesh= (ID *)mesh->next ) {
-
- RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, kx_scene, kx_scene->GetSceneConverter());
- kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
-
- KX_MeshProxy* meshproxy = new KX_MeshProxy(meshobj);
- PyObject *item= meshproxy->NewProxy(true);
- PyList_Append(ret, item);
- Py_DECREF(item);
-
- }
-
- return ret;
- }
-#endif
-
-
return true;
}
Modified: branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.h
===================================================================
--- branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.h 2009-09-27 13:47:04 UTC (rev 23510)
+++ branches/ge_dyn_load/source/gameengine/Converter/KX_BlenderSceneConverter.h 2009-09-27 14:04:46 UTC (rev 23511)
@@ -146,7 +146,7 @@
struct Main* GetMainDynamicPath(const char *path);
vector<struct Main*> &GetMainDynamic();
- bool LinkBlendFile(const char *path);
+ bool LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str);
bool MergeScene(KX_Scene *to, KX_Scene *from);
RAS_MeshObject *ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name);
bool FreeBlendFile(struct Main *maggie);
Modified: branches/ge_dyn_load/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list