4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
28 * Ketsji scene. Holds references to all scene data.
31 /** \file gameengine/Ketsji/KX_Scene.cpp
36 #if defined(WIN32) && !defined(FREE_WINDOWS)
37 #pragma warning (disable : 4786)
41 #include "KX_PythonInit.h"
42 #include "MT_assert.h"
43 #include "KX_KetsjiEngine.h"
44 #include "KX_BlenderMaterial.h"
45 #include "RAS_IPolygonMaterial.h"
46 #include "ListValue.h"
47 #include "SCA_LogicManager.h"
48 #include "SCA_TimeEventManager.h"
49 //#include "SCA_AlwaysEventManager.h"
50 //#include "SCA_RandomEventManager.h"
51 //#include "KX_RayEventManager.h"
52 #include "KX_TouchEventManager.h"
53 #include "SCA_KeyboardManager.h"
54 #include "SCA_MouseManager.h"
55 //#include "SCA_PropertyEventManager.h"
56 #include "SCA_ActuatorEventManager.h"
57 #include "SCA_BasicEventManager.h"
58 #include "KX_Camera.h"
59 #include "SCA_JoystickManager.h"
61 #include "RAS_MeshObject.h"
63 #include "RAS_IRasterizer.h"
64 #include "RAS_BucketManager.h"
66 #include "FloatValue.h"
67 #include "SCA_IController.h"
68 #include "SCA_IActuator.h"
70 #include "BL_System.h"
71 #include "SG_Controller.h"
72 #include "SG_IObject.h"
74 #include "DNA_group_types.h"
75 #include "DNA_scene_types.h"
77 #include "KX_SG_NodeRelationships.h"
79 #include "KX_NetworkEventManager.h"
80 #include "NG_NetworkScene.h"
81 #include "PHY_IPhysicsEnvironment.h"
82 #include "KX_IPhysicsController.h"
83 #include "PHY_IGraphicController.h"
84 #include "KX_BlenderSceneConverter.h"
85 #include "KX_MotionState.h"
87 #include "BL_ModifierDeformer.h"
88 #include "BL_ShapeDeformer.h"
89 #include "BL_DeformableGameObject.h"
92 #include "KX_SoftBodyDeformer.h"
93 #include "KX_ConvertPhysicsObject.h"
94 #include "CcdPhysicsEnvironment.h"
95 #include "CcdPhysicsController.h"
102 void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene)
104 KX_GameObject* replica = ((KX_Scene*)scene)->AddNodeReplicaObject(node,(KX_GameObject*)gameobj);
109 return (void*)replica;
112 void* KX_SceneDestructionFunc(SG_IObject* node,void* gameobj,void* scene)
114 ((KX_Scene*)scene)->RemoveNodeDestructObject(node,(KX_GameObject*)gameobj);
119 bool KX_Scene::KX_ScenegraphUpdateFunc(SG_IObject* node,void* gameobj,void* scene)
121 return ((SG_Node*)node)->Schedule(((KX_Scene*)scene)->m_sghead);
124 bool KX_Scene::KX_ScenegraphRescheduleFunc(SG_IObject* node,void* gameobj,void* scene)
126 return ((SG_Node*)node)->Reschedule(((KX_Scene*)scene)->m_sghead);
129 SG_Callbacks KX_Scene::m_callbacks = SG_Callbacks(
130 KX_SceneReplicationFunc,
131 KX_SceneDestructionFunc,
132 KX_GameObject::UpdateTransformFunc,
133 KX_Scene::KX_ScenegraphUpdateFunc,
134 KX_Scene::KX_ScenegraphRescheduleFunc);
136 // temporarily var until there is a button in the userinterface
137 // (defined in KX_PythonInit.cpp)
138 extern bool gUseVisibilityTemp;
140 KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
141 class SCA_IInputDevice* mousedevice,
142 class NG_NetworkDeviceInterface *ndi,
143 const STR_String& sceneName,
145 class RAS_ICanvas* canvas):
149 m_sceneConverter(NULL),
150 m_physicsEnvironment(0),
151 m_sceneName(sceneName),
152 m_networkDeviceInterface(ndi),
153 m_active_camera(NULL),
154 m_ueberExecutionPriority(0),
155 m_blenderScene(scene)
157 m_suspendedtime = 0.0;
158 m_suspendeddelta = 0.0;
160 m_dbvt_culling = false;
161 m_dbvt_occlusion_res = 0;
162 m_activity_culling = false;
164 m_isclearingZbuffer = true;
165 m_tempObjectList = new CListValue();
166 m_objectlist = new CListValue();
167 m_parentlist = new CListValue();
168 m_lightlist= new CListValue();
169 m_inactivelist = new CListValue();
170 m_euthanasyobjects = new CListValue();
171 m_animatedlist = new CListValue();
173 m_logicmgr = new SCA_LogicManager();
175 m_timemgr = new SCA_TimeEventManager(m_logicmgr);
176 m_keyboardmgr = new SCA_KeyboardManager(m_logicmgr,keyboarddevice);
177 m_mousemgr = new SCA_MouseManager(m_logicmgr,mousedevice, canvas);
179 //SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr);
180 //SCA_PropertyEventManager* propmgr = new SCA_PropertyEventManager(m_logicmgr);
181 SCA_ActuatorEventManager* actmgr = new SCA_ActuatorEventManager(m_logicmgr);
182 //SCA_RandomEventManager* rndmgr = new SCA_RandomEventManager(m_logicmgr);
183 SCA_BasicEventManager* basicmgr = new SCA_BasicEventManager(m_logicmgr);
184 //KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr);
186 KX_NetworkEventManager* netmgr = new KX_NetworkEventManager(m_logicmgr, ndi);
190 //m_logicmgr->RegisterEventManager(alwaysmgr);
191 //m_logicmgr->RegisterEventManager(propmgr);
192 m_logicmgr->RegisterEventManager(actmgr);
193 m_logicmgr->RegisterEventManager(m_keyboardmgr);
194 m_logicmgr->RegisterEventManager(m_mousemgr);
195 m_logicmgr->RegisterEventManager(m_timemgr);
196 //m_logicmgr->RegisterEventManager(rndmgr);
197 //m_logicmgr->RegisterEventManager(raymgr);
198 m_logicmgr->RegisterEventManager(netmgr);
199 m_logicmgr->RegisterEventManager(basicmgr);
202 SYS_SystemHandle hSystem = SYS_GetSystem();
203 bool nojoystick= SYS_GetCommandLineInt(hSystem,"nojoystick",0);
206 SCA_JoystickManager *joymgr = new SCA_JoystickManager(m_logicmgr);
207 m_logicmgr->RegisterEventManager(joymgr);
210 MT_assert (m_networkDeviceInterface != NULL);
211 m_networkScene = new NG_NetworkScene(m_networkDeviceInterface);
215 m_bucketmanager=new RAS_BucketManager();
218 m_attr_dict = PyDict_New(); /* new ref */
219 m_draw_call_pre = NULL;
220 m_draw_call_post = NULL;
226 KX_Scene::~KX_Scene()
228 // The release of debug properties used to be in SCA_IScene::~SCA_IScene
229 // It's still there but we remove all properties here otherwise some
230 // reference might be hanging and causing late release of objects
231 RemoveAllDebugProperties();
233 while (GetRootParentList()->GetCount() > 0)
235 KX_GameObject* parentobj = (KX_GameObject*) GetRootParentList()->GetValue(0);
236 this->RemoveObject(parentobj);
240 m_objectlist->Release();
243 m_parentlist->Release();
246 m_inactivelist->Release();
249 m_lightlist->Release();
251 if (m_tempObjectList)
252 m_tempObjectList->Release();
254 if (m_euthanasyobjects)
255 m_euthanasyobjects->Release();
258 m_animatedlist->Release();
263 if (m_physicsEnvironment)
264 delete m_physicsEnvironment;
267 delete m_networkScene;
271 delete m_bucketmanager;
275 PyDict_Clear(m_attr_dict);
276 /* Py_CLEAR: Py_DECREF's and NULL's */
277 Py_CLEAR(m_attr_dict);
279 /* these may be NULL but the macro checks */
280 Py_CLEAR(m_draw_call_pre);
281 Py_CLEAR(m_draw_call_post);
285 RAS_BucketManager* KX_Scene::GetBucketManager()
287 return m_bucketmanager;
291 CListValue* KX_Scene::GetTempObjectList()
293 return m_tempObjectList;
296 CListValue* KX_Scene::GetObjectList()
302 CListValue* KX_Scene::GetRootParentList()
307 CListValue* KX_Scene::GetInactiveList()
309 return m_inactivelist;
314 CListValue* KX_Scene::GetLightList()
319 SCA_LogicManager* KX_Scene::GetLogicManager()
324 SCA_TimeEventManager* KX_Scene::GetTimeEventManager()
332 list<class KX_Camera*>* KX_Scene::GetCameras()
337 list<class KX_FontObject*>* KX_Scene::GetFonts()
342 void KX_Scene::SetFramingType(RAS_FrameSettings & frame_settings)
344 m_frame_settings = frame_settings;
348 * Return a const reference to the framing
349 * type set by the above call.
350 * The contents are not guarenteed to be sensible
351 * if you don't call the above function.
353 const RAS_FrameSettings& KX_Scene::GetFramingType() const
355 return m_frame_settings;
361 * Store the current scene's viewport on the
362 * game engine canvas.
364 void KX_Scene::SetSceneViewport(const RAS_Rect &viewport)
366 m_viewport = viewport;
371 const RAS_Rect& KX_Scene::GetSceneViewport() const
378 void KX_Scene::SetWorldInfo(class KX_WorldInfo* worldinfo)
380 m_worldinfo = worldinfo;
385 class KX_WorldInfo* KX_Scene::GetWorldInfo()
391 const STR_String& KX_Scene::GetName()
397 void KX_Scene::Suspend()
402 void KX_Scene::Resume()
407 void KX_Scene::SetActivityCulling(bool b)
409 m_activity_culling = b;
412 bool KX_Scene::IsSuspended()
417 bool KX_Scene::IsClearingZBuffer()
419 return m_isclearingZbuffer;
422 void KX_Scene::EnableZBufferClearing(bool isclearingZbuffer)
424 m_isclearingZbuffer = isclearingZbuffer;
427 void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gameobj)
429 KX_GameObject* orgobj = (KX_GameObject*)gameobj;
430 if (NewRemoveObject(orgobj) != 0)
432 // object is not yet deleted because a reference is hanging somewhere.
433 // This should not happen anymore since we use proxy object for Python
434 // confident enough to put an assert?
436 printf("Zombie object! name=%s\n", orgobj->GetName().ReadPtr());
437 orgobj->SetSGNode(NULL);
438 PHY_IGraphicController* ctrl = orgobj->GetGraphicController();
441 // a graphic controller is set, we must delete it as the node will be deleted
443 orgobj->SetGraphicController(NULL);
450 KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CValue* gameobj)
452 // for group duplication, limit the duplication of the hierarchy to the
453 // objects that are part of the group.
454 if (!IsObjectInGroup(gameobj))
457 KX_GameObject* orgobj = (KX_GameObject*)gameobj;
458 KX_GameObject* newobj = (KX_GameObject*)orgobj->GetReplica();
459 m_map_gameobject_to_replica.insert(orgobj, newobj);
461 // also register 'timers' (time properties) of the replica
462 int numprops = newobj->GetPropertyCount();
464 for (int i = 0; i < numprops; i++)
466 CValue* prop = newobj->GetProperty(i);
468 if (prop->GetProperty("timer"))
469 this->m_timemgr->AddTimeProperty(prop);
474 newobj->SetSGNode((SG_Node*)node);
478 m_rootnode = new SG_Node(newobj,this,KX_Scene::m_callbacks);
480 // this fixes part of the scaling-added object bug
481 SG_Node* orgnode = orgobj->GetSGNode();
482 m_rootnode->SetLocalScale(orgnode->GetLocalScale());
483 m_rootnode->SetLocalPosition(orgnode->GetLocalPosition());
484 m_rootnode->SetLocalOrientation(orgnode->GetLocalOrientation());
486 // define the relationship between this node and it's parent.
487 KX_NormalParentRelation * parent_relation =
488 KX_NormalParentRelation::New();
489 m_rootnode->SetParentRelation(parent_relation);
491 newobj->SetSGNode(m_rootnode);
494 SG_IObject* replicanode = newobj->GetSGNode();
495 // SG_Node* rootnode = (replicanode == m_rootnode ? NULL : m_rootnode);
497 replicanode->SetSGClientObject(newobj);
499 // this is the list of object that are send to the graphics pipeline
500 m_objectlist->Add(newobj->AddRef());
501 if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
502 m_lightlist->Add(newobj->AddRef());
503 newobj->AddMeshUser();
505 // logic cannot be replicated, until the whole hierarchy is replicated.
506 m_logicHierarchicalGameObjects.push_back(newobj);
507 //replicate controllers of this node
508 SGControllerList scenegraphcontrollers = orgobj->GetSGNode()->GetSGControllerList();
509 replicanode->RemoveAllControllers();
510 SGControllerList::iterator cit;
511 //int numcont = scenegraphcontrollers.size();
513 for (cit = scenegraphcontrollers.begin();!(cit==scenegraphcontrollers.end());++cit)
515 // controller replication is quite complicated
516 // only replicate ipo and physics controller for now
518 SG_Controller* replicacontroller = (*cit)->GetReplica((SG_Node*) replicanode);
519 if (replicacontroller)
521 replicacontroller->SetObject(replicanode);
522 replicanode->AddSGController(replicacontroller);
525 // replicate graphic controller
526 if (orgobj->GetGraphicController())
528 PHY_IMotionState* motionstate = new KX_MotionState(newobj->GetSGNode());
529 PHY_IGraphicController* newctrl = orgobj->GetGraphicController()->GetReplica(motionstate);
530 newctrl->setNewClientInfo(newobj->getClientInfo());
531 newobj->SetGraphicController(newctrl);
538 // before calling this method KX_Scene::ReplicateLogic(), make sure to
539 // have called 'GameObject::ReParentLogic' for each object this
540 // hierarchy that's because first ALL bricks must exist in the new
541 // replica of the hierarchy in order to make cross-links work properly
543 // It is VERY important that the order of sensors and actuators in
544 // the replicated object is preserved: it is used to reconnect the logic.
545 // This method is more robust then using the bricks name in case of complex
546 // group replication. The replication of logic bricks is done in
547 // SCA_IObject::ReParentLogic(), make sure it preserves the order of the bricks.
548 void KX_Scene::ReplicateLogic(KX_GameObject* newobj)
550 // also relink the controller to sensors/actuators
551 SCA_ControllerList& controllers = newobj->GetControllers();
552 //SCA_SensorList& sensors = newobj->GetSensors();
553 //SCA_ActuatorList& actuators = newobj->GetActuators();
555 for (SCA_ControllerList::iterator itc = controllers.begin(); !(itc==controllers.end());itc++)
557 SCA_IController* cont = (*itc);
558 cont->SetUeberExecutePriority(m_ueberExecutionPriority);
559 vector<SCA_ISensor*> linkedsensors = cont->GetLinkedSensors();
560 vector<SCA_IActuator*> linkedactuators = cont->GetLinkedActuators();
562 // disconnect the sensors and actuators
563 // do it directly on the list at this controller is not connected to anything at this stage
564 cont->GetLinkedSensors().clear();
565 cont->GetLinkedActuators().clear();
567 // now relink each sensor
568 for (vector<SCA_ISensor*>::iterator its = linkedsensors.begin();!(its==linkedsensors.end());its++)
570 SCA_ISensor* oldsensor = (*its);
571 SCA_IObject* oldsensorobj = oldsensor->GetParent();
572 SCA_IObject* newsensorobj = NULL;
574 // the original owner of the sensor has been replicated?
575 void **h_obj = m_map_gameobject_to_replica[oldsensorobj];
577 newsensorobj = (SCA_IObject*)(*h_obj);
580 // no, then the sensor points outside the hierachy, keep it the same
581 if (m_objectlist->SearchValue(oldsensorobj))
582 // only replicate links that points to active objects
583 m_logicmgr->RegisterToSensor(cont,oldsensor);
587 // yes, then the new sensor has the same position
588 SCA_SensorList& sensorlist = oldsensorobj->GetSensors();
589 SCA_SensorList::iterator sit;
590 SCA_ISensor* newsensor = NULL;
593 for (sensorpos=0, sit=sensorlist.begin(); sit!=sensorlist.end(); sit++, sensorpos++)
595 if ((*sit) == oldsensor)
597 newsensor = newsensorobj->GetSensors().at(sensorpos);
601 assert(newsensor != NULL);
602 m_logicmgr->RegisterToSensor(cont,newsensor);
606 // now relink each actuator
607 for (vector<SCA_IActuator*>::iterator ita = linkedactuators.begin();!(ita==linkedactuators.end());ita++)
609 SCA_IActuator* oldactuator = (*ita);
610 SCA_IObject* oldactuatorobj = oldactuator->GetParent();
611 SCA_IObject* newactuatorobj = NULL;
613 // the original owner of the sensor has been replicated?
614 void **h_obj = m_map_gameobject_to_replica[oldactuatorobj];
616 newactuatorobj = (SCA_IObject*)(*h_obj);
620 // no, then the sensor points outside the hierachy, keep it the same
621 if (m_objectlist->SearchValue(oldactuatorobj))
622 // only replicate links that points to active objects
623 m_logicmgr->RegisterToActuator(cont,oldactuator);
627 // yes, then the new sensor has the same position
628 SCA_ActuatorList& actuatorlist = oldactuatorobj->GetActuators();
629 SCA_ActuatorList::iterator ait;
630 SCA_IActuator* newactuator = NULL;
633 for (actuatorpos=0, ait=actuatorlist.begin(); ait!=actuatorlist.end(); ait++, actuatorpos++)
635 if ((*ait) == oldactuator)
637 newactuator = newactuatorobj->GetActuators().at(actuatorpos);
641 assert(newactuator != NULL);
642 m_logicmgr->RegisterToActuator(cont,newactuator);
643 newactuator->SetUeberExecutePriority(m_ueberExecutionPriority);
647 // ready to set initial state
648 newobj->ResetState();
651 void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
653 KX_GameObject* groupobj = (KX_GameObject*) obj;
654 KX_GameObject* replica;
655 KX_GameObject* gameobj;
656 Object* blgroupobj = groupobj->GetBlenderObject();
659 vector<KX_GameObject*> duplilist;
661 if (!groupobj->GetSGNode() ||
662 !groupobj->IsDupliGroup() ||
663 level>MAX_DUPLI_RECUR)
666 // we will add one group at a time
667 m_logicHierarchicalGameObjects.clear();
668 m_map_gameobject_to_replica.clear();
669 m_ueberExecutionPriority++;
670 // for groups will do something special:
671 // we will force the creation of objects to those in the group only
672 // Again, this is match what Blender is doing (it doesn't care of parent relationship)
673 m_groupGameObjects.clear();
675 group = blgroupobj->dup_group;
676 for(go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next)
678 Object* blenderobj = go->ob;
679 if (blgroupobj == blenderobj)
680 // this check is also in group_duplilist()
683 gameobj = (KX_GameObject*)m_logicmgr->FindGameObjByBlendObj(blenderobj);
686 // this object has not been converted!!!
687 // Should not happen as dupli group are created automatically
691 gameobj->SetBlenderGroupObject(blgroupobj);
693 if ((blenderobj->lay & group->layer)==0)
695 // object is not visible in the 3D view, will not be instantiated
698 m_groupGameObjects.insert(gameobj);
701 set<CValue*>::iterator oit;
702 for (oit=m_groupGameObjects.begin(); oit != m_groupGameObjects.end(); oit++)
704 gameobj = (KX_GameObject*)(*oit);
706 KX_GameObject *parent = gameobj->GetParent();
709 parent->Release(); // GetParent() increased the refcount
711 // this object is not a top parent. Either it is the child of another
712 // object in the group and it will be added automatically when the parent
713 // is added. Or it is the child of an object outside the group and the group
714 // is inconsistent, skip it anyway
717 replica = (KX_GameObject*) AddNodeReplicaObject(NULL,gameobj);
718 // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame)
719 m_parentlist->Add(replica->AddRef());
721 // recurse replication into children nodes
722 NodeList& children = gameobj->GetSGNode()->GetSGChildren();
724 replica->GetSGNode()->ClearSGChildren();
725 for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
727 SG_Node* orgnode = (*childit);
728 SG_Node* childreplicanode = orgnode->GetSGReplica();
729 if (childreplicanode)
730 replica->GetSGNode()->AddChild(childreplicanode);
732 // don't replicate logic now: we assume that the objects in the group can have
733 // logic relationship, even outside parent relationship
734 // In order to match 3D view, the position of groupobj is used as a
735 // transformation matrix instead of the new position. This means that
736 // the group reference point is 0,0,0
738 // get the rootnode's scale
739 MT_Vector3 newscale = groupobj->NodeGetWorldScaling();
740 // set the replica's relative scale with the rootnode's scale
741 replica->NodeSetRelativeScale(newscale);
743 MT_Point3 offset(group->dupli_ofs);
744 MT_Point3 newpos = groupobj->NodeGetWorldPosition() +
745 newscale*(groupobj->NodeGetWorldOrientation() * (gameobj->NodeGetWorldPosition()-offset));
746 replica->NodeSetLocalPosition(newpos);
747 // set the orientation after position for softbody!
748 MT_Matrix3x3 newori = groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldOrientation();
749 replica->NodeSetLocalOrientation(newori);
750 // update scenegraph for entire tree of children
751 replica->GetSGNode()->UpdateWorldData(0);
752 replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox());
753 replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius());
754 // we can now add the graphic controller to the physic engine
755 replica->ActivateGraphicController(true);
761 // the logic must be replicated first because we need
762 // the new logic bricks before relinking
763 vector<KX_GameObject*>::iterator git;
764 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
766 (*git)->ReParentLogic();
769 // relink any pointers as necessary, sort of a temporary solution
770 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
772 // this will also relink the actuator to objects within the hierarchy
773 (*git)->Relink(&m_map_gameobject_to_replica);
774 // add the object in the layer of the parent
775 (*git)->SetLayer(groupobj->GetLayer());
776 // If the object was a light, we need to update it's RAS_LightObject as well
777 if ((*git)->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
779 KX_LightObject* lightobj = static_cast<KX_LightObject*>(*git);
780 lightobj->GetLightData()->m_layer = groupobj->GetLayer();
784 // replicate crosslinks etc. between logic bricks
785 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
787 ReplicateLogic((*git));
790 // now look if object in the hierarchy have dupli group and recurse
791 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
793 if ((*git) != groupobj && (*git)->IsDupliGroup())
794 // can't instantiate group immediately as it destroys m_logicHierarchicalGameObjects
795 duplilist.push_back((*git));
798 for (git = duplilist.begin(); !(git == duplilist.end()); ++git)
800 DupliGroupRecurse((*git), level+1);
805 SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
806 class CValue* parentobject,
810 m_logicHierarchicalGameObjects.clear();
811 m_map_gameobject_to_replica.clear();
812 m_groupGameObjects.clear();
814 // todo: place a timebomb in the object, for temporarily objects :)
815 // lifespan of zero means 'this object lives forever'
816 KX_GameObject* originalobj = (KX_GameObject*) originalobject;
817 KX_GameObject* parentobj = (KX_GameObject*) parentobject;
819 m_ueberExecutionPriority++;
821 // lets create a replica
822 KX_GameObject* replica = (KX_GameObject*) AddNodeReplicaObject(NULL,originalobj);
826 // add a timebomb to this object
827 // for now, convert between so called frames and realtime
828 m_tempObjectList->Add(replica->AddRef());
829 // this convert the life from frames to sort-of seconds, hard coded 0.02 that assumes we have 50 frames per second
830 // if you change this value, make sure you change it in KX_GameObject::pyattr_get_life property too
831 CValue *fval = new CFloatValue(lifespan*0.02);
832 replica->SetProperty("::timebomb",fval);
836 // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame)
837 m_parentlist->Add(replica->AddRef());
839 // recurse replication into children nodes
841 NodeList& children = originalobj->GetSGNode()->GetSGChildren();
843 replica->GetSGNode()->ClearSGChildren();
844 for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
846 SG_Node* orgnode = (*childit);
847 SG_Node* childreplicanode = orgnode->GetSGReplica();
848 if (childreplicanode)
849 replica->GetSGNode()->AddChild(childreplicanode);
852 // At this stage all the objects in the hierarchy have been duplicated,
853 // we can update the scenegraph, we need it for the duplication of logic
854 MT_Point3 newpos = ((KX_GameObject*) parentobject)->NodeGetWorldPosition();
855 replica->NodeSetLocalPosition(newpos);
857 MT_Matrix3x3 newori = ((KX_GameObject*) parentobject)->NodeGetWorldOrientation();
858 replica->NodeSetLocalOrientation(newori);
860 // get the rootnode's scale
861 MT_Vector3 newscale = parentobj->GetSGNode()->GetRootSGParent()->GetLocalScale();
863 // set the replica's relative scale with the rootnode's scale
864 replica->NodeSetRelativeScale(newscale);
866 replica->GetSGNode()->UpdateWorldData(0);
867 replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox());
868 replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius());
869 // the size is correct, we can add the graphic controller to the physic engine
870 replica->ActivateGraphicController(true);
872 // now replicate logic
873 vector<KX_GameObject*>::iterator git;
874 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
876 (*git)->ReParentLogic();
879 // relink any pointers as necessary, sort of a temporary solution
880 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
882 // this will also relink the actuators in the hierarchy
883 (*git)->Relink(&m_map_gameobject_to_replica);
884 // add the object in the layer of the parent
885 (*git)->SetLayer(parentobj->GetLayer());
886 // If the object was a light, we need to update it's RAS_LightObject as well
887 if ((*git)->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
889 KX_LightObject* lightobj = static_cast<KX_LightObject*>(*git);
890 lightobj->GetLightData()->m_layer = parentobj->GetLayer();
894 // replicate crosslinks etc. between logic bricks
895 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
897 ReplicateLogic((*git));
900 // check if there are objects with dupligroup in the hierarchy
901 vector<KX_GameObject*> duplilist;
902 for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
904 if ((*git)->IsDupliGroup())
906 // separate list as m_logicHierarchicalGameObjects is also used by DupliGroupRecurse()
907 duplilist.push_back(*git);
910 for (git = duplilist.begin();!(git==duplilist.end());++git)
912 DupliGroupRecurse(*git, 0);
914 // don't release replica here because we are returning it, not done with it...
920 void KX_Scene::RemoveObject(class CValue* gameobj)
922 KX_GameObject* newobj = (KX_GameObject*) gameobj;
924 // disconnect child from parent
925 SG_Node* node = newobj->GetSGNode();
929 node->DisconnectFromParent();
931 // recursively destruct
934 //no need to do that: the object is destroyed and memory released
935 //newobj->SetSGNode(0);
938 void KX_Scene::DelayedRemoveObject(class CValue* gameobj)
940 //KX_GameObject* newobj = (KX_GameObject*) gameobj;
941 if (!m_euthanasyobjects->SearchValue(gameobj))
943 m_euthanasyobjects->Add(gameobj->AddRef());
949 int KX_Scene::NewRemoveObject(class CValue* gameobj)
952 KX_GameObject* newobj = (KX_GameObject*) gameobj;
954 /* Invalidate the python reference, since the object may exist in script lists
955 * its possible that it wont be automatically invalidated, so do it manually here,
957 * if for some reason the object is added back into the scene python can always get a new Proxy
959 newobj->InvalidateProxy();
961 // keep the blender->game object association up to date
962 // note that all the replicas of an object will have the same
963 // blender object, that's why we need to check the game object
964 // as only the deletion of the original object must be recorded
965 m_logicmgr->UnregisterGameObj(newobj->GetBlenderObject(), gameobj);
968 //GetPhysicsEnvironment()->RemovePhysicsController(gameobj->getPhysicsController());
970 // remove all sensors/controllers/actuators from logicsystem...
972 SCA_SensorList& sensors = newobj->GetSensors();
973 for (SCA_SensorList::iterator its = sensors.begin();
974 !(its==sensors.end());its++)
976 m_logicmgr->RemoveSensor(*its);
979 SCA_ControllerList& controllers = newobj->GetControllers();
980 for (SCA_ControllerList::iterator itc = controllers.begin();
981 !(itc==controllers.end());itc++)
983 m_logicmgr->RemoveController(*itc);
986 SCA_ActuatorList& actuators = newobj->GetActuators();
987 for (SCA_ActuatorList::iterator ita = actuators.begin();
988 !(ita==actuators.end());ita++)
990 m_logicmgr->RemoveActuator(*ita);
992 // the sensors/controllers/actuators must also be released, this is done in ~SCA_IObject
994 // now remove the timer properties from the time manager
995 int numprops = newobj->GetPropertyCount();
997 for (int i = 0; i < numprops; i++)
999 CValue* propval = newobj->GetProperty(i);
1000 if (propval->GetProperty("timer"))
1002 m_timemgr->RemoveTimeProperty(propval);
1006 newobj->RemoveMeshes();
1008 if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT && m_lightlist->RemoveValue(newobj))
1009 ret = newobj->Release();
1010 if (m_objectlist->RemoveValue(newobj))
1011 ret = newobj->Release();
1012 if (m_tempObjectList->RemoveValue(newobj))
1013 ret = newobj->Release();
1014 if (m_parentlist->RemoveValue(newobj))
1015 ret = newobj->Release();
1016 if (m_inactivelist->RemoveValue(newobj))
1017 ret = newobj->Release();
1018 if (m_euthanasyobjects->RemoveValue(newobj))
1019 ret = newobj->Release();
1021 if (newobj == m_active_camera)
1023 //no AddRef done on m_active_camera so no Release
1024 //m_active_camera->Release();
1025 m_active_camera = NULL;
1028 // in case this is a camera
1029 m_cameras.remove((KX_Camera*)newobj);
1031 // in case this is a font
1032 m_fonts.remove((KX_FontObject*)newobj);
1034 /* currently does nothing, keep incase we need to Unregister something */
1036 if (m_sceneConverter)
1037 m_sceneConverter->UnregisterGameObject(newobj);
1040 // return value will be 0 if the object is actually deleted (all reference gone)
1047 void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj, bool use_gfx, bool use_phys)
1049 KX_GameObject* gameobj = static_cast<KX_GameObject*>(obj);
1050 RAS_MeshObject* mesh = static_cast<RAS_MeshObject*>(meshobj);
1053 std::cout << "KX_Scene::ReplaceMesh Warning: invalid object, doing nothing" << std::endl;
1057 if(use_gfx && mesh != NULL)
1059 gameobj->RemoveMeshes();
1060 gameobj->AddMesh(mesh);
1062 if (gameobj->m_isDeformable)
1064 BL_DeformableGameObject* newobj = static_cast<BL_DeformableGameObject*>( gameobj );
1066 if (newobj->GetDeformer())
1068 delete newobj->GetDeformer();
1069 newobj->SetDeformer(NULL);
1072 if (mesh->GetMesh())
1074 // we must create a new deformer but which one?
1075 KX_GameObject* parentobj = newobj->GetParent();
1076 // this always return the original game object (also for replicate)
1077 Object* blendobj = newobj->GetBlenderObject();
1078 // object that owns the new mesh
1079 Object* oldblendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName()));
1080 Mesh* blendmesh = mesh->GetMesh();
1082 bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(blendobj);
1083 bool bHasShapeKey = blendmesh->key != NULL && blendmesh->key->type==KEY_RELATIVE;
1084 bool bHasDvert = blendmesh->dvert != NULL;
1086 BL_ModifierDeformer::HasArmatureDeformer(blendobj) &&
1087 parentobj && // current parent is armature
1088 parentobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE &&
1089 oldblendobj && // needed for mesh deform
1090 blendobj->parent && // original object had armature (not sure this test is needed)
1091 blendobj->parent->type == OB_ARMATURE &&
1092 blendmesh->dvert!=NULL; // mesh has vertex group
1094 bool bHasSoftBody = (!parentobj && (blendobj->gameflag & OB_SOFT_BODY));
1096 bool releaseParent = true;
1099 if (oldblendobj==NULL) {
1100 if (bHasModifier || bHasShapeKey || bHasDvert || bHasArmature) {
1101 std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl;
1102 bHasShapeKey= bHasDvert= bHasArmature=bHasModifier= false;
1108 BL_ModifierDeformer* modifierDeformer;
1109 if (bHasShapeKey || bHasArmature)
1111 modifierDeformer = new BL_ModifierDeformer(
1114 oldblendobj, blendobj,
1117 static_cast<BL_ArmatureObject*>( parentobj )
1119 releaseParent= false;
1120 modifierDeformer->LoadShapeDrivers(blendobj->parent);
1124 modifierDeformer = new BL_ModifierDeformer(
1127 oldblendobj, blendobj,
1133 newobj->SetDeformer(modifierDeformer);
1135 else if (bHasShapeKey)
1137 BL_ShapeDeformer* shapeDeformer;
1140 shapeDeformer = new BL_ShapeDeformer(
1142 oldblendobj, blendobj,
1146 static_cast<BL_ArmatureObject*>( parentobj )
1148 releaseParent= false;
1149 shapeDeformer->LoadShapeDrivers(blendobj->parent);
1153 shapeDeformer = new BL_ShapeDeformer(
1155 oldblendobj, blendobj,
1162 newobj->SetDeformer( shapeDeformer);
1164 else if (bHasArmature)
1166 BL_SkinDeformer* skinDeformer = new BL_SkinDeformer(
1168 oldblendobj, blendobj,
1172 static_cast<BL_ArmatureObject*>( parentobj )
1174 releaseParent= false;
1175 newobj->SetDeformer(skinDeformer);
1179 BL_MeshDeformer* meshdeformer = new BL_MeshDeformer(
1180 newobj, oldblendobj, mesh
1182 newobj->SetDeformer(meshdeformer);
1185 else if (bHasSoftBody)
1187 KX_SoftBodyDeformer *softdeformer = new KX_SoftBodyDeformer(mesh, newobj);
1188 newobj->SetDeformer(softdeformer);
1192 // release parent reference if its not being used
1193 if( releaseParent && parentobj)
1194 parentobj->Release();
1198 gameobj->AddMeshUser();
1202 if(use_phys) { /* update the new assigned mesh with the physics mesh */
1203 KX_ReInstanceBulletShapeFromMesh(gameobj, NULL, use_gfx?NULL:mesh);
1208 /* Font Object routines */
1209 void KX_Scene::AddFont(KX_FontObject* font)
1211 if (!FindFont(font))
1212 m_fonts.push_back(font);
1215 KX_FontObject* KX_Scene::FindFont(KX_FontObject* font)
1217 list<KX_FontObject*>::iterator it = m_fonts.begin();
1219 while ( (it != m_fonts.end())
1220 && ((*it) != font) ) {
1224 return ((it == m_fonts.end()) ? NULL : (*it));
1228 /* Camera Object routines */
1229 KX_Camera* KX_Scene::FindCamera(KX_Camera* cam)
1231 list<KX_Camera*>::iterator it = m_cameras.begin();
1233 while ( (it != m_cameras.end())
1234 && ((*it) != cam) ) {
1238 return ((it == m_cameras.end()) ? NULL : (*it));
1242 KX_Camera* KX_Scene::FindCamera(STR_String& name)
1244 list<KX_Camera*>::iterator it = m_cameras.begin();
1246 while ( (it != m_cameras.end())
1247 && ((*it)->GetName() != name) ) {
1251 return ((it == m_cameras.end()) ? NULL : (*it));
1254 void KX_Scene::AddCamera(KX_Camera* cam)
1256 if (!FindCamera(cam))
1257 m_cameras.push_back(cam);
1261 KX_Camera* KX_Scene::GetActiveCamera()
1263 // NULL if not defined
1264 return m_active_camera;
1268 void KX_Scene::SetActiveCamera(KX_Camera* cam)
1270 // only set if the cam is in the active list? Or add it otherwise?
1271 if (!FindCamera(cam)){
1273 if (cam) std::cout << "Added cam " << cam->GetName() << std::endl;
1276 m_active_camera = cam;
1279 void KX_Scene::SetCameraOnTop(KX_Camera* cam)
1281 if (!FindCamera(cam)){
1282 // adding is always done at the back, so that's all that needs to be done
1284 if (cam) std::cout << "Added cam " << cam->GetName() << std::endl;
1286 m_cameras.remove(cam);
1287 m_cameras.push_back(cam);
1292 void KX_Scene::UpdateMeshTransformations()
1294 // do this incrementally in the future
1295 for (int i = 0; i < m_objectlist->GetCount(); i++)
1297 KX_GameObject* gameobj = (KX_GameObject*)m_objectlist->GetValue(i);
1298 gameobj->GetOpenGLMatrix();
1302 void KX_Scene::MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera* cam, int layer)
1304 int intersect = KX_Camera::INTERSECT;
1305 KX_GameObject *gameobj = node->Client()?(KX_GameObject*) node->Client()->GetSGClientObject():NULL;
1306 bool visible = (gameobj && gameobj->GetVisible() && (!layer || (gameobj->GetLayer() & layer)));
1307 bool dotest = visible || node->Left() || node->Right();
1309 /* If the camera is inside the box, assume intersect. */
1310 if (dotest && !node->inside( cam->NodeGetWorldPosition()))
1312 MT_Scalar radius = node->Radius();
1313 MT_Point3 center = node->Center();
1315 intersect = cam->SphereInsideFrustum(center, radius);
1317 if (intersect == KX_Camera::INTERSECT)
1321 intersect = cam->BoxInsideFrustum(box);
1327 case KX_Camera::OUTSIDE:
1328 MarkSubTreeVisible(node, rasty, false, cam);
1330 case KX_Camera::INTERSECT:
1332 MarkVisible(rasty, gameobj, cam, layer);
1334 MarkVisible(node->Left(), rasty, cam, layer);
1336 MarkVisible(node->Right(), rasty, cam, layer);
1338 case KX_Camera::INSIDE:
1339 MarkSubTreeVisible(node, rasty, true, cam, layer);
1344 void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible, KX_Camera* cam, int layer)
1348 KX_GameObject *gameobj = (KX_GameObject*) node->Client()->GetSGClientObject();
1349 if (gameobj->GetVisible())
1353 int nummeshes = gameobj->GetMeshCount();
1355 // this adds the vertices to the display list
1356 for (int m=0;m<nummeshes;m++)
1357 (gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode());
1360 gameobj->SetCulled(!visible);
1361 gameobj->UpdateBuckets(false);
1365 MarkSubTreeVisible(node->Left(), rasty, visible, cam, layer);
1367 MarkSubTreeVisible(node->Right(), rasty, visible, cam, layer);
1370 void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj,KX_Camera* cam,int layer)
1372 // User (Python/Actuator) has forced object invisible...
1373 if (!gameobj->GetSGNode() || !gameobj->GetVisible())
1376 // Shadow lamp layers
1377 if(layer && !(gameobj->GetLayer() & layer)) {
1378 gameobj->SetCulled(true);
1379 gameobj->UpdateBuckets(false);
1383 // If Frustum culling is off, the object is always visible.
1384 bool vis = !cam->GetFrustumCulling();
1386 // If the camera is inside this node, then the object is visible.
1389 vis = gameobj->GetSGNode()->inside( cam->GetCameraLocation() );
1392 // Test the object's bound sphere against the view frustum.
1395 MT_Vector3 scale = gameobj->GetSGNode()->GetWorldScaling();
1396 MT_Scalar radius = fabs(scale[scale.closestAxis()] * gameobj->GetSGNode()->Radius());
1397 switch (cam->SphereInsideFrustum(gameobj->NodeGetWorldPosition(), radius))
1399 case KX_Camera::INSIDE:
1402 case KX_Camera::OUTSIDE:
1405 case KX_Camera::INTERSECT:
1406 // Test the object's bound box against the view frustum.
1408 gameobj->GetSGNode()->getBBox(box);
1409 vis = cam->BoxInsideFrustum(box) != KX_Camera::OUTSIDE;
1416 int nummeshes = gameobj->GetMeshCount();
1418 for (int m=0;m<nummeshes;m++)
1420 // this adds the vertices to the display list
1421 (gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode());
1423 // Visibility/ non-visibility are marked
1425 gameobj->SetCulled(false);
1426 gameobj->UpdateBuckets(false);
1428 gameobj->SetCulled(true);
1429 gameobj->UpdateBuckets(false);
1433 void KX_Scene::PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo)
1435 KX_GameObject* gameobj = objectInfo->m_gameobject;
1436 if (!gameobj->GetVisible())
1437 // ideally, invisible objects should be removed from the culling tree temporarily
1439 if(((CullingInfo*)cullingInfo)->m_layer && !(gameobj->GetLayer() & ((CullingInfo*)cullingInfo)->m_layer))
1440 // used for shadow: object is not in shadow layer
1443 // make object visible
1444 gameobj->SetCulled(false);
1445 gameobj->UpdateBuckets(false);
1448 void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty,KX_Camera* cam, int layer)
1450 bool dbvt_culling = false;
1453 // test culling through Bullet
1454 PHY__Vector4 planes[6];
1455 // get the clip planes
1456 MT_Vector4* cplanes = cam->GetNormalizedClipPlanes();
1458 planes[0].setValue(cplanes[4].getValue()); // near
1459 planes[1].setValue(cplanes[5].getValue()); // far
1460 planes[2].setValue(cplanes[0].getValue()); // left
1461 planes[3].setValue(cplanes[1].getValue()); // right
1462 planes[4].setValue(cplanes[2].getValue()); // top
1463 planes[5].setValue(cplanes[3].getValue()); // bottom
1464 CullingInfo info(layer);
1465 dbvt_culling = m_physicsEnvironment->cullingTest(PhysicsCullingCallback,&info,planes,5,m_dbvt_occlusion_res);
1467 if (!dbvt_culling) {
1468 // the physics engine couldn't help us, do it the hard way
1469 for (int i = 0; i < m_objectlist->GetCount(); i++)
1471 MarkVisible(rasty, static_cast<KX_GameObject*>(m_objectlist->GetValue(i)), cam, layer);
1477 void KX_Scene::LogicBeginFrame(double curtime)
1479 // have a look at temp objects ...
1480 int lastobj = m_tempObjectList->GetCount() - 1;
1482 for (int i = lastobj; i >= 0; i--)
1484 CValue* objval = m_tempObjectList->GetValue(i);
1485 CFloatValue* propval = (CFloatValue*) objval->GetProperty("::timebomb");
1489 float timeleft = propval->GetNumber() - 1.0/KX_KetsjiEngine::GetTicRate();
1493 propval->SetFloat(timeleft);
1497 DelayedRemoveObject(objval);
1503 // all object is the tempObjectList should have a clock
1506 m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate());
1509 void KX_Scene::AddAnimatedObject(CValue* gameobj)
1511 m_animatedlist->Add(gameobj);
1514 void KX_Scene::RemoveAnimatedObject(CValue* gameobj)
1516 m_animatedlist->RemoveValue(gameobj);
1519 void KX_Scene::UpdateAnimations(double curtime)
1521 // Update any animations
1522 for (int i=0; i<m_animatedlist->GetCount(); ++i)
1523 ((KX_GameObject*)GetObjectList()->GetValue(i))->UpdateActionManager(curtime);
1526 void KX_Scene::LogicUpdateFrame(double curtime, bool frame)
1528 m_logicmgr->UpdateFrame(curtime, frame);
1533 void KX_Scene::LogicEndFrame()
1535 m_logicmgr->EndFrame();
1540 while ((numobj = m_euthanasyobjects->GetCount()) > 0)
1542 // remove the object from this list to make sure we will not hit it again
1543 obj = (KX_GameObject*)m_euthanasyobjects->GetValue(numobj-1);
1544 m_euthanasyobjects->Remove(numobj-1);
1553 * UpdateParents: SceneGraph transformation update.
1555 void KX_Scene::UpdateParents(double curtime)
1557 // we use the SG dynamic list
1560 while ((node = SG_Node::GetNextScheduled(m_sghead)) != NULL)
1562 node->UpdateWorldData(curtime);
1565 //for (int i=0; i<GetRootParentList()->GetCount(); i++)
1567 // KX_GameObject* parentobj = (KX_GameObject*)GetRootParentList()->GetValue(i);
1568 // parentobj->NodeUpdateGS(curtime);
1571 // the list must be empty here
1572 assert(m_sghead.Empty());
1573 // some nodes may be ready for reschedule, move them to schedule list for next time
1574 while ((node = SG_Node::GetNextRescheduled(m_sghead)) != NULL)
1576 node->Schedule(m_sghead);
1581 RAS_MaterialBucket* KX_Scene::FindBucket(class RAS_IPolyMaterial* polymat, bool &bucketCreated)
1583 return m_bucketmanager->FindBucket(polymat, bucketCreated);
1588 void KX_Scene::RenderBuckets(const MT_Transform & cameratransform,
1589 class RAS_IRasterizer* rasty,
1590 class RAS_IRenderTools* rendertools)
1592 m_bucketmanager->Renderbuckets(cameratransform,rasty,rendertools);
1593 KX_BlenderMaterial::EndFrame();
1596 void KX_Scene::UpdateObjectActivity(void)
1598 if (m_activity_culling) {
1599 /* determine the activity criterium and set objects accordingly */
1602 MT_Point3 camloc = GetActiveCamera()->NodeGetWorldPosition(); //GetCameraLocation();
1604 for (i=0;i<GetObjectList()->GetCount();i++)
1606 KX_GameObject* ob = (KX_GameObject*) GetObjectList()->GetValue(i);
1608 if (!ob->GetIgnoreActivityCulling()) {
1609 /* Simple test: more than 10 away from the camera, count
1610 * Manhattan distance. */
1611 MT_Point3 obpos = ob->NodeGetWorldPosition();
1613 if ( (fabs(camloc[0] - obpos[0]) > m_activity_box_radius)
1614 || (fabs(camloc[1] - obpos[1]) > m_activity_box_radius)
1615 || (fabs(camloc[2] - obpos[2]) > m_activity_box_radius) )
1626 void KX_Scene::SetActivityCullingRadius(float f)
1630 m_activity_box_radius = f;
1633 NG_NetworkDeviceInterface* KX_Scene::GetNetworkDeviceInterface()
1635 return m_networkDeviceInterface;
1638 NG_NetworkScene* KX_Scene::GetNetworkScene()
1640 return m_networkScene;
1643 void KX_Scene::SetNetworkDeviceInterface(NG_NetworkDeviceInterface* newInterface)
1645 m_networkDeviceInterface = newInterface;
1648 void KX_Scene::SetNetworkScene(NG_NetworkScene *newScene)
1650 m_networkScene = newScene;
1654 void KX_Scene::SetGravity(const MT_Vector3& gravity)
1656 GetPhysicsEnvironment()->setGravity(gravity[0],gravity[1],gravity[2]);
1659 void KX_Scene::SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter)
1661 m_sceneConverter = sceneConverter;
1664 void KX_Scene::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv)
1666 m_physicsEnvironment = physEnv;
1667 if(m_physicsEnvironment) {
1668 KX_TouchEventManager* touchmgr = new KX_TouchEventManager(m_logicmgr, physEnv);
1669 m_logicmgr->RegisterEventManager(touchmgr);
1673 void KX_Scene::setSuspendedTime(double suspendedtime)
1675 m_suspendedtime = suspendedtime;
1677 double KX_Scene::getSuspendedTime()
1679 return m_suspendedtime;
1681 void KX_Scene::setSuspendedDelta(double suspendeddelta)
1683 m_suspendeddelta = suspendeddelta;
1685 double KX_Scene::getSuspendedDelta()
1687 return m_suspendeddelta;
1690 short KX_Scene::GetAnimationFPS()
1692 return m_blenderScene->r.frs_sec;
1696 #include "KX_BulletPhysicsController.h"
1699 static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to)
1701 SCA_LogicManager *logicmgr= to->GetLogicManager();
1703 brick->Replace_IScene(to);
1704 brick->Replace_NetworkScene(to->GetNetworkScene());
1706 SCA_ISensor *sensor= dynamic_cast<class SCA_ISensor *>(brick);
1708 sensor->Replace_EventManager(logicmgr);
1711 /* near sensors have physics controllers */
1713 KX_TouchSensor *touch_sensor = dynamic_cast<class KX_TouchSensor *>(brick);
1715 touch_sensor->GetPhysicsController()->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
1721 #include "CcdGraphicController.h" // XXX ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
1722 #include "CcdPhysicsEnvironment.h" // XXX ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
1723 #include "KX_BulletPhysicsController.h"
1726 static void MergeScene_GameObject(KX_GameObject* gameobj, KX_Scene *to, KX_Scene *from)
1729 SCA_ActuatorList& actuators= gameobj->GetActuators();
1730 SCA_ActuatorList::iterator ita;
1732 for (ita = actuators.begin(); !(ita==actuators.end()); ++ita)
1734 MergeScene_LogicBrick(*ita, to);
1740 SCA_SensorList& sensors= gameobj->GetSensors();
1741 SCA_SensorList::iterator its;
1743 for (its = sensors.begin(); !(its==sensors.end()); ++its)
1745 MergeScene_LogicBrick(*its, to);
1750 SCA_ControllerList& controllers= gameobj->GetControllers();
1751 SCA_ControllerList::iterator itc;
1753 for (itc = controllers.begin(); !(itc==controllers.end()); ++itc)
1755 SCA_IController *cont= *itc;
1756 MergeScene_LogicBrick(cont, to);
1758 vector<SCA_ISensor*> linkedsensors = cont->GetLinkedSensors();
1759 vector<SCA_IActuator*> linkedactuators = cont->GetLinkedActuators();
1761 for (vector<SCA_IActuator*>::iterator ita = linkedactuators.begin();!(ita==linkedactuators.end());++ita) {
1762 MergeScene_LogicBrick(*ita, to);
1765 for (vector<SCA_ISensor*>::iterator its = linkedsensors.begin();!(its==linkedsensors.end());++its) {
1766 MergeScene_LogicBrick(*its, to);
1771 /* graphics controller */
1772 PHY_IGraphicController *ctrl = gameobj->GetGraphicController();
1774 /* SHOULD update the m_cullingTree */
1775 ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
1778 /* SG_Node can hold a scene reference */
1779 SG_Node *sg= gameobj->GetSGNode();
1781 if(sg->GetSGClientInfo() == from) {
1782 sg->SetSGClientInfo(to);
1784 /* Make sure to grab the children too since they might not be tied to a game object */
1785 NodeList children = sg->GetSGChildren();
1786 for (int i=0; i<children.size(); i++)
1787 children[i]->SetSGClientInfo(to);
1790 SGControllerList::iterator contit;
1791 SGControllerList& controllers = sg->GetSGControllerList();
1792 for (contit = controllers.begin();contit!=controllers.end();++contit)
1794 KX_BulletPhysicsController *phys_ctrl= dynamic_cast<KX_BulletPhysicsController *>(*contit);
1796 phys_ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
1798 #endif // USE_BULLET
1800 /* If the object is a light, update it's scene */
1801 if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT)
1802 ((KX_LightObject*)gameobj)->UpdateScene(to);
1804 /* Add the object to the scene's logic manager */
1805 to->GetLogicManager()->RegisterGameObjectName(gameobj->GetName(), gameobj);
1806 to->GetLogicManager()->RegisterGameObj(gameobj->GetBlenderObject(), gameobj);
1808 for (int i=0; i<gameobj->GetMeshCount(); ++i)
1809 to->GetLogicManager()->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), gameobj->GetBlenderObject());
1812 bool KX_Scene::MergeScene(KX_Scene *other)
1815 CcdPhysicsEnvironment *env= dynamic_cast<CcdPhysicsEnvironment *>(this->GetPhysicsEnvironment());
1816 CcdPhysicsEnvironment *env_other= dynamic_cast<CcdPhysicsEnvironment *>(other->GetPhysicsEnvironment());
1818 if((env==NULL) != (env_other==NULL)) /* TODO - even when both scenes have NONE physics, the other is loaded with bullet enabled, ??? */
1820 printf("KX_Scene::MergeScene: physics scenes type differ, aborting\n");
1821 printf("\tsource %d, terget %d\n", (int)(env!=NULL), (int)(env_other!=NULL));
1824 #endif // USE_BULLET
1826 if(GetSceneConverter() != other->GetSceneConverter()) {
1827 printf("KX_Scene::MergeScene: converters differ, aborting\n");
1832 GetBucketManager()->MergeBucketManager(other->GetBucketManager(), this);
1834 /* move materials across, assume they both use the same scene-converters */
1835 GetSceneConverter()->MergeScene(this, other);
1837 /* active + inactive == all ??? - lets hope so */
1838 for (int i = 0; i < other->GetObjectList()->GetCount(); i++)
1840 KX_GameObject* gameobj = (KX_GameObject*)other->GetObjectList()->GetValue(i);
1841 MergeScene_GameObject(gameobj, this, other);
1843 gameobj->UpdateBuckets(false); /* only for active objects */
1846 for (int i = 0; i < other->GetInactiveList()->GetCount(); i++)
1848 KX_GameObject* gameobj = (KX_GameObject*)other->GetInactiveList()->GetValue(i);
1849 MergeScene_GameObject(gameobj, this, other);
1852 GetTempObjectList()->MergeList(other->GetTempObjectList());
1853 other->GetTempObjectList()->ReleaseAndRemoveAll();
1855 GetObjectList()->MergeList(other->GetObjectList());
1856 other->GetObjectList()->ReleaseAndRemoveAll();
1858 GetInactiveList()->MergeList(other->GetInactiveList());
1859 other->GetInactiveList()->ReleaseAndRemoveAll();
1861 GetRootParentList()->MergeList(other->GetRootParentList());
1862 other->GetRootParentList()->ReleaseAndRemoveAll();
1864 GetLightList()->MergeList(other->GetLightList());
1865 other->GetLightList()->ReleaseAndRemoveAll();
1868 if(env) /* bullet scene? - dummy scenes dont need touching */
1869 env->MergeEnvironment(env_other);
1874 SCA_LogicManager *logicmgr= GetLogicManager();
1875 SCA_LogicManager *logicmgr_other= other->GetLogicManager();
1877 vector<class SCA_EventManager*>evtmgrs= logicmgr->GetEventManagers();
1878 //vector<class SCA_EventManager*>evtmgrs_others= logicmgr_other->GetEventManagers();
1880 //SCA_EventManager *evtmgr;
1881 SCA_EventManager *evtmgr_other;
1883 for(unsigned int i= 0; i < evtmgrs.size(); i++) {
1884 evtmgr_other= logicmgr_other->FindEventManager(evtmgrs[i]->GetType());
1886 if(evtmgr_other) /* unlikely but possible one scene has a joystick and not the other */
1887 evtmgr_other->Replace_LogicManager(logicmgr);
1889 /* when merging objects sensors are moved across into the new manager, dont need to do this here */
1892 /* grab any timer properties from the other scene */
1893 SCA_TimeEventManager *timemgr= GetTimeEventManager();
1894 SCA_TimeEventManager *timemgr_other= other->GetTimeEventManager();
1895 vector<CValue*> times = timemgr_other->GetTimeValues();
1897 for(unsigned int i= 0; i < times.size(); i++) {
1898 timemgr->AddTimeProperty(times[i]);
1905 void KX_Scene::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
1907 m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
1910 void KX_Scene::Render2DFilters(RAS_ICanvas* canvas)
1912 m_filtermanager.RenderFilters(canvas);
1917 void KX_Scene::RunDrawingCallbacks(PyObject* cb_list)
1921 if (cb_list && (len=PyList_GET_SIZE(cb_list)))
1923 PyObject* args= PyTuple_New(0); // save python creating each call
1927 // Iterate the list and run the callbacks
1928 for (Py_ssize_t pos=0; pos < len; pos++)
1930 func= PyList_GET_ITEM(cb_list, pos);
1931 ret= PyObject_Call(func, args, NULL);
1945 //----------------------------------------------------------------------------
1948 PyTypeObject KX_Scene::Type = {
1949 PyVarObject_HEAD_INIT(NULL, 0)
1951 sizeof(PyObjectPlus_Proxy),
1963 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1973 PyMethodDef KX_Scene::Methods[] = {
1974 KX_PYMETHODTABLE(KX_Scene, addObject),
1975 KX_PYMETHODTABLE(KX_Scene, end),
1976 KX_PYMETHODTABLE(KX_Scene, restart),
1977 KX_PYMETHODTABLE(KX_Scene, replace),
1978 KX_PYMETHODTABLE(KX_Scene, suspend),
1979 KX_PYMETHODTABLE(KX_Scene, resume),
1981 /* dict style access */
1982 KX_PYMETHODTABLE(KX_Scene, get),
1984 {NULL,NULL} //Sentinel
1986 static PyObject *Map_GetItem(PyObject *self_v, PyObject *item)
1988 KX_Scene* self= static_cast<KX_Scene*>BGE_PROXY_REF(self_v);
1989 const char *attr_str= _PyUnicode_AsString(item);
1990 PyObject* pyconvert;
1993 PyErr_SetString(PyExc_SystemError, "val = scene[key]: KX_Scene, "BGE_PROXY_ERROR_MSG);
1997 if (self->m_attr_dict && (pyconvert=PyDict_GetItem(self->m_attr_dict, item))) {
2001 Py_INCREF(pyconvert);
2005 if(attr_str) PyErr_Format(PyExc_KeyError, "value = scene[key]: KX_Scene, key \"%s\" does not exist", attr_str);
2006 else PyErr_SetString(PyExc_KeyError, "value = scene[key]: KX_Scene, key does not exist");
2012 static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val)
2014 KX_Scene* self= static_cast<KX_Scene*>BGE_PROXY_REF(self_v);
2015 const char *attr_str= _PyUnicode_AsString(key);
2020 PyErr_SetString(PyExc_SystemError, "scene[key] = value: KX_Scene, "BGE_PROXY_ERROR_MSG);
2024 if (val==NULL) { /* del ob["key"] */
2027 if(self->m_attr_dict)
2028 del |= (PyDict_DelItem(self->m_attr_dict, key)==0) ? 1:0;
2031 if(attr_str) PyErr_Format(PyExc_KeyError, "scene[key] = value: KX_Scene, key \"%s\" could not be set", attr_str);
2032 else PyErr_SetString(PyExc_KeyError, "del scene[key]: KX_Scene, key could not be deleted");
2035 else if (self->m_attr_dict) {
2036 PyErr_Clear(); /* PyDict_DelItem sets an error when it fails */
2039 else { /* ob["key"] = value */
2042 if (self->m_attr_dict==NULL) /* lazy init */
2043 self->m_attr_dict= PyDict_New();
2046 if(PyDict_SetItem(self->m_attr_dict, key, val)==0)
2049 PyErr_SetString(PyExc_KeyError, "scene[key] = value: KX_Scene, key not be added to internal dictionary");
2052 return -1; /* pythons error value */
2056 return 0; /* success */
2059 static int Seq_Contains(PyObject *self_v, PyObject *value)
2061 KX_Scene* self= static_cast<KX_Scene*>BGE_PROXY_REF(self_v);
2064 PyErr_SetString(PyExc_SystemError, "val in scene: KX_Scene, "BGE_PROXY_ERROR_MSG);
2068 if (self->m_attr_dict && PyDict_GetItem(self->m_attr_dict, value))
2074 PyMappingMethods KX_Scene::Mapping = {
2075 (lenfunc)NULL , /*inquiry mp_length */
2076 (binaryfunc)Map_GetItem, /*binaryfunc mp_subscript */
2077 (objobjargproc)Map_SetItem, /*objobjargproc mp_ass_subscript */
2080 PySequenceMethods KX_Scene::Sequence = {
2081 NULL, /* Cant set the len otherwise it can evaluate as false */
2082 NULL, /* sq_concat */
2083 NULL, /* sq_repeat */
2085 NULL, /* sq_slice */
2086 NULL, /* sq_ass_item */
2087 NULL, /* sq_ass_slice */
2088 (objobjproc)Seq_Contains, /* sq_contains */
2089 (binaryfunc) NULL, /* sq_inplace_concat */
2090 (ssizeargfunc) NULL, /* sq_inplace_repeat */
2093 PyObject* KX_Scene::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2095 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2096 return PyUnicode_FromString(self->GetName().ReadPtr());
2099 PyObject* KX_Scene::pyattr_get_objects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2101 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2102 return self->GetObjectList()->GetProxy();
2105 PyObject* KX_Scene::pyattr_get_objects_inactive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2107 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2108 return self->GetInactiveList()->GetProxy();
2111 PyObject* KX_Scene::pyattr_get_lights(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2113 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2114 return self->GetLightList()->GetProxy();
2117 PyObject* KX_Scene::pyattr_get_cameras(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2119 /* With refcounts in this case...
2120 * the new CListValue is owned by python, so its possible python holds onto it longer then the BGE
2121 * however this is the same with "scene.objects + []", when you make a copy by adding lists.
2124 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2125 CListValue* clist = new CListValue();
2127 /* return self->GetCameras()->GetProxy(); */
2129 list<KX_Camera*>::iterator it = self->GetCameras()->begin();
2130 while (it != self->GetCameras()->end()) {
2131 clist->Add((*it)->AddRef());
2135 return clist->NewProxy(true);
2138 PyObject* KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2140 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2141 return self->GetActiveCamera()->GetProxy();
2145 int KX_Scene::pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
2147 KX_Scene* self= static_cast<KX_Scene*>(self_v);
2150 if (!ConvertPythonToCamera(value, &camOb, false, "scene.active_camera = value: KX_Scene"))
2151 return PY_SET_ATTR_FAIL;
2153 self->SetActiveCamera(camOb);
2154 return PY_SET_ATTR_SUCCESS;
2157 PyObject* KX_Scene::pyattr_get_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2159 KX_Scene* self = static_cast<KX_Scene*>(self_v);
2161 if(self->m_draw_call_pre==NULL)
2162 self->m_draw_call_pre= PyList_New(0);
2163 Py_INCREF(self->m_draw_call_pre);
2164 return self->m_draw_call_pre;
2167 PyObject* KX_Scene::pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
2169 KX_Scene* self = static_cast<KX_Scene*>(self_v);
2171 if(self->m_draw_call_post==NULL)
2172 self->m_draw_call_post= PyList_New(0);
2173 Py_INCREF(self->m_draw_call_post);
2174 return self->m_draw_call_post;
2177 int KX_Scene::pyattr_set_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
2179 KX_Scene* self = static_cast<KX_Scene*>(self_v);
2181 if (!PyList_CheckExact(value))
2183 PyErr_SetString(PyExc_ValueError, "Expected a list");
2184 return PY_SET_ATTR_FAIL;
2186 Py_XDECREF(self->m_draw_call_pre);
2189 self->m_draw_call_pre = value;
2191 return PY_SET_ATTR_SUCCESS;
2194 int KX_Scene::pyattr_set_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
2196 KX_Scene* self = static_cast<KX_Scene*>(self_v);
2198 if (!PyList_CheckExact(value))
2200 PyErr_SetString(PyExc_ValueError, "Expected a list");
2201 return PY_SET_ATTR_FAIL;
2203 Py_XDECREF(self->m_draw_call_post);
2206 self->m_draw_call_post = value;
2208 return PY_SET_ATTR_SUCCESS;
2211 PyAttributeDef KX_Scene::Attributes[] = {
2212 KX_PYATTRIBUTE_RO_FUNCTION("name", KX_Scene, pyattr_get_name),
2213 KX_PYATTRIBUTE_RO_FUNCTION("objects", KX_Scene, pyattr_get_objects),
2214 KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive),
2215 KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights),
2216 KX_PYATTRIBUTE_RO_FUNCTION("cameras", KX_Scene, pyattr_get_cameras),
2217 KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights),
2218 KX_PYATTRIBUTE_RW_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera),
2219 KX_PYATTRIBUTE_RW_FUNCTION("pre_draw", KX_Scene, pyattr_get_drawing_callback_pre, pyattr_set_drawing_callback_pre),
2220 KX_PYATTRIBUTE_RW_FUNCTION("post_draw", KX_Scene, pyattr_get_drawing_callback_post, pyattr_set_drawing_callback_post),
2221 KX_PYATTRIBUTE_BOOL_RO("suspended", KX_Scene, m_suspend),
2222 KX_PYATTRIBUTE_BOOL_RO("activity_culling", KX_Scene, m_activity_culling),
2223 KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius),
2224 KX_PYATTRIBUTE_BOOL_RO("dbvt_culling", KX_Scene, m_dbvt_culling),
2228 KX_PYMETHODDEF_DOC(KX_Scene, addObject,
2229 "addObject(object, other, time=0)\n"
2230 "Returns the added object.\n")
2232 PyObject *pyob, *pyother;
2233 KX_GameObject *ob, *other;
2237 if (!PyArg_ParseTuple(args, "OO|i:addObject", &pyob, &pyother, &time))
2240 if ( !ConvertPythonToGameObject(pyob, &ob, false, "scene.addObject(object, other, time): KX_Scene (first argument)") ||
2241 !ConvertPythonToGameObject(pyother, &other, false, "scene.addObject(object, other, time): KX_Scene (second argument)") )
2245 SCA_IObject* replica = AddReplicaObject((SCA_IObject*)ob, other, time);
2247 // release here because AddReplicaObject AddRef's
2248 // the object is added to the scene so we dont want python to own a reference
2250 return replica->GetProxy();
2253 KX_PYMETHODDEF_DOC(KX_Scene, end,
2255 "Removes this scene from the game.\n")
2258 KX_GetActiveEngine()->RemoveScene(m_sceneName);
2263 KX_PYMETHODDEF_DOC(KX_Scene, restart,
2265 "Restarts this scene.\n")
2267 KX_GetActiveEngine()->ReplaceScene(m_sceneName, m_sceneName);
2272 KX_PYMETHODDEF_DOC(KX_Scene, replace,
2273 "replace(newScene)\n"
2274 "Replaces this scene with another one.\n")
2278 if (!PyArg_ParseTuple(args, "s:replace", &name))
2281 KX_GetActiveEngine()->ReplaceScene(m_sceneName, name);
2286 KX_PYMETHODDEF_DOC(KX_Scene, suspend,
2288 "Suspends this scene.\n")
2295 KX_PYMETHODDEF_DOC(KX_Scene, resume,
2297 "Resumes this scene.\n")
2304 /* Matches python dict.get(key, [default]) */
2305 KX_PYMETHODDEF_DOC(KX_Scene, get, "")
2308 PyObject* def = Py_None;
2311 if (!PyArg_ParseTuple(args, "O|O:get", &key, &def))
2314 if (m_attr_dict && (ret=PyDict_GetItem(m_attr_dict, key))) {
2323 #endif // WITH_PYTHON