2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* Set scene/camera stuff
|
|
|
|
*
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2011-10-23 17:52:20 +00:00
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_SceneActuator.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "SCA_IActuator.h"
|
|
|
|
#include "KX_SceneActuator.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include "KX_Scene.h"
|
|
|
|
#include "KX_Camera.h"
|
|
|
|
#include "KX_KetsjiEngine.h"
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
KX_SceneActuator::KX_SceneActuator(SCA_IObject *gameobj,
|
|
|
|
int mode,
|
|
|
|
KX_Scene *scene,
|
|
|
|
KX_KetsjiEngine* ketsjiEngine,
|
|
|
|
const STR_String& nextSceneName,
|
2009-06-28 11:22:26 +00:00
|
|
|
KX_Camera* camera)
|
2009-09-24 21:22:24 +00:00
|
|
|
: SCA_IActuator(gameobj, KX_ACT_SCENE)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
m_mode = mode;
|
|
|
|
m_scene = scene;
|
|
|
|
m_KetsjiEngine=ketsjiEngine;
|
|
|
|
m_camera = camera;
|
|
|
|
m_nextSceneName = nextSceneName;
|
2008-07-19 07:45:19 +00:00
|
|
|
if (m_camera)
|
|
|
|
m_camera->RegisterActuator(this);
|
2002-10-12 11:37:38 +00:00
|
|
|
} /* End of constructor */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KX_SceneActuator::~KX_SceneActuator()
|
|
|
|
{
|
2008-07-19 07:45:19 +00:00
|
|
|
if (m_camera)
|
|
|
|
m_camera->UnregisterActuator(this);
|
2002-10-12 11:37:38 +00:00
|
|
|
} /* end of destructor */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CValue* KX_SceneActuator::GetReplica()
|
|
|
|
{
|
|
|
|
KX_SceneActuator* replica = new KX_SceneActuator(*this);
|
|
|
|
replica->ProcessReplica();
|
|
|
|
return replica;
|
|
|
|
}
|
|
|
|
|
2008-07-19 07:45:19 +00:00
|
|
|
void KX_SceneActuator::ProcessReplica()
|
|
|
|
{
|
|
|
|
if (m_camera)
|
|
|
|
m_camera->RegisterActuator(this);
|
|
|
|
SCA_IActuator::ProcessReplica();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_SceneActuator::UnlinkObject(SCA_IObject* clientobj)
|
|
|
|
{
|
|
|
|
if (clientobj == (SCA_IObject*)m_camera)
|
|
|
|
{
|
|
|
|
// this object is being deleted, we cannot continue to track it.
|
|
|
|
m_camera = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-06 20:18:42 +00:00
|
|
|
void KX_SceneActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
|
2008-07-19 07:45:19 +00:00
|
|
|
{
|
|
|
|
void **h_obj = (*obj_map)[m_camera];
|
|
|
|
if (h_obj) {
|
|
|
|
if (m_camera)
|
|
|
|
m_camera->UnregisterActuator(this);
|
|
|
|
m_camera = (KX_Camera*)(*h_obj);
|
|
|
|
m_camera->RegisterActuator(this);
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
bool KX_SceneActuator::Update()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2005-03-09 19:45:59 +00:00
|
|
|
// bool result = false; /*unused*/
|
2002-10-12 11:37:38 +00:00
|
|
|
bool bNegativeEvent = IsNegativeEvent();
|
|
|
|
RemoveAllEvents();
|
|
|
|
|
|
|
|
if (bNegativeEvent)
|
|
|
|
return false; // do nothing on negative events
|
|
|
|
|
|
|
|
switch (m_mode)
|
|
|
|
{
|
|
|
|
case KX_SCENE_RESTART:
|
|
|
|
{
|
|
|
|
m_KetsjiEngine->ReplaceScene(m_scene->GetName(),m_scene->GetName());
|
|
|
|
break;
|
|
|
|
}
|
2004-09-19 01:33:08 +00:00
|
|
|
case KX_SCENE_SET_CAMERA:
|
|
|
|
if (m_camera)
|
|
|
|
{
|
|
|
|
m_scene->SetActiveCamera(m_camera);
|
|
|
|
}
|
2008-04-14 20:54:20 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// if no camera is set and the parent object is a camera, use it as the camera
|
|
|
|
SCA_IObject* parent = GetParent();
|
2009-06-28 11:22:26 +00:00
|
|
|
if (parent->GetGameObjectType()==SCA_IObject::OBJ_CAMERA)
|
2008-04-14 20:54:20 +00:00
|
|
|
{
|
|
|
|
m_scene->SetActiveCamera((KX_Camera*)parent);
|
|
|
|
}
|
|
|
|
}
|
2004-09-19 01:33:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_nextSceneName.Length())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (m_mode)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
case KX_SCENE_SET_SCENE:
|
|
|
|
{
|
|
|
|
m_KetsjiEngine->ReplaceScene(m_scene->GetName(),m_nextSceneName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SCENE_ADD_FRONT_SCENE:
|
|
|
|
{
|
|
|
|
bool overlay=true;
|
|
|
|
m_KetsjiEngine->ConvertAndAddScene(m_nextSceneName,overlay);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SCENE_ADD_BACK_SCENE:
|
|
|
|
{
|
|
|
|
bool overlay=false;
|
|
|
|
m_KetsjiEngine->ConvertAndAddScene(m_nextSceneName,overlay);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SCENE_REMOVE_SCENE:
|
|
|
|
{
|
|
|
|
m_KetsjiEngine->RemoveScene(m_nextSceneName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SCENE_SUSPEND:
|
|
|
|
{
|
|
|
|
m_KetsjiEngine->SuspendScene(m_nextSceneName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SCENE_RESUME:
|
|
|
|
{
|
|
|
|
m_KetsjiEngine->ResumeScene(m_nextSceneName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
; /* do nothing? this is an internal error !!! */
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* returns a camera if the name is valid */
|
2011-10-27 14:41:26 +00:00
|
|
|
KX_Camera* KX_SceneActuator::FindCamera(const char *camName)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
KX_SceneList* sl = m_KetsjiEngine->CurrentScenes();
|
|
|
|
STR_String name = STR_String(camName);
|
|
|
|
KX_SceneList::iterator it = sl->begin();
|
|
|
|
KX_Camera* cam = NULL;
|
|
|
|
|
|
|
|
while ((it != sl->end()) && (!cam))
|
|
|
|
{
|
|
|
|
cam = (*it)->FindCamera(name);
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cam;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-27 14:41:26 +00:00
|
|
|
KX_Scene* KX_SceneActuator::FindScene(const char * sceneName)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
return m_KetsjiEngine->FindScene(sceneName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject KX_SceneActuator::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2009-08-10 00:07:34 +00:00
|
|
|
"KX_SceneActuator",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,0,0,0,0,0,0,0,0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&SCA_IActuator::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_SceneActuator::Methods[] =
|
|
|
|
{
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_SceneActuator::Attributes[] = {
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_STRING_RW("scene",0,32,true,KX_SceneActuator,m_nextSceneName),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("camera",KX_SceneActuator,pyattr_get_camera,pyattr_set_camera),
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useRestart", KX_SceneActuator, m_restart),
|
|
|
|
KX_PYATTRIBUTE_INT_RW("mode", KX_SCENE_NODEF+1, KX_SCENE_MAX-1, true, KX_SceneActuator, m_mode),
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
|
|
|
|
if (!actuator->m_camera)
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
|
|
|
return actuator->m_camera->GetProxy();
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
|
|
|
|
KX_Camera *camOb;
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
if (!ConvertPythonToCamera(value, &camOb, true, "actu.camera = value: KX_SceneActuator"))
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
|
|
|
|
if (actuator->m_camera)
|
|
|
|
actuator->m_camera->UnregisterActuator(actuator);
|
|
|
|
|
|
|
|
if(camOb==NULL) {
|
2009-04-20 15:06:46 +00:00
|
|
|
actuator->m_camera= NULL;
|
|
|
|
}
|
2009-06-08 20:08:19 +00:00
|
|
|
else {
|
2009-04-20 15:06:46 +00:00
|
|
|
actuator->m_camera = camOb;
|
|
|
|
actuator->m_camera->RegisterActuator(actuator);
|
|
|
|
}
|
2009-06-08 20:08:19 +00:00
|
|
|
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-04-20 15:06:46 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* eof */
|