00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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/csobject.h"
00028 #include "csutil/scf.h"
00029 #include "csutil/scf_implementation.h"
00030 #include "csutil/refarr.h"
00031 #include "csutil/weakref.h"
00032
00033 #include "celtool/celtoolextern.h"
00034
00035 #include "physicallayer/propchg.h"
00036 #include "physicallayer/propclas.h"
00037 #include "physicallayer/propfact.h"
00038 #include "physicallayer/pl.h"
00039 #include "physicallayer/messaging.h"
00040
00041 struct iCelEntity;
00042 struct iObjectRegistry;
00043
00044
00045 struct Property
00046 {
00047 csStringID id;
00048 celDataType datatype;
00049 bool readonly;
00050 const char* desc;
00051 Property () : id (csInvalidStringID) { }
00052 };
00053
00059 struct PropertyHolder
00060 {
00061 Property* properties;
00062 size_t propertycount;
00063
00064 bool actions_done;
00065
00066 csString mask;
00067
00072 csHash<int, csStringID> constants;
00073
00078 csHash<int, csStringID> new_constants;
00079
00080 PropertyHolder () : properties (0), propertycount (0), actions_done (false)
00081 { }
00082 ~PropertyHolder () { delete[] properties; }
00083 void SetCount (int cnt)
00084 {
00085 if (properties) return;
00086 propertycount = cnt;
00087 properties = new Property[cnt];
00088 }
00089 };
00090
00096 class CEL_CELTOOL_EXPORT celPcCommon
00097 : public scfImplementation4<celPcCommon, iCelPropertyClass, iCelTimerListener,
00098 iMessageSender,iMessageReceiver>
00099 {
00100 private:
00101 csRefArray<iCelPropertyChangeCallback> callbacks;
00102
00103
00104
00105
00106 bool propclasses_dirty;
00107 csString tag;
00108
00109 csObject csobj;
00110
00111 static csStringID id_tag;
00112 static csStringID id_name;
00113 static csStringID id_value;
00114
00115 protected:
00116 iCelEntity* entity;
00117 iObjectRegistry* object_reg;
00118 csWeakRef<iCelPlLayer> pl;
00119
00120 protected:
00121 void FirePropertyChangeCallback (int propertyId);
00122
00126 void SetActionMask (const char* mask);
00127
00131 void AddAction (int idx, const char* id)
00132 {
00133 propholder->actions_done = true;
00134 propholder->constants.Put (pl->FetchStringID (id), idx);
00135 csString newid = propholder->mask;
00136 CS_ASSERT (newid.Length () > 0);
00137 newid += id;
00138 propholder->new_constants.Put (pl->FetchStringID (newid), idx);
00139 }
00140
00152 void AddProperty (size_t idx, const char* id,
00153 celDataType type, bool readonly, const char* desc,
00154 void* prop)
00155 {
00156
00157 if (idx >= propholder->propertycount)
00158 {
00159 csRef<iReporter> rep = csQueryRegistry<iReporter>(object_reg);
00160 if (rep)
00161 rep->ReportError("crystalspace.cel.physicallayer",
00162 "celPcCommon::AddProperty out of bounds %zu >= %zu!",
00163 idx, propholder->propertycount);
00164 else
00165 csPrintf("Error: celPcCommon::AddProperty out of bounds %zu >= %zu!",
00166 idx, propholder->propertycount);
00167 return;
00168 }
00169 if (propdata == 0)
00170 {
00171 propdata = new void* [propholder->propertycount];
00172 }
00173 Property& pr = propholder->properties[idx];
00174 if (pr.id == csInvalidStringID)
00175 {
00176 pr.id = pl->FetchStringID (id);
00177 pr.datatype = type;
00178 pr.readonly = readonly;
00179 pr.desc = desc;
00180 propholder->constants.Put (pr.id, (int)idx);
00181 }
00182 propdata[idx] = prop;
00183 }
00184
00185 void** propdata;
00186 PropertyHolder* propholder;
00187
00188 private:
00189 template <class T>
00190 bool SetPropertyTemplated (csStringID propertyId, T l,
00191 celDataType type);
00192 template <class T>
00193 T GetPropertyTemplated (csStringID propertyId, celDataType type);
00194 template <class T>
00195 bool GetPropertyTemplated (csStringID propertyId, celDataType type, T& v);
00196
00197 public:
00198 celPcCommon (iObjectRegistry* object_reg);
00199 virtual ~celPcCommon ();
00200
00201 bool HavePropertyClassesChanged ()
00202 {
00203 if (!propclasses_dirty) return false;
00204 propclasses_dirty = false;
00205 return true;
00206 }
00207
00208 virtual void SetTag (const char* tagname);
00209 virtual const char* GetTag () const { return tag; }
00210
00211 virtual const char* GetName () const;
00212 virtual void SetName (const char* pcname);
00213
00214 iObject *QueryObject ();
00215
00216 virtual iCelEntity* GetEntity () { return entity; }
00217 virtual void SetEntity (iCelEntity* entity);
00218 virtual bool AddPropertyChangeCallback (iCelPropertyChangeCallback* cb);
00219 virtual bool RemovePropertyChangeCallback (
00220 iCelPropertyChangeCallback* cb);
00221
00222 virtual bool SetPropertyIndexed (int, long) { return false; }
00223 virtual bool SetPropertyIndexed (int, float) { return false; }
00224 virtual bool SetPropertyIndexed (int, bool) { return false; }
00225 virtual bool SetPropertyIndexed (int, const char*) { return false; }
00226 virtual bool SetPropertyIndexed (int, const csVector2&) { return false; }
00227 virtual bool SetPropertyIndexed (int, const csVector3&) { return false; }
00228 virtual bool SetPropertyIndexed (int, const csColor&) { return false; }
00229 virtual bool SetPropertyIndexed (int, iCelPropertyClass* pclass)
00230 { return false; }
00231 virtual bool SetPropertyIndexed (int, iCelEntity* entity) { return false; }
00232 virtual bool SetPropertyIndexed (int, iBase* ibase) { return false; }
00233
00234 virtual bool SetProperty (csStringID, long);
00235 virtual bool SetProperty (csStringID, float);
00236 virtual bool SetProperty (csStringID, bool);
00237 virtual bool SetProperty (csStringID, const char*);
00238 virtual bool SetProperty (csStringID, const csVector2&);
00239 virtual bool SetProperty (csStringID, const csVector3&);
00240 virtual bool SetProperty (csStringID, const csColor&);
00241 virtual bool SetProperty (csStringID, iCelPropertyClass* pclass);
00242 virtual bool SetProperty (csStringID, iCelEntity* entity);
00243 virtual bool SetProperty (csStringID, iBase* ibase);
00244
00245 virtual bool GetPropertyIndexed (int, long& l) { return false; }
00246 virtual bool GetPropertyIndexed (int, float& f) { return false; }
00247 virtual bool GetPropertyIndexed (int, bool& b) { return false; }
00248 virtual bool GetPropertyIndexed (int, const char*&) { return false; }
00249 virtual bool GetPropertyIndexed (int, csVector2&) { return false; }
00250 virtual bool GetPropertyIndexed (int, csVector3&) { return false; }
00251 virtual bool GetPropertyIndexed (int, csColor&) { return false; }
00252 virtual bool GetPropertyIndexed (int, iCelPropertyClass*&) { return false; }
00253 virtual bool GetPropertyIndexed (int, iCelEntity*&) { return false; }
00254 virtual bool GetPropertyIndexed (int, iBase*&) { return false; }
00255
00256 virtual long GetPropertyLongByID (csStringID);
00257 virtual float GetPropertyFloatByID (csStringID);
00258 virtual bool GetPropertyBoolByID (csStringID);
00259 virtual const char* GetPropertyStringByID (csStringID);
00260 virtual bool GetPropertyVectorByID (csStringID, csVector2&);
00261 virtual bool GetPropertyVectorByID (csStringID, csVector3&);
00262 virtual bool GetPropertyColorByID (csStringID, csColor&);
00263 virtual iCelPropertyClass* GetPropertyPClassByID (csStringID);
00264 virtual iCelEntity* GetPropertyEntityByID (csStringID);
00265 virtual iBase* GetPropertyIBaseByID (csStringID);
00266
00267 virtual bool PerformAction (csStringID, iCelParameterBlock*, celData& ret);
00268 virtual bool PerformActionIndexed (int, iCelParameterBlock*, celData& ret)
00269 { return false; }
00270 virtual const char* GetPropertyOrActionDescription (csStringID);
00271 virtual size_t GetPropertyAndActionCount ();
00272 virtual csStringID GetPropertyOrActionID (size_t);
00273 virtual void PropertyClassesHaveChanged ()
00274 {
00275 propclasses_dirty = true;
00276 }
00277 virtual celDataType GetPropertyOrActionType (csStringID);
00278 virtual bool IsPropertyReadOnly (csStringID);
00279
00280 virtual csPtr<iCelDataBuffer> SaveFirstPass () { return 0; }
00281 virtual bool LoadFirstPass (iCelDataBuffer*) { return false; }
00282
00283 virtual csPtr<iCelDataBuffer> Save () { return 0; }
00284 virtual bool Load (iCelDataBuffer* databuf) { return false; }
00285
00286 virtual csPtr<iCelDataBuffer> GetPersistentData (
00287 celPersistenceType persistence_type)
00288 { return 0; }
00289 virtual celPersistenceResult SetPersistentData (csTicks data_time,
00290 iCelDataBuffer* data, celPersistenceType persistence_type)
00291 { return CEL_PERSIST_RESULT_OK; };
00292
00293
00294 virtual void TickEveryFrame () { }
00295 virtual void TickOnce () { }
00296
00297
00298 virtual void MessageDispatcherRemoved (iMessageDispatcher* dispatcher) { }
00299
00300
00301 virtual bool ReceiveMessage (csStringID msg_id, iMessageSender* sender,
00302 celData& ret, iCelParameterBlock* params);
00303 };
00304
00305 #endif // __CEL_CELTOOL_STDPC__
00306