Commit: f80924027f848f2deef01c6e7575923377e8fa9e
Author: Roman Pogribnyi
Date:   Wed Jul 2 20:13:12 2014 +0200
https://developer.blender.org/rBf80924027f848f2deef01c6e7575923377e8fa9e

importing manta module to interpreter

===================================================================

M       extern/manta_pp/pwrapper/registry.cpp
M       intern/smoke/intern/MANTA.h

===================================================================

diff --git a/extern/manta_pp/pwrapper/registry.cpp 
b/extern/manta_pp/pwrapper/registry.cpp
index b571b2e..0880b88 100644
--- a/extern/manta_pp/pwrapper/registry.cpp
+++ b/extern/manta_pp/pwrapper/registry.cpp
@@ -97,6 +97,13 @@ public:
        ClassData* lookup(const std::string& name);
        bool canConvert(ClassData* from, ClassData* to);
        PyThreadState *state;
+       /*blender integration*/
+       PyGILState_STATE mMainGilState;     
+    PyThreadState* mOldThreadState;    
+    PyThreadState* mNewThreadState;     
+    PyThreadState* mSubThreadState;     
+    PyGILState_STATE mSubGilState;      
+
 private:
        ClassData* getOrConstructClass(const string& name);
        void registerBaseclasses();
@@ -400,10 +407,10 @@ void WrapperRegistry::runPreInit() {
        // add python directories to path
 //     WrapperRegistry::instance().initModule();
        PyObject *sys_path = NULL;
-       PyObject *sd = PyThreadState_GET()->interp->sysdict;
-    if (sd == NULL)
-        sys_path = NULL;
-    else sys_path = PyDict_GetItemString(sd, (char*)"path");
+//     PyObject *sd = PyThreadState_GET()->interp->sysdict;
+//    if (sd == NULL)
+//        sys_path = NULL;
+//    else sys_path = PyDict_GetItemString(sd, (char*)"path");
        sys_path = PySys_GetObject("path");
        
        for (size_t i=0; i<mPaths.size(); i++) {
@@ -459,7 +466,7 @@ void WrapperRegistry::construct(const string& scriptname, 
const vector<string>&
        registerDummyTypes();
        
        // load main extension module
-       PyImport_AppendInittab((char*)gDefaultModuleName.c_str(), PyInit_Main);
+//     PyImport_AppendInittab((char*)gDefaultModuleName.c_str(), PyInit_Main);
 }
 
 inline PyObject* castPy(PyTypeObject* p) { 
@@ -587,17 +594,29 @@ PyObject* WrapperRegistry::initModule() {
 
 void setup(const std::string& filename, const std::vector<std::string>& args) {
        WrapperRegistry::instance().construct(filename,args);
-       int a = Py_IsInitialized();
-       Py_Initialize();
-//     int b = Py_IsInitialized();
-//     PyThreadState *st = Py_NewInterpreter();
-       int c = Py_IsInitialized();
+       
+       WrapperRegistry::instance().mMainGilState =  PyGILState_Ensure(); 
+       WrapperRegistry::instance().mOldThreadState = PyThreadState_Get(); 
+       WrapperRegistry::instance().mNewThreadState = Py_NewInterpreter();
+       PyThreadState_Swap( WrapperRegistry::instance().mNewThreadState );
+       WrapperRegistry::instance().mSubThreadState = PyEval_SaveThread();  
+       WrapperRegistry::instance().mSubGilState = PyGILState_Ensure();     
+
+       PyObject * manta_module = PyInit_Main();
+       PyImport_Import(manta_module);
+       int k=0;
+
        WrapperRegistry::instance().runPreInit();
 }
 
 void finalize() {
-       Py_Finalize();
+//     Py_Finalize();
        //Py_EndInterpreter(WrapperRegistry::instance().state);
+       PyGILState_Release( WrapperRegistry::instance().mSubGilState );      
+       PyEval_RestoreThread( WrapperRegistry::instance().mSubThreadState ); 
+       Py_EndInterpreter( WrapperRegistry::instance().mNewThreadState );    
+       PyThreadState_Swap( WrapperRegistry::instance().mOldThreadState );
+       PyGILState_Release( WrapperRegistry::instance().mMainGilState );    
        WrapperRegistry::instance().cleanup();
 }
 
diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h
index 67dd9cc..4abde3e 100644
--- a/intern/smoke/intern/MANTA.h
+++ b/intern/smoke/intern/MANTA.h
@@ -170,27 +170,12 @@ void run_manta_scene()
        int a = Py_IsInitialized();
        //PyInterpreterState *st = PyThreadState_GET()->interp;
        //PyThreadState *ts = Py_NewInterpreter();
-       PyGILState_STATE mMainGilState;     
-    PyThreadState* mOldThreadState;    
-    PyThreadState* mNewThreadState;     
-    PyThreadState* mSubThreadState;     
-    PyGILState_STATE mSubGilState;      
-       mMainGilState =  PyGILState_Ensure(); 
-       mOldThreadState = PyThreadState_Get(); 
-       mNewThreadState = Py_NewInterpreter();
-       PyThreadState_Swap( mNewThreadState );
-       mSubThreadState = PyEval_SaveThread();  
-       mSubGilState = PyGILState_Ensure();     
-       
+               
        vector<string> args;
        args.push_back("manta_scene.py");
        
        runScript(args);
-       PyGILState_Release( mSubGilState );      
-       PyEval_RestoreThread( mSubThreadState ); 
-       Py_EndInterpreter( mNewThreadState );    
-       PyThreadState_Swap( mOldThreadState );
-       PyGILState_Release( mMainGilState );     
+        
        //system("./manta manta_scene.py");
 //     pthread_exit(NULL);
 }
@@ -214,7 +199,7 @@ static void generate_manta_sim_file(Scene *scene, 
SmokeModifierData *smd)
        stringstream ss; /*setup contents*/
        
        /*header*/
-       ss << "from manta import * \n";
+       ss << "import manta\n";//"from manta import * \n";
        ss << "import os, shutil, math, sys \n";
        if (!file_exists("manta_flow.obj")){
                return;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to