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 "iutil/objreg.h" 00026 #include "ivaria/reporter.h" 00027 #include "csutil/scf.h" 00028 #include "csutil/scf_implementation.h" 00029 #include "csutil/refarr.h" 00030 #include "csutil/weakref.h" 00031 00032 #include "celtool/celtoolextern.h" 00033 00034 #include "physicallayer/propchg.h" 00035 #include "physicallayer/propclas.h" 00036 #include "physicallayer/propfact.h" 00037 #include "physicallayer/pl.h" 00038 #include "physicallayer/messaging.h" 00039 00040 struct iCelEntity; 00041 struct iObjectRegistry; 00042 00043 00044 struct Property 00045 { 00046 csStringID id; 00047 celDataType datatype; 00048 bool readonly; 00049 const char* desc; 00050 Property () : id (csInvalidStringID) { } 00051 }; 00052 00058 struct PropertyHolder 00059 { 00060 Property* properties; 00061 size_t propertycount; 00062 // Set to true if we have done an action. 00063 bool actions_done; 00064 00069 csHash<int, csStringID> constants; 00070 00071 PropertyHolder () : properties (0), propertycount (0), actions_done (false) 00072 { } 00073 ~PropertyHolder () { delete[] properties; } 00074 void SetCount (int cnt) 00075 { 00076 if (properties) return; 00077 propertycount = cnt; 00078 properties = new Property[cnt]; 00079 } 00080 }; 00081 00087 class CEL_CELTOOL_EXPORT celPcCommon : 00088 public scfImplementation3<celPcCommon, 00089 iCelPropertyClass, 00090 iCelTimerListener, 00091 iMessageSender> 00092 { 00093 private: 00094 csRefArray<iCelPropertyChangeCallback> callbacks; 00095 // This flag is true if we currently don't know the state of 00096 // the sibling property classes (property classes in the same 00097 // entity). It is set to true by PropertyClassesHaveChanged() 00098 // and cleared by HavePropertyClassesChanged(). 00099 bool propclasses_dirty; 00100 char* tag; 00101 // the name of the property class 00102 const char* name; 00103 00104 protected: 00105 iCelEntity* entity; 00106 iObjectRegistry* object_reg; 00107 csWeakRef<iCelPlLayer> pl; 00108 00109 protected: 00110 void FirePropertyChangeCallback (int propertyId); 00111 00115 void AddAction (int idx, const char* id) 00116 { 00117 propholder->actions_done = true; 00118 propholder->constants.Put (pl->FetchStringID (id), idx); 00119 } 00120 00132 void AddProperty (size_t idx, const char* id, 00133 celDataType type, bool readonly, const char* desc, 00134 void* prop) 00135 { 00136 // return if an invalid index was specified 00137 if (idx >= propholder->propertycount) 00138 { 00139 csRef<iReporter> rep = csQueryRegistry<iReporter>(object_reg); 00140 if (rep) 00141 rep->ReportError("crystalspace.cel.physicallayer", 00142 "celPcCommon::AddProperty out of bounds %zu >= %zu!", 00143 idx,propholder->propertycount); 00144 else 00145 csPrintf("Error: celPcCommon::AddProperty out of bounds %zu >= %zu!", 00146 idx,propholder->propertycount); 00147 return; 00148 } 00149 if (propdata == 0) 00150 { 00151 propdata = new void* [propholder->propertycount]; 00152 } 00153 Property& pr = propholder->properties[idx]; 00154 if (pr.id == csInvalidStringID) 00155 { 00156 pr.id = pl->FetchStringID (id); 00157 pr.datatype = type; 00158 pr.readonly = readonly; 00159 pr.desc = desc; 00160 propholder->constants.Put (pr.id, (int)idx); 00161 } 00162 propdata[idx] = prop; 00163 } 00164 00165 void** propdata; 00166 PropertyHolder* propholder; 00167 00168 private: 00169 template <class T> 00170 bool SetPropertyTemplated (csStringID propertyId, T l, 00171 celDataType type); 00172 template <class T> 00173 T GetPropertyTemplated (csStringID propertyId, celDataType type); 00174 template <class T> 00175 bool GetPropertyTemplated (csStringID propertyId, celDataType type, T& v); 00176 00177 public: 00178 celPcCommon (iObjectRegistry* object_reg); 00179 virtual ~celPcCommon (); 00180 00181 bool HavePropertyClassesChanged () 00182 { 00183 if (!propclasses_dirty) return false; 00184 propclasses_dirty = false; 00185 return true; 00186 } 00187 00188 virtual void SetTag (const char* tagname); 00189 virtual const char* GetTag () const { return tag; } 00190 00191 virtual void SetName (const char* pcname); 00192 virtual const char* GetName () const { return name; } 00193 00194 virtual iCelEntity* GetEntity () { return entity; } 00195 virtual void SetEntity (iCelEntity* entity); 00196 virtual bool AddPropertyChangeCallback (iCelPropertyChangeCallback* cb); 00197 virtual bool RemovePropertyChangeCallback ( 00198 iCelPropertyChangeCallback* cb); 00199 00200 virtual bool SetPropertyIndexed (int, long) { return false; } 00201 virtual bool SetPropertyIndexed (int, float) { return false; } 00202 virtual bool SetPropertyIndexed (int, bool) { return false; } 00203 virtual bool SetPropertyIndexed (int, const char*) { return false; } 00204 virtual bool SetPropertyIndexed (int, const csVector2&) { return false; } 00205 virtual bool SetPropertyIndexed (int, const csVector3&) { return false; } 00206 virtual bool SetPropertyIndexed (int, const csColor&) { return false; } 00207 virtual bool SetPropertyIndexed (int, iCelPropertyClass* pclass) 00208 { return false; } 00209 virtual bool SetPropertyIndexed (int, iCelEntity* entity) { return false; } 00210 virtual bool SetPropertyIndexed (int, iBase* ibase) { return false; } 00211 00212 virtual bool SetProperty (csStringID, long); 00213 virtual bool SetProperty (csStringID, float); 00214 virtual bool SetProperty (csStringID, bool); 00215 virtual bool SetProperty (csStringID, const char*); 00216 virtual bool SetProperty (csStringID, const csVector2&); 00217 virtual bool SetProperty (csStringID, const csVector3&); 00218 virtual bool SetProperty (csStringID, const csColor&); 00219 virtual bool SetProperty (csStringID, iCelPropertyClass* pclass); 00220 virtual bool SetProperty (csStringID, iCelEntity* entity); 00221 virtual bool SetProperty (csStringID, iBase* ibase); 00222 00223 virtual bool GetPropertyIndexed (int, long& l) { return false; } 00224 virtual bool GetPropertyIndexed (int, float& f) { return false; } 00225 virtual bool GetPropertyIndexed (int, bool& b) { return false; } 00226 virtual bool GetPropertyIndexed (int, const char*&) { return false; } 00227 virtual bool GetPropertyIndexed (int, csVector2&) { return false; } 00228 virtual bool GetPropertyIndexed (int, csVector3&) { return false; } 00229 virtual bool GetPropertyIndexed (int, csColor&) { return false; } 00230 virtual bool GetPropertyIndexed (int, iCelPropertyClass*&) { return false; } 00231 virtual bool GetPropertyIndexed (int, iCelEntity*&) { return false; } 00232 virtual bool GetPropertyIndexed (int, iBase*&) { return false; } 00233 00234 virtual long GetPropertyLongByID (csStringID); 00235 virtual float GetPropertyFloatByID (csStringID); 00236 virtual bool GetPropertyBoolByID (csStringID); 00237 virtual const char* GetPropertyStringByID (csStringID); 00238 virtual bool GetPropertyVectorByID (csStringID, csVector2&); 00239 virtual bool GetPropertyVectorByID (csStringID, csVector3&); 00240 virtual bool GetPropertyColorByID (csStringID, csColor&); 00241 virtual iCelPropertyClass* GetPropertyPClassByID (csStringID); 00242 virtual iCelEntity* GetPropertyEntityByID (csStringID); 00243 virtual iBase* GetPropertyIBaseByID (csStringID); 00244 00245 virtual bool PerformAction (csStringID, iCelParameterBlock*, celData& ret); 00246 virtual bool PerformActionIndexed (int, iCelParameterBlock*, celData& ret) 00247 { return false; } 00248 virtual const char* GetPropertyOrActionDescription (csStringID); 00249 virtual size_t GetPropertyAndActionCount (); 00250 virtual csStringID GetPropertyOrActionID (size_t); 00251 virtual void PropertyClassesHaveChanged () 00252 { 00253 propclasses_dirty = true; 00254 } 00255 virtual celDataType GetPropertyOrActionType (csStringID); 00256 virtual bool IsPropertyReadOnly (csStringID); 00257 00258 virtual csPtr<iCelDataBuffer> SaveFirstPass () { return 0; } 00259 virtual bool LoadFirstPass (iCelDataBuffer*) { return 0; } 00260 00261 virtual csPtr<iCelDataBuffer> GetPersistentData ( 00262 celPersistenceType persistence_type) 00263 { return 0; } 00264 virtual celPersistenceResult SetPersistentData (csTicks data_time, 00265 iCelDataBuffer* data, celPersistenceType persistence_type) 00266 { return CEL_PERSIST_RESULT_OK; }; 00267 00268 // --- For iCelTimerListener ----------------------------------------- 00269 virtual void TickEveryFrame () { } 00270 virtual void TickOnce () { } 00271 00272 // --- For iMessageSender -------------------------------------------- 00273 virtual void MessageDispatcherRemoved ( 00274 iMessageDispatcher* dispatcher) { } 00275 }; 00276 00277 #endif // __CEL_CELTOOL_STDPC__ 00278
Generated for CEL: Crystal Entity Layer 1.4.1 by doxygen 1.7.1