Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_Scene.cpp
| Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, | ||||
| m_isclearingZbuffer = true; | m_isclearingZbuffer = true; | ||||
| m_tempObjectList = new CListValue(); | m_tempObjectList = new CListValue(); | ||||
| m_objectlist = new CListValue(); | m_objectlist = new CListValue(); | ||||
| m_parentlist = new CListValue(); | m_parentlist = new CListValue(); | ||||
| m_lightlist= new CListValue(); | m_lightlist= new CListValue(); | ||||
| m_inactivelist = new CListValue(); | m_inactivelist = new CListValue(); | ||||
| m_euthanasyobjects = new CListValue(); | m_euthanasyobjects = new CListValue(); | ||||
| m_animatedlist = new CListValue(); | m_animatedlist = new CListValue(); | ||||
| m_cameralist = new CListValue(); | |||||
| m_fontlist = new CListValue(); | |||||
| m_logicmgr = new SCA_LogicManager(); | m_logicmgr = new SCA_LogicManager(); | ||||
| m_timemgr = new SCA_TimeEventManager(m_logicmgr); | m_timemgr = new SCA_TimeEventManager(m_logicmgr); | ||||
| m_keyboardmgr = new SCA_KeyboardManager(m_logicmgr,keyboarddevice); | m_keyboardmgr = new SCA_KeyboardManager(m_logicmgr,keyboarddevice); | ||||
| m_mousemgr = new SCA_MouseManager(m_logicmgr,mousedevice, canvas); | m_mousemgr = new SCA_MouseManager(m_logicmgr,mousedevice, canvas); | ||||
| //SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr); | //SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if (m_tempObjectList) | ||||
| m_tempObjectList->Release(); | m_tempObjectList->Release(); | ||||
| if (m_euthanasyobjects) | if (m_euthanasyobjects) | ||||
| m_euthanasyobjects->Release(); | m_euthanasyobjects->Release(); | ||||
| if (m_animatedlist) | if (m_animatedlist) | ||||
| m_animatedlist->Release(); | m_animatedlist->Release(); | ||||
| if (m_cameralist) | |||||
| m_cameralist->Release(); | |||||
| if (m_fontlist) | |||||
| m_fontlist->Release(); | |||||
| if (m_logicmgr) | if (m_logicmgr) | ||||
| delete m_logicmgr; | delete m_logicmgr; | ||||
| if (m_physicsEnvironment) | if (m_physicsEnvironment) | ||||
| delete m_physicsEnvironment; | delete m_physicsEnvironment; | ||||
| if (m_networkScene) | if (m_networkScene) | ||||
| delete m_networkScene; | delete m_networkScene; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| CListValue* KX_Scene::GetLightList() | CListValue* KX_Scene::GetLightList() | ||||
| { | { | ||||
| return m_lightlist; | return m_lightlist; | ||||
| } | } | ||||
| SCA_LogicManager* KX_Scene::GetLogicManager() | CListValue* KX_Scene::GetCameraList() | ||||
| { | { | ||||
| return m_logicmgr; | return m_cameralist; | ||||
| } | } | ||||
| SCA_TimeEventManager* KX_Scene::GetTimeEventManager() | CListValue* KX_Scene::GetFontList() | ||||
| { | { | ||||
| return m_timemgr; | return m_fontlist; | ||||
| } | } | ||||
| SCA_LogicManager* KX_Scene::GetLogicManager() | |||||
| { | |||||
| return m_logicmgr; | |||||
| } | |||||
| SCA_TimeEventManager* KX_Scene::GetTimeEventManager() | |||||
| list<class KX_Camera*>* KX_Scene::GetCameras() | |||||
| { | { | ||||
| return &m_cameras; | return m_timemgr; | ||||
| } | } | ||||
| void KX_Scene::SetFramingType(RAS_FrameSettings & frame_settings) | void KX_Scene::SetFramingType(RAS_FrameSettings & frame_settings) | ||||
| { | { | ||||
| m_frame_settings = frame_settings; | m_frame_settings = frame_settings; | ||||
| }; | }; | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 721 Lines • ▼ Show 20 Lines | int KX_Scene::NewRemoveObject(class CValue* gameobj) | ||||
| if (m_parentlist->RemoveValue(newobj)) | if (m_parentlist->RemoveValue(newobj)) | ||||
| ret = newobj->Release(); | ret = newobj->Release(); | ||||
| if (m_inactivelist->RemoveValue(newobj)) | if (m_inactivelist->RemoveValue(newobj)) | ||||
| ret = newobj->Release(); | ret = newobj->Release(); | ||||
| if (m_euthanasyobjects->RemoveValue(newobj)) | if (m_euthanasyobjects->RemoveValue(newobj)) | ||||
| ret = newobj->Release(); | ret = newobj->Release(); | ||||
| if (m_animatedlist->RemoveValue(newobj)) | if (m_animatedlist->RemoveValue(newobj)) | ||||
| ret = newobj->Release(); | ret = newobj->Release(); | ||||
| if (m_fontlist->RemoveValue(newobj)) | |||||
| ret = newobj->Release(); | |||||
| if (m_cameralist->RemoveValue(newobj)) | |||||
| ret = newobj->Release(); | |||||
| if (newobj == m_active_camera) | if (newobj == m_active_camera) | ||||
| { | |||||
| //no AddRef done on m_active_camera so no Release | |||||
| //m_active_camera->Release(); | |||||
| m_active_camera = NULL; | m_active_camera = NULL; | ||||
| } | |||||
| // in case this is a camera | |||||
| m_cameras.remove((KX_Camera*)newobj); | |||||
| // in case this is a font | |||||
| m_fonts.remove((KX_FontObject*)newobj); | |||||
| /* currently does nothing, keep in case we need to Unregister something */ | /* currently does nothing, keep in case we need to Unregister something */ | ||||
| #if 0 | #if 0 | ||||
| if (m_sceneConverter) | if (m_sceneConverter) | ||||
| m_sceneConverter->UnregisterGameObject(newobj); | m_sceneConverter->UnregisterGameObject(newobj); | ||||
| #endif | #endif | ||||
| // return value will be 0 if the object is actually deleted (all reference gone) | // return value will be 0 if the object is actually deleted (all reference gone) | ||||
| ▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| if (use_phys) { /* update the new assigned mesh with the physics mesh */ | if (use_phys) { /* update the new assigned mesh with the physics mesh */ | ||||
| if (gameobj->GetPhysicsController()) | if (gameobj->GetPhysicsController()) | ||||
| gameobj->GetPhysicsController()->ReinstancePhysicsShape(NULL, use_gfx?NULL:mesh); | gameobj->GetPhysicsController()->ReinstancePhysicsShape(NULL, use_gfx?NULL:mesh); | ||||
| } | } | ||||
| } | } | ||||
| /* Font Object routines */ | |||||
| void KX_Scene::AddFont(KX_FontObject* font) | |||||
| { | |||||
| if (!FindFont(font)) | |||||
| m_fonts.push_back(font); | |||||
| } | |||||
| KX_FontObject* KX_Scene::FindFont(KX_FontObject* font) | |||||
| { | |||||
| list<KX_FontObject*>::iterator it = m_fonts.begin(); | |||||
| while ((it != m_fonts.end()) && ((*it) != font)) | |||||
| { | |||||
| ++it; | |||||
| } | |||||
| return ((it == m_fonts.end()) ? NULL : (*it)); | |||||
| } | |||||
| /* Camera Object routines */ | |||||
| KX_Camera* KX_Scene::FindCamera(KX_Camera* cam) | |||||
| { | |||||
| list<KX_Camera*>::iterator it = m_cameras.begin(); | |||||
| while ((it != m_cameras.end()) && ((*it) != cam)) { | |||||
| it++; | |||||
| } | |||||
| return ((it == m_cameras.end()) ? NULL : (*it)); | |||||
| } | |||||
| KX_Camera* KX_Scene::FindCamera(STR_String& name) | |||||
| { | |||||
| list<KX_Camera*>::iterator it = m_cameras.begin(); | |||||
| while ((it != m_cameras.end()) && ((*it)->GetName() != name)) { | |||||
| it++; | |||||
| } | |||||
| return ((it == m_cameras.end()) ? NULL : (*it)); | |||||
| } | |||||
| void KX_Scene::AddCamera(KX_Camera* cam) | |||||
| { | |||||
| if (!FindCamera(cam)) | |||||
| m_cameras.push_back(cam); | |||||
| } | |||||
| KX_Camera* KX_Scene::GetActiveCamera() | KX_Camera* KX_Scene::GetActiveCamera() | ||||
| { | { | ||||
| // NULL if not defined | // NULL if not defined | ||||
| return m_active_camera; | return m_active_camera; | ||||
| } | } | ||||
| void KX_Scene::SetActiveCamera(KX_Camera* cam) | void KX_Scene::SetActiveCamera(KX_Camera* cam) | ||||
| { | { | ||||
| // only set if the cam is in the active list? Or add it otherwise? | // only set if the cam is in the active list? Or add it otherwise? | ||||
| if (!FindCamera(cam)) { | if (!m_cameralist->SearchValue(cam)) { | ||||
| AddCamera(cam); | m_cameralist->Add(cam->AddRef()); | ||||
| if (cam) std::cout << "Added cam " << cam->GetName() << std::endl; | if (cam) std::cout << "Added cam " << cam->GetName() << std::endl; | ||||
| } | } | ||||
| m_active_camera = cam; | m_active_camera = cam; | ||||
| } | } | ||||
| void KX_Scene::SetCameraOnTop(KX_Camera* cam) | void KX_Scene::SetCameraOnTop(KX_Camera* cam) | ||||
| { | { | ||||
| if (!FindCamera(cam)) { | if (!m_cameralist->SearchValue(cam)) { | ||||
| // adding is always done at the back, so that's all that needs to be done | // adding is always done at the back, so that's all that needs to be done | ||||
| AddCamera(cam); | m_cameralist->Add(cam->AddRef()); | ||||
| if (cam) std::cout << "Added cam " << cam->GetName() << std::endl; | if (cam) std::cout << "Added cam " << cam->GetName() << std::endl; | ||||
| } else { | } else { | ||||
| m_cameras.remove(cam); | // no release and addref just change camera place | ||||
| m_cameras.push_back(cam); | m_cameralist->RemoveValue(cam); | ||||
| m_cameralist->Add(cam); | |||||
| } | } | ||||
| } | } | ||||
| void KX_Scene::MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera* cam, int layer) | void KX_Scene::MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera* cam, int layer) | ||||
| { | { | ||||
| int intersect = KX_Camera::INTERSECT; | int intersect = KX_Camera::INTERSECT; | ||||
| KX_GameObject *gameobj = node->Client()?(KX_GameObject*) node->Client()->GetSGClientObject():NULL; | KX_GameObject *gameobj = node->Client()?(KX_GameObject*) node->Client()->GetSGClientObject():NULL; | ||||
| bool visible = (gameobj && gameobj->GetVisible() && (!layer || (gameobj->GetLayer() & layer))); | bool visible = (gameobj && gameobj->GetVisible() && (!layer || (gameobj->GetLayer() & layer))); | ||||
| ▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | void KX_Scene::RenderBuckets(const MT_Transform & cameratransform, | ||||
| class RAS_IRasterizer* rasty) | class RAS_IRasterizer* rasty) | ||||
| { | { | ||||
| m_bucketmanager->Renderbuckets(cameratransform,rasty); | m_bucketmanager->Renderbuckets(cameratransform,rasty); | ||||
| KX_BlenderMaterial::EndFrame(); | KX_BlenderMaterial::EndFrame(); | ||||
| } | } | ||||
| void KX_Scene::RenderFonts() | void KX_Scene::RenderFonts() | ||||
| { | { | ||||
| list<KX_FontObject*>::iterator it = m_fonts.begin(); | for (unsigned int i = 0; i < m_fontlist->GetCount(); ++i) | ||||
| while (it != m_fonts.end()) { | ((KX_FontObject*)m_fontlist->GetValue(i))->DrawFontText(); | ||||
| (*it)->DrawFontText(); | |||||
| ++it; | |||||
| } | |||||
| } | } | ||||
| void KX_Scene::UpdateObjectLods(void) | void KX_Scene::UpdateObjectLods(void) | ||||
| { | { | ||||
| KX_GameObject* gameobj; | KX_GameObject* gameobj; | ||||
| MT_Vector3 cam_pos = this->m_active_camera->NodeGetWorldPosition(); | MT_Vector3 cam_pos = this->m_active_camera->NodeGetWorldPosition(); | ||||
| for (int i = 0; i < this->GetObjectList()->GetCount(); i++) { | for (int i = 0; i < this->GetObjectList()->GetCount(); i++) { | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | if (sg->GetSGClientInfo() == from) { | ||||
| for (int i=0; i<children.size(); i++) | for (int i=0; i<children.size(); i++) | ||||
| children[i]->SetSGClientInfo(to); | children[i]->SetSGClientInfo(to); | ||||
| } | } | ||||
| } | } | ||||
| /* If the object is a light, update it's scene */ | /* If the object is a light, update it's scene */ | ||||
| if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT) | if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT) | ||||
| ((KX_LightObject*)gameobj)->UpdateScene(to); | ((KX_LightObject*)gameobj)->UpdateScene(to); | ||||
| if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA) | |||||
| to->AddCamera((KX_Camera*)gameobj); | |||||
| /* Add the object to the scene's logic manager */ | /* Add the object to the scene's logic manager */ | ||||
| to->GetLogicManager()->RegisterGameObjectName(gameobj->GetName(), gameobj); | to->GetLogicManager()->RegisterGameObjectName(gameobj->GetName(), gameobj); | ||||
| to->GetLogicManager()->RegisterGameObj(gameobj->GetBlenderObject(), gameobj); | to->GetLogicManager()->RegisterGameObj(gameobj->GetBlenderObject(), gameobj); | ||||
| for (int i=0; i<gameobj->GetMeshCount(); ++i) | for (int i=0; i<gameobj->GetMeshCount(); ++i) | ||||
| to->GetLogicManager()->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), gameobj->GetBlenderObject()); | to->GetLogicManager()->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), gameobj->GetBlenderObject()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | bool KX_Scene::MergeScene(KX_Scene *other) | ||||
| other->GetInactiveList()->ReleaseAndRemoveAll(); | other->GetInactiveList()->ReleaseAndRemoveAll(); | ||||
| GetRootParentList()->MergeList(other->GetRootParentList()); | GetRootParentList()->MergeList(other->GetRootParentList()); | ||||
| other->GetRootParentList()->ReleaseAndRemoveAll(); | other->GetRootParentList()->ReleaseAndRemoveAll(); | ||||
| GetLightList()->MergeList(other->GetLightList()); | GetLightList()->MergeList(other->GetLightList()); | ||||
| other->GetLightList()->ReleaseAndRemoveAll(); | other->GetLightList()->ReleaseAndRemoveAll(); | ||||
| GetCameraList()->MergeList(other->GetCameraList()); | |||||
| other->GetCameraList()->ReleaseAndRemoveAll(); | |||||
| GetFontList()->MergeList(other->GetFontList()); | |||||
| other->GetFontList()->ReleaseAndRemoveAll(); | |||||
| if (env) | if (env) | ||||
| env->MergeEnvironment(env_other); | env->MergeEnvironment(env_other); | ||||
| /* move materials across, assume they both use the same scene-converters | /* move materials across, assume they both use the same scene-converters | ||||
| * Do this after lights are merged so materials can use the lights in shaders | * Do this after lights are merged so materials can use the lights in shaders | ||||
| */ | */ | ||||
| GetSceneConverter()->MergeScene(this, other); | GetSceneConverter()->MergeScene(this, other); | ||||
| ▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| PyObject *KX_Scene::pyattr_get_lights(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_Scene::pyattr_get_lights(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_Scene* self = static_cast<KX_Scene*>(self_v); | KX_Scene* self = static_cast<KX_Scene*>(self_v); | ||||
| return self->GetLightList()->GetProxy(); | return self->GetLightList()->GetProxy(); | ||||
| } | } | ||||
| PyObject *KX_Scene::pyattr_get_cameras(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_Scene::pyattr_get_fonts(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| /* With refcounts in this case... | |||||
| * the new CListValue is owned by python, so its possible python holds onto it longer then the BGE | |||||
| * however this is the same with "scene.objects + []", when you make a copy by adding lists. | |||||
| */ | |||||
| KX_Scene* self = static_cast<KX_Scene*>(self_v); | KX_Scene* self = static_cast<KX_Scene*>(self_v); | ||||
| CListValue* clist = new CListValue(); | return self->GetFontList()->GetProxy(); | ||||
| /* return self->GetCameras()->GetProxy(); */ | |||||
| list<KX_Camera*>::iterator it = self->GetCameras()->begin(); | |||||
| while (it != self->GetCameras()->end()) { | |||||
| clist->Add((*it)->AddRef()); | |||||
| it++; | |||||
| } | } | ||||
| return clist->NewProxy(true); | PyObject *KX_Scene::pyattr_get_cameras(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | |||||
| KX_Scene* self = static_cast<KX_Scene*>(self_v); | |||||
| return self->GetCameraList()->GetProxy(); | |||||
| } | } | ||||
| PyObject *KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_Scene* self = static_cast<KX_Scene*>(self_v); | KX_Scene* self = static_cast<KX_Scene*>(self_v); | ||||
| KX_Camera* cam= self->GetActiveCamera(); | KX_Camera* cam= self->GetActiveCamera(); | ||||
| if (cam) | if (cam) | ||||
| return self->GetActiveCamera()->GetProxy(); | return self->GetActiveCamera()->GetProxy(); | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | int KX_Scene::pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| PyAttributeDef KX_Scene::Attributes[] = { | PyAttributeDef KX_Scene::Attributes[] = { | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("name", KX_Scene, pyattr_get_name), | KX_PYATTRIBUTE_RO_FUNCTION("name", KX_Scene, pyattr_get_name), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("objects", KX_Scene, pyattr_get_objects), | KX_PYATTRIBUTE_RO_FUNCTION("objects", KX_Scene, pyattr_get_objects), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive), | KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights), | KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("fonts", KX_Scene, pyattr_get_fonts), | |||||
campbellbarton: calling `fonts` is odd, this is really text objects, should call `texts` ? | |||||
| KX_PYATTRIBUTE_RO_FUNCTION("cameras", KX_Scene, pyattr_get_cameras), | KX_PYATTRIBUTE_RO_FUNCTION("cameras", KX_Scene, pyattr_get_cameras), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera), | KX_PYATTRIBUTE_RW_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("pre_draw", KX_Scene, pyattr_get_drawing_callback_pre, pyattr_set_drawing_callback_pre), | KX_PYATTRIBUTE_RW_FUNCTION("pre_draw", KX_Scene, pyattr_get_drawing_callback_pre, pyattr_set_drawing_callback_pre), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("post_draw", KX_Scene, pyattr_get_drawing_callback_post, pyattr_set_drawing_callback_post), | KX_PYATTRIBUTE_RW_FUNCTION("post_draw", KX_Scene, pyattr_get_drawing_callback_post, pyattr_set_drawing_callback_post), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_Scene, pyattr_get_gravity, pyattr_set_gravity), | KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_Scene, pyattr_get_gravity, pyattr_set_gravity), | ||||
| KX_PYATTRIBUTE_BOOL_RO("suspended", KX_Scene, m_suspend), | KX_PYATTRIBUTE_BOOL_RO("suspended", KX_Scene, m_suspend), | ||||
| KX_PYATTRIBUTE_BOOL_RO("activity_culling", KX_Scene, m_activity_culling), | KX_PYATTRIBUTE_BOOL_RO("activity_culling", KX_Scene, m_activity_culling), | ||||
| KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius), | KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius), | ||||
| ▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines | |||||
calling fonts is odd, this is really text objects, should call texts ?