importing the GameLogic module was being done by adding the text "import GameLogic...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 14 Jul 2008 00:47:07 +0000 (00:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 14 Jul 2008 00:47:07 +0000 (00:47 +0000)
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/GameLogic/SCA_PythonController.cpp
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Ketsji/KX_PythonInit.h
source/gameengine/Ketsji/KX_SoundActuator.cpp

index 4af5ac4d5d2f3a47502b6ac0f7b678a8ad8ebf11..b3a3a47152ad03a54a710f023020308a9efb4e57 100644 (file)
@@ -332,6 +332,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(startscene);
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
                        initGameKeys();
                        initPythonConstraintBinding();
 
@@ -399,7 +400,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                exitstring = ketsjiengine->GetExitString();
                                
                                // when exiting the mainloop
-                               dictionaryClearByHand(gameLogic);
+                               
+                               // Clears the dictionary by hand:
+                               // This prevents, extra references to global variables
+                               // inside the GameLogic dictionary when the python interpreter is finalized.
+                               // which allows the scene to safely delete them :)
+                               // see: (space.c)->start_game
+                               PyDict_Clear(PyModule_GetDict(gameLogic));
+                               
                                ketsjiengine->StopEngine();
                                exitGamePythonScripting();
                                networkdevice->Disconnect();
@@ -591,6 +599,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(startscene);
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
                        initGameKeys();
                        initPythonConstraintBinding();
 
index 76386079bdf13d71ba8cb88313f79009f9294251..01ae4072335d30023f1aa64986187e05e539b5ea 100644 (file)
@@ -116,7 +116,7 @@ CValue* SCA_PythonController::GetReplica()
 
 void SCA_PythonController::SetScriptText(const STR_String& text)
 { 
-       m_scriptText = "import GameLogic\n" + text;
+       m_scriptText = text;
        m_bModified = true;
 }
 
@@ -354,8 +354,10 @@ SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value)
                        return sensor->AddRef();
                }
        }
-               
-       PyErr_SetString(PyExc_AttributeError, "Unable to find requested sensor");
+       
+       char emsg[96];
+       PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested sensor \"%s\"", scriptArg );
+       PyErr_SetString(PyExc_AttributeError, emsg);
        return NULL;
 }
 
@@ -382,8 +384,10 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value)
                        return actua->AddRef();
                }
        }
-               
-       PyErr_SetString(PyExc_AttributeError, "Unable to find requested actuator");
+       
+       char emsg[96];
+       PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested actuator \"%s\"", scriptArg );
+       PyErr_SetString(PyExc_AttributeError, emsg);
        return NULL;
 }
 
index d6908b53d405f0761a50d0efc752d584c488cdc5..b5ebffb93784e3652ddcfee0920dd460e04d1899 100644 (file)
@@ -644,7 +644,7 @@ bool GPG_Application::startEngine(void)
                PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest);
                m_ketsjiengine->SetPythonDictionary(dictionaryobject);
                initRasterizer(m_rasterizer, m_canvas);
-               PyObject *gameLogic = initGameLogic(startscene);
+               PyDict_SetItemString(dictionaryobject, "GameLogic", initGameLogic(startscene)); // Same as importing the module
                initGameKeys();
                initPythonConstraintBinding();
 
index 20187a193ba41151d9dee599dc4b2bd8f0cee057..db099d56b558f6c0f469a75f4cdcc2fb46b8429d 100644 (file)
@@ -231,7 +231,10 @@ void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
 }
 
 
-
+/*
+ * At the moment the GameLogic module is imported into 'pythondictionary' after this function is called.
+ * if this function ever changes to assign a copy, make sure the game logic module is imported into this dictionary before hand.
+ */
 void KX_KetsjiEngine::SetPythonDictionary(PyObject* pythondictionary)
 {
        MT_assert(pythondictionary);
index 433e0636833c914c3afef50edd21b59dd60418a3..61ed8b6a8e4a8567e8e92e03dedba20c75bc514a 100644 (file)
@@ -828,20 +828,9 @@ PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook
                Py_FatalError("can't initialize module GameLogic");
     }
 
-       return d;
+       return m;
 }
 
-void dictionaryClearByHand(PyObject *dict)
-{
-       // Clears the dictionary by hand:
-       // This prevents, extra references to global variables
-       // inside the GameLogic dictionary when the python interpreter is finalized.
-       // which allows the scene to safely delete them :)
-       // see: (space.c)->start_game
-       if(dict) PyDict_Clear(dict);
-}
-
-
 // Python Sandbox code
 // override builtin functions import() and open()
 
index c7d8f1b78bc00f966bf20fa41073ae2326f30342..41cf7fd67b3389db4dea906fa9a7def3ee5a5ea9 100644 (file)
@@ -47,7 +47,6 @@ PyObject*     initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur
 void           exitGamePlayerPythonScripting();
 PyObject*      initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level);
 void           exitGamePythonScripting();
-void           dictionaryClearByHand(PyObject *dict);
 
 void PHY_SetActiveScene(class KX_Scene* scene);
 class KX_Scene* PHY_GetActiveScene();
index 949156571a7de05a19b5d6326744f1cecd631749..34a3baec0933f29a5895048ed8f190d464261a08 100644 (file)
@@ -291,7 +291,8 @@ PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObje
        char* name = objectname.Ptr();
        
        if (!name) {
-               Py_Return;                                      /* internal error */
+               PyErr_SetString(PyExc_RuntimeError, "Unable to get sound filename");
+               return NULL;
        } else
                return PyString_FromString(name);
 }