Blender  V2.59
KX_StateActuator.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: KX_StateActuator.cpp 35171 2011-02-25 13:35:59Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  * Actuator to toggle visibility/invisibility of objects
00029  */
00030 
00036 #include "KX_StateActuator.h"
00037 #include "KX_GameObject.h"
00038 
00039 KX_StateActuator::KX_StateActuator(
00040         SCA_IObject* gameobj,
00041         int operation,
00042         unsigned int mask
00043         ) 
00044         : SCA_IActuator(gameobj, KX_ACT_STATE),
00045           m_operation(operation),
00046           m_mask(mask)
00047 {
00048         // intentionally empty
00049 }
00050 
00051 KX_StateActuator::~KX_StateActuator(
00052         void
00053         )
00054 {
00055         // intentionally empty
00056 }
00057 
00058 // used to put state actuator to be executed before any other actuators
00059 SG_QList KX_StateActuator::m_stateActuatorHead;
00060 
00061 CValue*
00062 KX_StateActuator::GetReplica(
00063         void
00064         )
00065 {
00066         KX_StateActuator* replica = new KX_StateActuator(*this);
00067         replica->ProcessReplica();
00068         return replica;
00069 }
00070 
00071 bool
00072 KX_StateActuator::Update()
00073 {
00074         bool bNegativeEvent = IsNegativeEvent();
00075         unsigned int objMask;
00076 
00077         // execution of state actuator means that we are in the execution phase, reset this pointer
00078         // because all the active actuator of this object will be removed for sure.
00079         m_gameobj->m_firstState = NULL;
00080         RemoveAllEvents();
00081         if (bNegativeEvent) return false;
00082 
00083         KX_GameObject *obj = (KX_GameObject*) GetParent();
00084         
00085         objMask = obj->GetState();
00086         switch (m_operation) 
00087         {
00088         case OP_CPY:
00089                 objMask = m_mask;
00090                 break;
00091         case OP_SET:
00092                 objMask |= m_mask;
00093                 break;
00094         case OP_CLR:
00095                 objMask &= ~m_mask;
00096                 break;
00097         case OP_NEG:
00098                 objMask ^= m_mask;
00099                 break;
00100         default:
00101                 // unsupported operation, no  nothing
00102                 return false;
00103         }
00104         obj->SetState(objMask);
00105         return false;
00106 }
00107 
00108 // this function is only used to deactivate actuators outside the logic loop
00109 // e.g. when an object is deleted.
00110 void KX_StateActuator::Deactivate()
00111 {
00112         if (QDelink())
00113         {
00114                 // the actuator was in the active list
00115                 if (m_stateActuatorHead.QEmpty())
00116                         // no more state object active
00117                         m_stateActuatorHead.Delink();
00118         }
00119 }
00120 
00121 void KX_StateActuator::Activate(SG_DList& head)
00122 {
00123         // sort the state actuators per object on the global list
00124         if (QEmpty())
00125         {
00126                 InsertSelfActiveQList(m_stateActuatorHead, &m_gameobj->m_firstState);
00127                 // add front to make sure it runs before other actuators
00128                 head.AddFront(&m_stateActuatorHead);
00129         }
00130 }
00131 
00132 #ifdef WITH_PYTHON
00133 
00134 /* ------------------------------------------------------------------------- */
00135 /* Python functions                                                          */
00136 /* ------------------------------------------------------------------------- */
00137 
00138 
00139 
00140 /* Integration hooks ------------------------------------------------------- */
00141 PyTypeObject KX_StateActuator::Type = {
00142         PyVarObject_HEAD_INIT(NULL, 0)
00143         "KX_StateActuator",
00144         sizeof(PyObjectPlus_Proxy),
00145         0,
00146         py_base_dealloc,
00147         0,
00148         0,
00149         0,
00150         0,
00151         py_base_repr,
00152         0,0,0,0,0,0,0,0,0,
00153         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00154         0,0,0,0,0,0,0,
00155         Methods,
00156         0,
00157         0,
00158         &SCA_IActuator::Type,
00159         0,0,0,0,0,0,
00160         py_base_new
00161 };
00162 
00163 PyMethodDef KX_StateActuator::Methods[] = {
00164         {NULL,NULL} //Sentinel
00165 };
00166 
00167 PyAttributeDef KX_StateActuator::Attributes[] = {
00168         KX_PYATTRIBUTE_INT_RW("operation",KX_StateActuator::OP_NOP+1,KX_StateActuator::OP_COUNT-1,false,KX_StateActuator,m_operation),
00169         KX_PYATTRIBUTE_INT_RW("mask",0,0x3FFFFFFF,false,KX_StateActuator,m_mask),
00170         { NULL }        //Sentinel
00171 };
00172 
00173 #endif // WITH_PYTHON