CEL

Public API Reference

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   // the name of the property class
00092   const char* name;
00093 
00094 protected:
00095   iCelEntity* entity;
00096   iObjectRegistry* object_reg;
00097   csWeakRef<iCelPlLayer> pl;
00098 
00099 protected:
00100   void FirePropertyChangeCallback (int propertyId);
00101 
00105   void AddAction (int idx, const char* id)
00106   {
00107     propholder->actions_done = true;
00108     propholder->constants.Put (pl->FetchStringID (id), idx);
00109   }
00110 
00122   void AddProperty (int idx, const char* id,
00123         celDataType type, bool readonly, const char* desc,
00124         void* prop)
00125   {
00126     if (propdata == 0)
00127     {
00128       propdata = new void* [propholder->propertycount];
00129     }
00130     Property& pr = propholder->properties[idx];
00131     if (pr.id == csInvalidStringID)
00132     {
00133       pr.id = pl->FetchStringID (id);
00134       pr.datatype = type;
00135       pr.readonly = readonly;
00136       pr.desc = desc;
00137       propholder->constants.Put (pr.id, idx);
00138     }
00139     propdata[idx] = prop;
00140   }
00141 
00142   void** propdata;
00143   PropertyHolder* propholder;
00144 
00145 private:
00146   template <class T>
00147   bool SetPropertyTemplated (csStringID propertyId, T l,
00148     celDataType type);
00149   template <class T>
00150   T GetPropertyTemplated (csStringID propertyId, celDataType type);
00151   template <class T>
00152   bool GetPropertyTemplated (csStringID propertyId, celDataType type, T& v);
00153 
00154 public:
00155   celPcCommon (iObjectRegistry* object_reg);
00156   virtual ~celPcCommon ();
00157 
00158   bool HavePropertyClassesChanged ()
00159   {
00160     if (!propclasses_dirty) return false;
00161     propclasses_dirty = false;
00162     return true;
00163   }
00164 
00165   virtual void SetTag (const char* tagname);
00166   virtual const char* GetTag () const { return tag; }
00167 
00168   virtual void SetName (const char* pcname);
00169   virtual const char* GetName () const { return name; }
00170 
00171   virtual iCelEntity* GetEntity () { return entity; }
00172   virtual void SetEntity (iCelEntity* entity);
00173   virtual bool AddPropertyChangeCallback (iCelPropertyChangeCallback* cb);
00174   virtual bool RemovePropertyChangeCallback (
00175         iCelPropertyChangeCallback* cb);
00176 
00177   virtual bool SetPropertyIndexed (int, long) { return false; }
00178   virtual bool SetPropertyIndexed (int, float) { return false; }
00179   virtual bool SetPropertyIndexed (int, bool) { return false; }
00180   virtual bool SetPropertyIndexed (int, const char*) { return false; }
00181   virtual bool SetPropertyIndexed (int, const csVector2&) { return false; }
00182   virtual bool SetPropertyIndexed (int, const csVector3&) { return false; }
00183   virtual bool SetPropertyIndexed (int, const csColor&) { return false; }
00184   virtual bool SetPropertyIndexed (int, iCelPropertyClass* pclass)
00185   { return false; }
00186   virtual bool SetPropertyIndexed (int, iCelEntity* entity) { return false; }
00187   virtual bool SetPropertyIndexed (int, iBase* ibase) { return false; }
00188 
00189   virtual bool SetProperty (csStringID, long);
00190   virtual bool SetProperty (csStringID, float);
00191   virtual bool SetProperty (csStringID, bool);
00192   virtual bool SetProperty (csStringID, const char*);
00193   virtual bool SetProperty (csStringID, const csVector2&);
00194   virtual bool SetProperty (csStringID, const csVector3&);
00195   virtual bool SetProperty (csStringID, const csColor&);
00196   virtual bool SetProperty (csStringID, iCelPropertyClass* pclass);
00197   virtual bool SetProperty (csStringID, iCelEntity* entity);
00198   virtual bool SetProperty (csStringID, iBase* ibase);
00199 
00200   virtual bool GetPropertyIndexed (int, long& l) { return false; }
00201   virtual bool GetPropertyIndexed (int, float& f) { return false; }
00202   virtual bool GetPropertyIndexed (int, bool& b) { return false; }
00203   virtual bool GetPropertyIndexed (int, const char*&) { return false; }
00204   virtual bool GetPropertyIndexed (int, csVector2&) { return false; }
00205   virtual bool GetPropertyIndexed (int, csVector3&) { return false; }
00206   virtual bool GetPropertyIndexed (int, csColor&) { return false; }
00207   virtual bool GetPropertyIndexed (int, iCelPropertyClass*&) { return false; }
00208   virtual bool GetPropertyIndexed (int, iCelEntity*&) { return false; }
00209   virtual bool GetPropertyIndexed (int, iBase*&) { return false; }
00210 
00211   virtual long GetPropertyLongByID (csStringID);
00212   virtual float GetPropertyFloatByID (csStringID);
00213   virtual bool GetPropertyBoolByID (csStringID);
00214   virtual const char* GetPropertyStringByID (csStringID);
00215   virtual bool GetPropertyVectorByID (csStringID, csVector2&);
00216   virtual bool GetPropertyVectorByID (csStringID, csVector3&);
00217   virtual bool GetPropertyColorByID (csStringID, csColor&);
00218   virtual iCelPropertyClass* GetPropertyPClassByID (csStringID);
00219   virtual iCelEntity* GetPropertyEntityByID (csStringID);
00220   virtual iBase* GetPropertyIBaseByID (csStringID);
00221 
00222   virtual long GetPropertyLong (csStringID id)
00223   {
00224     return GetPropertyLongByID (id);
00225   }
00226   virtual float GetPropertyFloat (csStringID id)
00227   {
00228     return GetPropertyFloatByID (id);
00229   }
00230   virtual bool GetPropertyBool (csStringID id)
00231   {
00232     return GetPropertyBoolByID (id);
00233   }
00234   virtual const char* GetPropertyString (csStringID id)
00235   {
00236     return GetPropertyStringByID (id);
00237   }
00238   virtual bool GetPropertyVector (csStringID id, csVector2& v)
00239   {
00240     return GetPropertyVectorByID (id, v);
00241   }
00242   virtual bool GetPropertyVector (csStringID id, csVector3& v)
00243   {
00244     return GetPropertyVectorByID (id, v);
00245   }
00246   virtual bool GetPropertyColor (csStringID id, csColor& c)
00247   {
00248     return GetPropertyColorByID (id, c);
00249   }
00250   virtual iCelPropertyClass* GetPropertyPClass (csStringID id)
00251   {
00252     return GetPropertyPClassByID (id);
00253   }
00254   virtual iCelEntity* GetPropertyEntity (csStringID id)
00255   {
00256     return GetPropertyEntityByID (id);
00257   }
00258   virtual iBase* GetPropertyIBase (csStringID id)
00259   {
00260     return GetPropertyIBaseByID (id);
00261   }
00262 
00263   virtual bool PerformAction (csStringID, iCelParameterBlock*, celData& ret);
00264   virtual bool PerformActionIndexed (int, iCelParameterBlock*, celData& ret)
00265   { return false; }
00266   virtual const char* GetPropertyOrActionDescription (csStringID);
00267   virtual size_t GetPropertyAndActionCount ();
00268   virtual csStringID GetPropertyOrActionID (size_t);
00269   virtual void PropertyClassesHaveChanged ()
00270   {
00271     propclasses_dirty = true;
00272   }
00273   virtual celDataType GetPropertyOrActionType (csStringID);
00274   virtual bool IsPropertyReadOnly (csStringID);
00275 
00276   virtual csPtr<iCelDataBuffer> SaveFirstPass () { return 0; }
00277   virtual bool LoadFirstPass (iCelDataBuffer*) { return 0; }
00278 
00279   virtual csPtr<iCelDataBuffer> GetPersistentData (
00280         celPersistenceType persistence_type)
00281     { return 0; }
00282   virtual celPersistenceResult SetPersistentData (csTicks data_time, 
00283         iCelDataBuffer* data, celPersistenceType persistence_type)
00284     { return CEL_PERSIST_RESULT_OK; };
00285 
00286   // --- For iCelTimerListener -----------------------------------------
00287   virtual void TickEveryFrame () { }
00288   virtual void TickOnce () { }
00289 };
00290 
00291 #endif // __CEL_CELTOOL_STDPC__
00292 

Generated for CEL: Crystal Entity Layer 1.2 by doxygen 1.4.7