Blender  V2.59
SCA_IController.h
Go to the documentation of this file.
00001 /*
00002  * $Id: SCA_IController.h 35063 2011-02-22 10:33:14Z 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  */
00029 
00034 #ifndef __KX_ICONTROLLER
00035 #define __KX_ICONTROLLER
00036 
00037 #include "SCA_ILogicBrick.h"
00038 #include "PyObjectPlus.h"
00039 
00045 class SCA_IController : public SCA_ILogicBrick
00046 {
00047         Py_Header;
00048 protected:
00049         std::vector<class SCA_ISensor*>         m_linkedsensors;
00050         std::vector<class SCA_IActuator*>       m_linkedactuators;
00051         unsigned int                                            m_statemask;
00052         bool                                                            m_justActivated;
00053         bool                                                            m_bookmark;
00054 public:
00055         SCA_IController(SCA_IObject* gameobj);
00056         virtual ~SCA_IController();
00057         virtual void Trigger(class SCA_LogicManager* logicmgr)=0;
00058         void    LinkToSensor(SCA_ISensor* sensor);
00059         void    LinkToActuator(SCA_IActuator*);
00060         std::vector<class SCA_ISensor*>&        GetLinkedSensors();
00061         std::vector<class SCA_IActuator*>&      GetLinkedActuators();
00062         void    ReserveActuator(int num)
00063         {
00064                 m_linkedactuators.reserve(num);
00065         }
00066         void    UnlinkAllSensors();
00067         void    UnlinkAllActuators();
00068         void    UnlinkActuator(class SCA_IActuator* actua);
00069         void    UnlinkSensor(class SCA_ISensor* sensor);
00070         void    SetState(unsigned int state) { m_statemask = state; }
00071         void    ApplyState(unsigned int state);
00072         void    Deactivate()
00073         {
00074                 // the controller can only be part of a sensor m_newControllers list
00075                 Delink();
00076         }
00077         bool IsJustActivated()
00078         {
00079                 return m_justActivated;
00080         }
00081         void ClrJustActivated()
00082         {
00083                 m_justActivated = false;
00084         }
00085         void SetBookmark(bool bookmark)
00086         {
00087                 m_bookmark = bookmark;
00088         }
00089         void Activate(SG_DList& head)
00090         {
00091                 if (QEmpty())
00092                 {
00093                         if (m_bookmark)
00094                         {
00095                                 m_gameobj->m_activeBookmarkedControllers.QAddBack(this);
00096                                 head.AddFront(&m_gameobj->m_activeBookmarkedControllers);
00097                         }
00098                         else
00099                         {
00100                                 InsertActiveQList(m_gameobj->m_activeControllers);
00101                                 head.AddBack(&m_gameobj->m_activeControllers);
00102                         }
00103                 }
00104         }
00105         
00106 
00107 #ifdef WITH_PYTHON
00108         static PyObject*        pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00109         static PyObject*        pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00110         static PyObject*        pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00111 #endif // WITH_PYTHON
00112 };
00113 
00114 #endif
00115