- rather then passing the python namespace dictionary to the controller function get the namespace from the converter.

- renamed SetPythonDictionary() to SetPyNamespace()
- remove IsLight(), GetGameObjectType() existed before this but wasnt used for lights.
This commit is contained in:
Campbell Barton
2009-09-29 22:49:33 +00:00
parent 71b3088596
commit 8b6f5c171d
17 changed files with 27 additions and 62 deletions

View File

@@ -375,7 +375,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
// some python things // some python things
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata);
ketsjiengine->SetPythonDictionary(dictionaryobject); ketsjiengine->SetPyNamespace(dictionaryobject);
initRasterizer(rasterizer, canvas); initRasterizer(rasterizer, canvas);
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module. PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
@@ -406,9 +406,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw
// convert and add scene // convert and add scene
sceneconverter->ConvertScene( sceneconverter->ConvertScene(
startscene, startscene,
#ifndef DISABLE_PYTHON
dictionaryobject,
#endif
rendertools, rendertools,
canvas); canvas);
ketsjiengine->AddScene(startscene); ketsjiengine->AddScene(startscene);
@@ -702,7 +699,7 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win,
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
// some python things // some python things
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata);
ketsjiengine->SetPythonDictionary(dictionaryobject); ketsjiengine->SetPyNamespace(dictionaryobject);
initRasterizer(rasterizer, canvas); initRasterizer(rasterizer, canvas);
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
@@ -721,9 +718,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win,
// convert and add scene // convert and add scene
sceneconverter->ConvertScene( sceneconverter->ConvertScene(
startscene, startscene,
#ifndef DISABLE_PYTHON
dictionaryobject,
#endif
rendertools, rendertools,
canvas); canvas);
ketsjiengine->AddScene(startscene); ketsjiengine->AddScene(startscene);

View File

@@ -1897,9 +1897,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
KX_Scene* kxscene, KX_Scene* kxscene,
KX_KetsjiEngine* ketsjiEngine, KX_KetsjiEngine* ketsjiEngine,
e_PhysicsEngine physics_engine, e_PhysicsEngine physics_engine,
#ifndef DISABLE_PYTHON
PyObject* pythondictionary,
#endif
RAS_IRenderTools* rendertools, RAS_IRenderTools* rendertools,
RAS_ICanvas* canvas, RAS_ICanvas* canvas,
KX_BlenderSceneConverter* converter, KX_BlenderSceneConverter* converter,
@@ -2655,11 +2652,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
struct Object* blenderobj = gameobj->GetBlenderObject(); struct Object* blenderobj = gameobj->GetBlenderObject();
int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
BL_ConvertControllers(blenderobj,gameobj,logicmgr, BL_ConvertControllers(blenderobj,gameobj,logicmgr, layerMask,isInActiveLayer,converter);
#ifndef DISABLE_PYTHON
pythondictionary,
#endif
layerMask,isInActiveLayer,converter);
} }
for ( i=0;i<logicbrick_conversionlist->GetCount();i++) for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
{ {

View File

@@ -40,9 +40,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
class KX_Scene* kxscene, class KX_Scene* kxscene,
class KX_KetsjiEngine* ketsjiEngine, class KX_KetsjiEngine* ketsjiEngine,
e_PhysicsEngine physics_engine, e_PhysicsEngine physics_engine,
#ifndef DISABLE_PYTHON
PyObject* pythondictionary,
#endif
class RAS_IRenderTools* rendertools, class RAS_IRenderTools* rendertools,
class RAS_ICanvas* canvas, class RAS_ICanvas* canvas,
class KX_BlenderSceneConverter* sceneconverter, class KX_BlenderSceneConverter* sceneconverter,

View File

@@ -243,9 +243,6 @@ struct BlenderDebugDraw : public btIDebugDraw
#endif #endif
void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene, void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
#ifndef DISABLE_PYTHON
PyObject* dictobj,
#endif
class RAS_IRenderTools* rendertools, class RAS_IRenderTools* rendertools,
class RAS_ICanvas* canvas) class RAS_ICanvas* canvas)
{ {
@@ -330,9 +327,6 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
destinationscene, destinationscene,
m_ketsjiEngine, m_ketsjiEngine,
physics_engine, physics_engine,
#ifndef DISABLE_PYTHON
dictobj,
#endif
rendertools, rendertools,
canvas, canvas,
this, this,
@@ -924,3 +918,10 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
} }
#ifndef DISABLE_PYTHON
PyObject *KX_BlenderSceneConverter::GetPyNamespace()
{
return m_ketsjiEngine->GetPyNamespace();
}
#endif

View File

@@ -89,9 +89,6 @@ public:
*/ */
virtual void ConvertScene( virtual void ConvertScene(
class KX_Scene* destinationscene, class KX_Scene* destinationscene,
#ifndef DISABLE_PYTHON
PyObject* dictobj,
#endif
class RAS_IRenderTools* rendertools, class RAS_IRenderTools* rendertools,
class RAS_ICanvas* canvas class RAS_ICanvas* canvas
); );
@@ -145,6 +142,9 @@ public:
struct Main* GetMain() { return m_maggie; }; struct Main* GetMain() { return m_maggie; };
#ifndef DISABLE_PYTHON
PyObject *GetPyNamespace();
#endif
#ifdef WITH_CXX_GUARDEDALLOC #ifdef WITH_CXX_GUARDEDALLOC
public: public:

View File

@@ -92,9 +92,6 @@ void BL_ConvertControllers(
struct Object* blenderobject, struct Object* blenderobject,
class KX_GameObject* gameobj, class KX_GameObject* gameobj,
SCA_LogicManager* logicmgr, SCA_LogicManager* logicmgr,
#ifndef DISABLE_PYTHON
PyObject* pythondictionary,
#endif
int activeLayerBitInfo, int activeLayerBitInfo,
bool isInActiveLayer, bool isInActiveLayer,
KX_BlenderSceneConverter* converter KX_BlenderSceneConverter* converter
@@ -160,10 +157,9 @@ void BL_ConvertControllers(
bPythonCont* pycont = (bPythonCont*) bcontr->data; bPythonCont* pycont = (bPythonCont*) bcontr->data;
SCA_PythonController* pyctrl = new SCA_PythonController(gameobj, pycont->mode); SCA_PythonController* pyctrl = new SCA_PythonController(gameobj, pycont->mode);
gamecontroller = pyctrl; gamecontroller = pyctrl;
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
pyctrl->SetDictionary(pythondictionary); pyctrl->SetNamespace(converter->GetPyNamespace());
if(pycont->mode==SCA_PythonController::SCA_PYEXEC_SCRIPT) { if(pycont->mode==SCA_PythonController::SCA_PYEXEC_SCRIPT) {
if (pycont->text) if (pycont->text)

View File

@@ -35,9 +35,6 @@ void BL_ConvertControllers(
struct Object* blenderobject, struct Object* blenderobject,
class KX_GameObject* gameobj, class KX_GameObject* gameobj,
class SCA_LogicManager* logicmgr, class SCA_LogicManager* logicmgr,
#ifndef DISABLE_PYTHON
PyObject* pythondictionary,
#endif
int activeLayerBitInfo, int activeLayerBitInfo,
bool isInActiveLayer, bool isInActiveLayer,
class KX_BlenderSceneConverter* converter class KX_BlenderSceneConverter* converter

View File

@@ -219,6 +219,7 @@ public:
typedef enum ObjectTypes { typedef enum ObjectTypes {
OBJ_ARMATURE=0, OBJ_ARMATURE=0,
OBJ_CAMERA=1, OBJ_CAMERA=1,
OBJ_LIGHT=2,
}ObjectTypes; }ObjectTypes;
}; };

View File

@@ -151,7 +151,7 @@ void SCA_PythonController::SetScriptName(const STR_String& name)
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
void SCA_PythonController::SetDictionary(PyObject* pythondictionary) void SCA_PythonController::SetNamespace(PyObject* pythondictionary)
{ {
if (m_pythondictionary) if (m_pythondictionary)
{ {

View File

@@ -84,7 +84,7 @@ class SCA_PythonController : public SCA_IController
void SetScriptText(const STR_String& text); void SetScriptText(const STR_String& text);
void SetScriptName(const STR_String& name); void SetScriptName(const STR_String& name);
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
void SetDictionary(PyObject* pythondictionary); void SetNamespace(PyObject* pythondictionary);
#endif #endif
void SetDebug(bool debug) { m_debug = debug; } void SetDebug(bool debug) { m_debug = debug; }
void AddTriggeredSensor(class SCA_ISensor* sensor) void AddTriggeredSensor(class SCA_ISensor* sensor)

View File

@@ -679,7 +679,7 @@ bool GPG_Application::startEngine(void)
// some python things // some python things
PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie, m_argc, m_argv); PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie, m_argc, m_argv);
m_ketsjiengine->SetPythonDictionary(dictionaryobject); m_ketsjiengine->SetPyNamespace(dictionaryobject);
initRasterizer(m_rasterizer, m_canvas); initRasterizer(m_rasterizer, m_canvas);
PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene); PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
@@ -702,7 +702,6 @@ bool GPG_Application::startEngine(void)
m_sceneconverter->ConvertScene( m_sceneconverter->ConvertScene(
startscene, startscene,
dictionaryobject,
m_rendertools, m_rendertools,
m_canvas); m_canvas);
m_ketsjiengine->AddScene(startscene); m_ketsjiengine->AddScene(startscene);

View File

@@ -748,14 +748,6 @@ public:
void void
) { return m_bIsNegativeScaling; } ) { return m_bIsNegativeScaling; }
/**
* Is this a light?
*/
virtual bool
IsLight(
void
) { return false; }
/** /**
* @section Logic bubbling methods. * @section Logic bubbling methods.
*/ */

View File

@@ -53,9 +53,6 @@ public:
*/ */
virtual void ConvertScene( virtual void ConvertScene(
class KX_Scene* destinationscene, class KX_Scene* destinationscene,
#ifndef DISABLE_PYTHON
PyObject* dictobj,
#endif
class RAS_IRenderTools* rendertools, class RAS_IRenderTools* rendertools,
class RAS_ICanvas* canvas)=0; class RAS_ICanvas* canvas)=0;

View File

@@ -238,7 +238,7 @@ void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
* At the moment the GameLogic module is imported into 'pythondictionary' after this function is called. * 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. * 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) void KX_KetsjiEngine::SetPyNamespace(PyObject* pythondictionary)
{ {
MT_assert(pythondictionary); MT_assert(pythondictionary);
m_pythondictionary = pythondictionary; m_pythondictionary = pythondictionary;
@@ -1618,9 +1618,6 @@ KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename)
scene); scene);
m_sceneconverter->ConvertScene(tmpscene, m_sceneconverter->ConvertScene(tmpscene,
#ifndef DISABLE_PYTHON
m_pythondictionary,
#endif
m_rendertools, m_rendertools,
m_canvas); m_canvas);

View File

@@ -204,7 +204,8 @@ public:
void SetRenderTools(RAS_IRenderTools* rendertools); void SetRenderTools(RAS_IRenderTools* rendertools);
void SetRasterizer(RAS_IRasterizer* rasterizer); void SetRasterizer(RAS_IRasterizer* rasterizer);
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
void SetPythonDictionary(PyObject* pythondictionary); void SetPyNamespace(PyObject* pythondictionary);
PyObject* GetPyNamespace(){return m_pythondictionary;};
#endif #endif
void SetSceneConverter(KX_ISceneConverter* sceneconverter); void SetSceneConverter(KX_ISceneConverter* sceneconverter);
void SetGame2IpoMode(bool game2ipo,int startFrame); void SetGame2IpoMode(bool game2ipo,int startFrame);

View File

@@ -64,6 +64,8 @@ public:
void BindShadowBuffer(class RAS_IRasterizer *ras, class KX_Camera *cam, class MT_Transform& camtrans); void BindShadowBuffer(class RAS_IRasterizer *ras, class KX_Camera *cam, class MT_Transform& camtrans);
void UnbindShadowBuffer(class RAS_IRasterizer *ras); void UnbindShadowBuffer(class RAS_IRasterizer *ras);
void Update(); void Update();
virtual int GetGameObjectType() { return OBJ_LIGHT; }
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
/* attributes */ /* attributes */
@@ -73,8 +75,6 @@ public:
static PyObject* pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject* value); static int pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject* value);
#endif #endif
virtual bool IsLight(void) { return true; }
}; };
#endif //__KX_LIGHT #endif //__KX_LIGHT

View File

@@ -477,7 +477,7 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
// this is the list of object that are send to the graphics pipeline // this is the list of object that are send to the graphics pipeline
m_objectlist->Add(newobj->AddRef()); m_objectlist->Add(newobj->AddRef());
if (newobj->IsLight()) if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
m_lightlist->Add(newobj->AddRef()); m_lightlist->Add(newobj->AddRef());
newobj->AddMeshUser(); newobj->AddMeshUser();
@@ -753,7 +753,7 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
// add the object in the layer of the parent // add the object in the layer of the parent
(*git)->SetLayer(groupobj->GetLayer()); (*git)->SetLayer(groupobj->GetLayer());
// If the object was a light, we need to update it's RAS_LightObject as well // If the object was a light, we need to update it's RAS_LightObject as well
if ((*git)->IsLight()) if ((*git)->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
{ {
KX_LightObject* lightobj = static_cast<KX_LightObject*>(*git); KX_LightObject* lightobj = static_cast<KX_LightObject*>(*git);
lightobj->GetLightData()->m_layer = groupobj->GetLayer(); lightobj->GetLightData()->m_layer = groupobj->GetLayer();
@@ -861,7 +861,7 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
// add the object in the layer of the parent // add the object in the layer of the parent
(*git)->SetLayer(parentobj->GetLayer()); (*git)->SetLayer(parentobj->GetLayer());
// If the object was a light, we need to update it's RAS_LightObject as well // If the object was a light, we need to update it's RAS_LightObject as well
if ((*git)->IsLight()) if ((*git)->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
{ {
KX_LightObject* lightobj = static_cast<KX_LightObject*>(*git); KX_LightObject* lightobj = static_cast<KX_LightObject*>(*git);
lightobj->GetLightData()->m_layer = parentobj->GetLayer(); lightobj->GetLightData()->m_layer = parentobj->GetLayer();
@@ -982,7 +982,7 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj)
newobj->RemoveMeshes(); newobj->RemoveMeshes();
ret = 1; ret = 1;
if (newobj->IsLight() && m_lightlist->RemoveValue(newobj)) if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT && m_lightlist->RemoveValue(newobj))
ret = newobj->Release(); ret = newobj->Release();
if (m_objectlist->RemoveValue(newobj)) if (m_objectlist->RemoveValue(newobj))
ret = newobj->Release(); ret = newobj->Release();