00001 #ifndef ERIS_ENTITY_H
00002 #define ERIS_ENTITY_H
00003
00004
00005 #include <sigc++/object.h>
00006 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0
00007 #include <sigc++/basic_signal.h>
00008 #else
00009 #include <sigc++/signal.h>
00010 #endif
00011
00012 #include <Atlas/Message/Object.h>
00013
00014 namespace Atlas {
00015 namespace Objects {
00016 namespace Entity {
00017 class RootEntity;
00018 class GameEntity;
00019 }
00020
00021 namespace Operation {
00022 class Move;
00023 class Set;
00024 class Sound;
00025 class Talk;
00026 }
00027 }
00028 }
00029
00030 #include <wfmath/point.h>
00031 #include <wfmath/vector.h>
00032 #include <wfmath/axisbox.h>
00033 #include <wfmath/quaternion.h>
00034
00035
00036 #include <Eris/Types.h>
00037 #include <Eris/SignalDispatcher.h>
00038
00039
00040 namespace Eris {
00041
00042
00043 class Entity;
00044 class World;
00045 class Dispatcher;
00046 class Property;
00047 class TypeInfo;
00048
00049 typedef std::vector<Entity*> EntityArray;
00050
00051 typedef std::map<std::string, Property*> PropertyMap;
00052
00054
00064 class Entity : virtual public SigC::Object
00065 {
00066 public:
00067 explicit Entity(const Atlas::Objects::Entity::GameEntity &ge, World *world);
00068 virtual ~Entity();
00069
00070
00071
00072
00073 Entity* getContainer() const
00074 { return _container; }
00075
00076 unsigned int getNumMembers() const
00077 { return _members.size(); }
00078
00079 bool hasBBox() const
00080 { return _hasBBox; }
00081
00082 Entity* getMember(unsigned int index);
00083
00084
00086
00088
00089
00090
00091
00092 virtual WFMath::Point<3> getPosition() const;
00093 virtual WFMath::Vector<3> getVelocity() const;
00094
00096 virtual WFMath::Quaternion getOrientation() const;
00097
00098 virtual WFMath::AxisBox<3> getBBox() const;
00099
00100
00102
00103 const std::string& getName() const { return _name;}
00104
00106 float getStamp() const
00107 { return _stamp; }
00108
00110 StringSet getInherits() const
00111 { return _parents; }
00112
00113 TypeInfo* Entity::getType() const;
00114
00115 World* getWorld() const
00116 { return _world; }
00117
00120 bool isVisible() const
00121 { return _visible; }
00122
00123
00124 SigC::Signal1<void, Entity*> AddedMember;
00125 SigC::Signal1<void, Entity*> RemovedMember;
00126
00128
00132 SigC::Signal2<void, Entity*, Entity*> Recontainered;
00133
00135 SigC::Signal1<void, const StringSet&> Changed;
00136
00139 SigC::Signal1<void, const WFMath::Point<3>&> Moved;
00140
00142 SigC::Signal1<void, const std::string&> Say;
00143
00146 template <class T>
00147 void connectOpToSlot(const std::string &op, const SigC::Slot1<void, const T&> &slot)
00148 { innerOpToSlot(new SignalDispatcher<T>(op, slot)); }
00149
00152 template <class T>
00153 void connectOpFromSlot(const std::string &op, SigC::Slot1<void, const T&> &slot)
00154 { innerOpFromSlot(new SignalDispatcher<T>(op, slot)); }
00155
00156 void observeProperty(const std::string &nm,
00157 const SigC::Slot1<void, const Atlas::Message::Object&> slot);
00158
00159 protected:
00161 explicit Entity(const std::string &id, World *world);
00162
00163
00164
00165 friend class World;
00166
00167 virtual void handleMove();
00168 virtual void handleTalk(const std::string &msg);
00169
00171 virtual void setProperty(const std::string &p, const Atlas::Message::Object &v);
00172
00173 virtual void setPosition(const WFMath::Point<3>& pt);
00175 virtual void setContainer(Entity *pr);
00176
00177 virtual void setContents(const Atlas::Message::Object::ListType &contents);
00178
00180 virtual void addMember(Entity *e);
00181
00183
00185 virtual void rmvMember(Entity *e);
00186
00190 virtual void setVisible(bool vis);
00191
00192 void setContainerById(const std::string &id);
00193
00194 const std::string _id;
00195 std::string _name;
00196 float _stamp;
00197 std::string _description;
00198 StringSet _parents;
00199 bool _visible;
00200
00201
00202 Entity* _container;
00203 EntityArray _members;
00204
00205 WFMath::AxisBox<3> _bbox;
00206 WFMath::Point<3> _position;
00207 WFMath::Vector<3> _velocity;
00208 WFMath::Quaternion _orientation;
00209
00210
00211 void beginUpdate();
00212 void endUpdate();
00213
00214 PropertyMap _properties;
00215
00219 bool _inUpdate;
00220
00224 bool _hasBBox;
00225
00230 StringSet _modified;
00231
00232 private:
00233
00234
00235
00236
00237
00238 void recvSight(const Atlas::Objects::Entity::GameEntity &ge);
00239 void recvMove(const Atlas::Objects::Operation::Move &mv);
00240 void recvSet(const Atlas::Objects::Operation::Set &st);
00241
00242 void recvSound(const Atlas::Objects::Operation::Sound &snd);
00243 void recvTalk(const Atlas::Objects::Operation::Talk &tk);
00244
00245 void innerOpFromSlot(Dispatcher *s);
00246 void innerOpToSlot(Dispatcher *s);
00247
00248
00249 StringList _localDispatchers;
00250
00251 World *_world;
00252 };
00253
00254
00255
00256 class Moveable : public Entity
00257 {
00258 typedef Entity Inherited;
00259 public:
00260 Moveable(const std::string &id);
00261 virtual ~Moveable();
00262
00263 virtual WFMath::Point<3> getPosition() const {return Inherited::getPosition();}
00264 void getPosition(bool predicted);
00265
00266 protected:
00267 WFMath::Vector<3> _velocity,
00268 _delta;
00269 };
00270
00271 class UnknownProperty : public InvalidOperation
00272 {
00273 public:
00274 UnknownProperty(const std::string &p, const std::string &m) :
00275 InvalidOperation(m), prop(p)
00276 {;}
00277 virtual ~UnknownProperty() throw () { }
00278
00279 const std::string prop;
00280 };
00281
00282 }
00283
00284 #endif