Blender  V2.59
SCA_ILogicBrick.h
Go to the documentation of this file.
00001 /*
00002  * $Id: SCA_ILogicBrick.h 36523 2011-05-06 20:18:42Z blendix $
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_ILOGICBRICK
00035 #define __KX_ILOGICBRICK
00036 
00037 #include "Value.h"
00038 #include "SCA_IObject.h"
00039 #include "BoolValue.h"
00040 #include "CTR_Map.h"
00041 #include "CTR_HashedPtr.h"
00042 
00043 class NG_NetworkScene;
00044 class SCA_IScene;
00045 
00046 class SCA_ILogicBrick : public CValue
00047 {
00048         Py_Header;
00049 protected:
00050         SCA_IObject*            m_gameobj;
00051         int                                     m_Execute_Priority;
00052         int                                     m_Execute_Ueber_Priority;
00053 
00054         bool                            m_bActive;
00055         CValue*                         m_eventval;
00056         STR_String                      m_text;
00057         STR_String                      m_name;
00058         //unsigned long         m_drawcolor;
00059         void RegisterEvent(CValue* eventval);
00060         void RemoveEvent();
00061         CValue* GetEvent();
00062 
00063 public:
00064         SCA_ILogicBrick(SCA_IObject* gameobj);
00065         virtual ~SCA_ILogicBrick();
00066 
00067         void SetExecutePriority(int execute_Priority);
00068         void SetUeberExecutePriority(int execute_Priority);
00069 
00070         SCA_IObject*    GetParent() { return m_gameobj; }
00071 
00072         virtual void    ReParent(SCA_IObject* parent);
00073         virtual void    Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
00074         virtual void Delete() { Release(); }
00075 
00076         // act as a BoolValue (with value IsPositiveTrigger)
00077         virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
00078         virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
00079 
00080         virtual const STR_String &      GetText();
00081         virtual double          GetNumber();
00082         virtual STR_String&     GetName();
00083         virtual void            SetName(const char *);
00084                 
00085         bool                            IsActive()
00086         {
00087                 return m_bActive;
00088         }
00089 
00090         void                            SetActive(bool active)
00091         {
00092                 m_bActive=active;
00093         }
00094 
00095         // insert in a QList at position corresponding to m_Execute_Priority
00096         void                        InsertActiveQList(SG_QList& head)
00097         {
00098                 SG_QList::iterator<SCA_ILogicBrick> it(head);
00099                 for(it.begin(); !it.end() && m_Execute_Priority > (*it)->m_Execute_Priority; ++it);
00100                 it.add_back(this);
00101         }
00102 
00103         // insert in a QList at position corresponding to m_Execute_Priority
00104         // inside a longer list that contains elements of other objects. 
00105         // Sorting is done only between the elements of the same object.
00106         // head is the head of the combined list
00107         // current points to the first element of the object in the list, NULL if none yet
00108         void                        InsertSelfActiveQList(SG_QList& head, SG_QList** current)
00109         {
00110                 if (!*current)
00111                 {
00112                         // first element can be put anywhere
00113                         head.QAddBack(this);
00114                         *current = this;
00115                         return;
00116                 }
00117                 // note: we assume current points actually to one o our element, skip the tests
00118                 SG_QList::iterator<SCA_ILogicBrick> it(head,*current);
00119                 if (m_Execute_Priority <= (*it)->m_Execute_Priority)
00120                 {
00121                         // this element comes before the first
00122                         *current = this;
00123                 }
00124                 else
00125                 {
00126                         for(++it; !it.end() && (*it)->m_gameobj == m_gameobj &&  m_Execute_Priority > (*it)->m_Execute_Priority; ++it);
00127                 }
00128                 it.add_back(this);
00129         }
00130 
00131         virtual bool            LessComparedTo(SCA_ILogicBrick* other);
00132 
00133         /* runtime variable, set when Triggering the python controller */
00134         static class SCA_LogicManager*  m_sCurrentLogicManager;
00135 
00136 
00137         /* for moving logic bricks between scenes */
00138         virtual void            Replace_IScene(SCA_IScene *val) {};
00139         virtual void            Replace_NetworkScene(NG_NetworkScene *val) {};
00140 
00141 #ifdef WITH_PYTHON
00142         // python methods
00143         
00144         static PyObject*        pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00145 
00146         // check that attribute is a property
00147         static int CheckProperty(void *self, const PyAttributeDef *attrdef);
00148 
00149         enum KX_BOOL_TYPE {
00150                 KX_BOOL_NODEF = 0,
00151                 KX_TRUE,
00152                 KX_FALSE,
00153                 KX_BOOL_MAX
00154         };
00155 
00156 
00157 protected: 
00158         /* Some conversions to go with the bool type. */
00160         bool PyArgToBool(int boolArg);
00161 
00163         PyObject* BoolToPyArg(bool);
00164         
00165 #endif // WITH_PYTHON
00166 
00167 };
00168 
00169 #endif
00170