celtool/stdpcimp.h
00001 /* 00002 Crystal Space Entity Layer 00003 Copyright (C) 2001 by Jorrit Tyberghein 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CEL_CELTOOL_STDPC__ 00021 #define __CEL_CELTOOL_STDPC__ 00022 00023 #include "cstypes.h" 00024 #include "iutil/comp.h" 00025 #include "csutil/scf.h" 00026 #include "csutil/scf_implementation.h" 00027 #include "csutil/refarr.h" 00028 #include "csutil/weakref.h" 00029 #include "physicallayer/propclas.h" 00030 #include "physicallayer/propfact.h" 00031 #include "physicallayer/pl.h" 00032 00033 struct iCelEntity; 00034 struct iObjectRegistry; 00035 00036 00037 struct Property 00038 { 00039 csStringID id; 00040 celDataType datatype; 00041 bool readonly; 00042 const char* desc; 00043 Property () : id (csInvalidStringID) { } 00044 }; 00045 00051 struct PropertyHolder 00052 { 00053 Property* properties; 00054 size_t propertycount; 00055 // Set to true if we have done an action. 00056 bool actions_done; 00057 00062 csHash<int, csStringID> constants; 00063 00064 PropertyHolder () : properties (0), propertycount (0), actions_done (false) 00065 { } 00066 ~PropertyHolder () { delete[] properties; } 00067 void SetCount (int cnt) 00068 { 00069 if (properties) return; 00070 propertycount = cnt; 00071 properties = new Property[cnt]; 00072 } 00073 }; 00074 00080 class celPcCommon : public scfImplementation2< 00081 celPcCommon, iCelPropertyClass, iCelTimerListener> 00082 { 00083 private: 00084 csRefArray<iCelPropertyChangeCallback> callbacks; 00085 // This flag is true if we currently don't know the state of 00086 // the sibling property classes (property classes in the same 00087 // entity). It is set to true by PropertyClassesHaveChanged() 00088 // and cleared by HavePropertyClassesChanged(). 00089 bool propclasses_dirty; 00090 char* tag; 00091 00092 protected: 00093 iCelEntity* entity; 00094 iObjectRegistry* object_reg; 00095 csWeakRef<iCelPlLayer> pl; 00096 00097 protected: 00098 void FirePropertyChangeCallback (int propertyId); 00099 00103 void AddAction (int idx, const char* id) 00104 { 00105 propholder->actions_done = true; 00106 propholder->constants.Put (pl->FetchStringID (id), idx); 00107 } 00108 00120 void AddProperty (int idx, const char* id, 00121 celDataType type, bool readonly, const char* desc, 00122 void* prop) 00123 { 00124 if (propdata == 0) 00125 { 00126 propdata = new void* [propholder->propertycount]; 00127 } 00128 Property& pr = propholder->properties[idx]; 00129 if (pr.id == csInvalidStringID) 00130 { 00131 pr.id = pl->FetchStringID (id); 00132 pr.datatype = type; 00133 pr.readonly = readonly; 00134 pr.desc = desc; 00135 propholder->constants.Put (pr.id, idx); 00136 } 00137 propdata[idx] = prop; 00138 } 00139 00140 void** propdata; 00141 PropertyHolder* propholder; 00142 00143 private: 00144 template <class T> 00145 bool SetPropertyTemplated (csStringID propertyId, T l, 00146 celDataType type); 00147 template <class T> 00148 T GetPropertyTemplated (csStringID propertyId, celDataType type); 00149 template <class T> 00150 bool GetPropertyTemplated (csStringID propertyId, celDataType type, T& v); 00151 00152 public: 00153 celPcCommon (iObjectRegistry* object_reg); 00154 virtual ~celPcCommon (); 00155 00156 bool HavePropertyClassesChanged () 00157 { 00158 if (!propclasses_dirty) return false; 00159 propclasses_dirty = false; 00160 return true; 00161 } 00162 00163 virtual void SetTag (const char* tagname); 00164 virtual const char* GetTag () const { return tag; } 00165 00166 virtual iCelEntity* GetEntity () { return entity; } 00167 virtual void SetEntity (iCelEntity* entity); 00168 virtual bool AddPropertyChangeCallback (iCelPropertyChangeCallback* cb); 00169 virtual bool RemovePropertyChangeCallback ( 00170 iCelPropertyChangeCallback* cb); 00171 00172 virtual bool SetPropertyIndexed (int, long) { return false; } 00173 virtual bool SetPropertyIndexed (int, float) { return false; } 00174 virtual bool SetPropertyIndexed (int, bool) { return false; } 00175 virtual bool SetPropertyIndexed (int, const char*) { return false; } 00176 virtual bool SetPropertyIndexed (int, const csVector2&) { return false; } 00177 virtual bool SetPropertyIndexed (int, const csVector3&) { return false; } 00178 virtual bool SetPropertyIndexed (int, const csColor&) { return false; } 00179 virtual bool SetPropertyIndexed (int, iCelPropertyClass* pclass) 00180 { return false; } 00181 virtual bool SetPropertyIndexed (int, iCelEntity* entity) { return false; } 00182 virtual bool SetPropertyIndexed (int, iBase* ibase) { return false; } 00183 00184 virtual bool SetProperty (csStringID, long); 00185 virtual bool SetProperty (csStringID, float); 00186 virtual bool SetProperty (csStringID, bool); 00187 virtual bool SetProperty (csStringID, const char*); 00188 virtual bool SetProperty (csStringID, const csVector2&); 00189 virtual bool SetProperty (csStringID, const csVector3&); 00190 virtual bool SetProperty (csStringID, const csColor&); 00191 virtual bool SetProperty (csStringID, iCelPropertyClass* pclass); 00192 virtual bool SetProperty (csStringID, iCelEntity* entity); 00193 virtual bool SetProperty (csStringID, iBase* ibase); 00194 00195 virtual bool GetPropertyIndexed (int, long& l) { return false; } 00196 virtual bool GetPropertyIndexed (int, float& f) { return false; } 00197 virtual bool GetPropertyIndexed (int, bool& b) { return false; } 00198 virtual bool GetPropertyIndexed (int, const char*&) { return false; } 00199 virtual bool GetPropertyIndexed (int, csVector2&) { return false; } 00200 virtual bool GetPropertyIndexed (int, csVector3&) { return false; } 00201 virtual bool GetPropertyIndexed (int, csColor&) { return false; } 00202 virtual bool GetPropertyIndexed (int, iCelPropertyClass*&) { return false; } 00203 virtual bool GetPropertyIndexed (int, iCelEntity*&) { return false; } 00204 virtual bool GetPropertyIndexed (int, iBase*&) { return false; } 00205 00206 virtual long GetPropertyLong (csStringID); 00207 virtual float GetPropertyFloat (csStringID); 00208 virtual bool GetPropertyBool (csStringID); 00209 virtual const char* GetPropertyString (csStringID); 00210 virtual bool GetPropertyVector (csStringID, csVector2&); 00211 virtual bool GetPropertyVector (csStringID, csVector3&); 00212 virtual bool GetPropertyColor (csStringID, csColor&); 00213 virtual iCelPropertyClass* GetPropertyPClass (csStringID); 00214 virtual iCelEntity* GetPropertyEntity (csStringID); 00215 virtual iBase* GetPropertyIBase (csStringID); 00216 00217 virtual bool PerformAction (csStringID, iCelParameterBlock*, celData& ret); 00218 virtual bool PerformActionIndexed (int, iCelParameterBlock*, celData& ret) 00219 { return false; } 00220 virtual const char* GetPropertyOrActionDescription (csStringID); 00221 virtual size_t GetPropertyAndActionCount (); 00222 virtual csStringID GetPropertyOrActionID (size_t); 00223 virtual void PropertyClassesHaveChanged () 00224 { 00225 propclasses_dirty = true; 00226 } 00227 virtual celDataType GetPropertyOrActionType (csStringID); 00228 virtual bool IsPropertyReadOnly (csStringID); 00229 00230 virtual csPtr<iCelDataBuffer> SaveFirstPass () { return 0; } 00231 virtual bool LoadFirstPass (iCelDataBuffer*) { return 0; } 00232 00233 virtual csPtr<iCelDataBuffer> GetPersistentData ( 00234 celPersistenceType persistence_type) 00235 { return 0; } 00236 virtual celPersistenceResult SetPersistentData (csTicks data_time, 00237 iCelDataBuffer* data, celPersistenceType persistence_type) 00238 { return CEL_PERSIST_RESULT_OK; }; 00239 00240 // --- For iCelTimerListener ----------------------------------------- 00241 virtual void TickEveryFrame () { } 00242 virtual void TickOnce () { } 00243 }; 00244 00245 #endif // __CEL_CELTOOL_STDPC__ 00246
Generated for CEL: Crystal Entity Layer by doxygen 1.4.7