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