Blender V2.61 - r43446

KX_StateActuator.cpp

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