4 #include <Eris/Types.h>
6 #include <Atlas/Objects/ObjectsFwd.h>
8 #include <wfmath/point.h>
9 #include <wfmath/vector.h>
10 #include <wfmath/axisbox.h>
11 #include <wfmath/quaternion.h>
12 #include <wfmath/timestamp.h>
14 #include <sigc++/trackable.h>
15 #include <sigc++/slot.h>
16 #include <sigc++/signal.h>
17 #include <sigc++/connection.h>
25 typedef std::map<std::string, Element> MapType;
38 typedef std::vector<Entity*> EntityArray;
39 typedef std::vector<Task*> TaskArray;
40 typedef std::vector<TypeInfoPtr> TypeInfoArray;
57 class Entity :
virtual public sigc::trackable
60 typedef std::map<std::string, Atlas::Message::Element> AttrMap;
94 const Atlas::Message::Element&
valueOfAttr(
const std::string& attr)
const;
101 bool hasAttr(
const std::string &p)
const;
122 const std::string&
getId()
const;
129 const std::string&
getName()
const;
199 const WFMath::Vector< 3 > &
getVelocity(
void)
const;
205 const WFMath::AxisBox< 3 > &
getBBox(
void)
const;
227 bool hasChild(
const std::string& eid)
const;
244 static bool extractEntityId(
const Atlas::Message::Element& element, std::string&
id);
248 C toLocationCoords(
const C& c)
const;
251 C fromLocationCoords(
const C& c)
const;
259 WFMath::Vector<3> toLocationCoords(
const WFMath::Vector<3>& v)
const;
261 WFMath::Vector<3> fromLocationCoords(
const WFMath::Vector<3>& v)
const;
264 sigc::signal<void, Entity*> ChildAdded;
265 sigc::signal<void, Entity*> ChildRemoved;
300 sigc::signal< void, const Atlas::Objects::Root & >
Say;
306 sigc::signal<void, const std::string&>
Emote;
313 sigc::signal<void, const Atlas::Objects::Operation::RootOperation&>
Acted;
320 sigc::signal<void, const Atlas::Objects::Root&>
Noise;
347 virtual void init(
const Atlas::Objects::Entity::RootEntity &ge,
bool fromCreateOp);
352 virtual void onTalk(
const Atlas::Objects::Operation::RootOperation& talk);
354 virtual void onAttrChanged(
const std::string& attr,
const Atlas::Message::Element &v);
356 virtual void onLocationChanged(
Entity* oldLoc);
371 virtual void onAction(
const Atlas::Objects::Operation::RootOperation& act);
377 virtual void onSoundAction(
const Atlas::Objects::Operation::RootOperation& op);
383 virtual void onImaginary(
const Atlas::Objects::Root& act);
418 void sight(
const Atlas::Objects::Entity::RootEntity& gent);
427 void setFromRoot(
const Atlas::Objects::Root& obj,
bool allowMotion,
bool includeTypeInfoAttributes =
false);
433 void setAttr(
const std::string &p,
const Atlas::Message::Element &v);
455 virtual void attrChangedFromTypeInfo(
const std::string& attributeName,
const Atlas::Message::Element& element);
467 void addToUpdate(
const std::string& attr);
489 typedef std::map<std::string, Entity*> IdEntityMap;
490 void buildEntityDictFromContents(IdEntityMap& dict);
493 void removeChild(
Entity* e);
495 void addToLocation();
496 void removeFromLocation();
498 void updateTasks(
const Atlas::Message::Element& e);
499 void removeTask(
Task* t);
508 WFMath::Point<3> position;
509 WFMath::Vector<3> velocity;
512 void updatePredictedState(
const WFMath::TimeStamp& t);
514 void createAlarmExpired();
547 EntityArray m_contents;
552 std::string m_description;
556 WFMath::AxisBox<3> m_bbox;
557 WFMath::Point<3> m_position;
558 WFMath::Vector<3> m_velocity;
559 WFMath::Quaternion m_orientation;
560 WFMath::Vector<3> m_acc;
576 typedef sigc::signal<void, const Atlas::Message::Element&> AttrChangedSignal;
578 typedef std::map<std::string, AttrChangedSignal> ObserverMap;
579 ObserverMap m_observers;
586 WFMath::TimeStamp m_lastMoveTime;
597 return m_contents.size();
601 return m_contents[index];
644 return m_orientation;
664 inline C Entity::toLocationCoords(
const C& c)
const
670 inline C Entity::fromLocationCoords(
const C& c)
const
675 inline WFMath::Vector<3> Entity::toLocationCoords(
const WFMath::Vector<3>& v)
const
677 return WFMath::Vector<3>(v).rotate(m_orientation);
680 inline WFMath::Vector<3> Entity::fromLocationCoords(
const WFMath::Vector<3>& v)
const
682 return WFMath::Vector<3>(v).rotate(m_orientation.inverse());
sigc::signal< void, const Atlas::Objects::Root & > Say
Emitted with the entity speaks.
Definition: Entity.h:300
bool isVisible() const
determine if this entity is visible.
Definition: Entity.cpp:785
virtual void onChildAdded(Entity *child)
Over-rideable hook when child entities are added.
Definition: Entity.cpp:362
void setContentsFromAtlas(const StringList &contents)
wrapper for setLocation with additional code the retrive the location if it's not available right now
Definition: Entity.cpp:693
bool hasAttr(const std::string &p) const
Checks whether an attribute exists.
Definition: Entity.cpp:124
void typeInfo_AttributeChanges(const std::string &attributeName, const Atlas::Message::Element &element)
Connected to the TypeInfo::AttributeChanges event.
Definition: Entity.cpp:472
sigc::connection observe(const std::string &attr, const AttrChangedSlot &aslot)
Setup an observer so that the specified slot is fired when the named attribue's value changes.
Definition: Entity.cpp:163
virtual void onSoundAction(const Atlas::Objects::Operation::RootOperation &op)
Over-rideable hook when this entity is heard performing an action.
Definition: Entity.cpp:332
const Atlas::Message::Element & valueOfAttr(const std::string &attr) const
Gets the value of a named attribute.
Definition: Entity.cpp:104
void setLocationFromAtlas(const std::string &locId)
update the entity's location based on Atlas data.
Definition: Entity.cpp:626
Entity * getLocation() const
The containing entity, or null if this is a top-level visible entity.
Definition: Entity.h:625
Entity * getContained(unsigned int index) const
Gets the child entity at the specified index.
Definition: Entity.h:600
Entity is a concrete (instantiable) class representing one game entity.
Definition: Entity.h:58
WFMath::Point< 3 > getPosition() const
Returns the Entity's position inside it's parent in the parent's local system coordinates.
Definition: Entity.h:631
const std::string m_id
the Atlas object ID
Definition: Entity.h:549
sigc::signal< void, const std::string & > Emote
Emitted when this entity emits an imaginary operation (also known as an emote.
Definition: Entity.h:306
sigc::signal< void, const StringSet & > Changed
Emitted when one or more attributes change.
Definition: Entity.h:276
bool hasBBox() const
Returns true if the entity has a bounding box.
Definition: Entity.h:653
sigc::slot< void, const Atlas::Message::Element & > AttrChangedSlot
A slot which can be used for receiving attribute update signals.
Definition: Entity.h:106
bool m_hasBBox
This flag should be set when the server notifies that this entity has a bounding box.
Definition: Entity.h:584
void updateCalculatedVisibility(bool wasVisible)
recursively update the real visiblity of this entity, and fire appropriate signals.
Definition: Entity.cpp:795
bool isMoving() const
Test if this entity has a non-zero velocity vector.
Definition: Entity.cpp:206
sigc::signal< void, Task * > TaskAdded
Emitted when a task has been added to the entity.
Definition: Entity.h:338
virtual TypeService * getTypeService() const =0
Gets the typeservice used throughout the Eris system.
Definition: IGRouter.h:14
virtual void onChildRemoved(Entity *child)
Over-rideable hook when child entities are removed.
Definition: Entity.cpp:367
bool m_limbo
waiting for parent bind
Definition: Entity.h:554
A service class querying and caching types.
Definition: TypeService.h:25
const TaskArray & getTasks() const
Gets the tasks associated with this entity.
Definition: Entity.h:658
void setLocation(Entity *newLocation)
setLocation is the core of the entity hierarchy maintenance logic.
Definition: Entity.cpp:648
const WFMath::Vector< 3 > & getVelocity(void) const
Returns the entity's velocity as last set explicitely.
Definition: Entity.h:636
WFMath::Quaternion getViewOrientation() const
retreive this Entity's orientation in view coordinates.
Definition: Entity.cpp:180
void setAttr(const std::string &p, const Atlas::Message::Element &v)
Definition: Entity.cpp:380
sigc::signal< void, Task * > TaskRemoved
Emitted when a task has been removed from the entity.
Definition: Entity.h:342
virtual void onMoved()
over-rideable hook method when then Entity position, orientation or velocity change.
Definition: Entity.cpp:322
TypeInfo * getType() const
Gets the type of this entity.
Definition: Entity.h:619
void setFromRoot(const Atlas::Objects::Root &obj, bool allowMotion, bool includeTypeInfoAttributes=false)
Initialise all simple state from a Root.
Definition: Entity.cpp:265
const AttrMap getAttributes() const
Gets all attributes defined for this entity.
Definition: Entity.cpp:138
const TypeInfoSet & getParents() const
Gets the currently resolved parent TypeInfo instances.
Definition: TypeInfo.h:206
Definition: LogStream.h:56
virtual void removeFromMovementPrediction()=0
Removes the entity from any movement prediction service.
float getStamp() const
Access the current time-stamp of the entity.
Definition: Entity.h:614
StringSet m_modifiedAttrs
When a batched property update is in progress, the set tracks the names of each modified property.
Definition: Entity.h:574
virtual void onVisibilityChanged(bool vis)
over-rideable hook when the actual (computed) visiblity of this entity changed.
Definition: Entity.cpp:822
static bool extractEntityId(const Atlas::Message::Element &element, std::string &id)
Extracts an entity id from the supplied element.
Definition: Entity.cpp:832
sigc::signal< void > BeingDeleted
Emitted prior to deletion.
Definition: Entity.h:333
WFMath::Vector< 3 > getPredictedVelocity() const
Retrieve the current predicted velocity of an entity.
Definition: Entity.cpp:201
const WFMath::Quaternion & getOrientation(void) const
Returns the entity's orientation as last set explicitely.
Definition: Entity.h:642
TypeInfoPtr getTypeByName(const std::string &tynm)
find the TypeInfo for the named type; this may involve a search, or a map lookup.
Definition: TypeService.cpp:62
const std::string & getId() const
Retrieve the unique entity ID.
Definition: Entity.h:604
bool nativeAttrChanged(const std::string &p, const Atlas::Message::Element &v)
Map Atlas attributes to natively stored properties.
Definition: Entity.cpp:425
virtual void addToMovementPredition()=0
Adds the entity to any movement prediction service.
void filterMoveAttrs(Atlas::Message::MapType &attrs) const
Remove from a map all items whose key is a movement related attribute, eg position or velocity.
Definition: Entity.cpp:295
virtual void onTaskAdded(Task *task)
Over-rideable hook for when tasks are added.
Definition: Entity.cpp:372
virtual void init(const Atlas::Objects::Entity::RootEntity &ge, bool fromCreateOp)
over-rideable initialisation helper.
Definition: Entity.cpp:90
Definition: Exceptions.h:29
sigc::signal< void > Moved
Emitted when then entity's position, orientation or velocity change.
Definition: Entity.h:279
const WFMath::AxisBox< 3 > & getBBox(void) const
Returns the entity's bounding box in the entity's local system coordinates.
Definition: Entity.h:648
void fillAttributesFromType(Entity::AttrMap &attributes, TypeInfo *typeInfo) const
Utility method for recursively filling a map of attributes from a TypeInfo instance.
Definition: Entity.cpp:154
The representation of an Atlas type (i.e a class or operation definition).
Definition: TypeInfo.h:38
virtual void setMoving(bool moving)
over-rideable hook for when the entity changes from stationary to moving or vice-versa.
Definition: Entity.cpp:345
const Atlas::Message::MapType & getAttributes() const
Gets the default attributes for this entity type.
Definition: TypeInfo.h:186
int m_updateLevel
If greater than zero, we are doing a batched update.
Definition: Entity.h:568
WFMath::Point< 3 > getViewPosition() const
retreive this Entity's position in view coordinates.
Definition: Entity.cpp:169
void setVisible(bool vis)
the View calls this to change local entity visibility.
Definition: Entity.cpp:773
std::string m_name
a human readable name
Definition: Entity.h:550
void sight(const Atlas::Objects::Entity::RootEntity &gent)
Fully initialise all entity state based on a RootEntity, including location and contents.
Definition: Entity.cpp:257
const AttrMap & getInstanceAttributes() const
Gets all locally defined attributes.
Definition: Entity.cpp:149
const Atlas::Message::Element * getAttribute(const std::string &attributeName) const
Gets the value of the named attribute.
Definition: TypeInfo.cpp:216
sigc::signal< void, const Atlas::Objects::Root & > Noise
Emitted when this entity performs an action which causes a noise.
Definition: Entity.h:320
bool m_recentlyCreated
flag set if this entity was the subject of a sight(create)
Definition: Entity.h:589
virtual void attrChangedFromTypeInfo(const std::string &attributeName, const Atlas::Message::Element &element)
Called when an attribute has been changed in the TypeInfo for this entity.
Definition: Entity.cpp:477
sigc::signal< void, Entity * > LocationChanged
Signal that the entity's container changed.
Definition: Entity.h:272
bool m_moving
flag recording if this entity is current considered in-motion
Definition: Entity.h:587
Definition: LogStream.h:46
const std::string & getName() const
Gets the name of the entity.
Definition: Entity.h:609
sigc::signal< void, const Atlas::Objects::Operation::RootOperation & > Acted
Emitted when this entity performs an action.
Definition: Entity.h:313
virtual Entity * getEntity(const std::string &id)=0
Gets an entity with the supplied id from the system.
virtual void onTalk(const Atlas::Objects::Operation::RootOperation &talk)
process TALK data - default implementation emits the Say signal.
Definition: Entity.cpp:304
float m_stamp
last modification time (in seconds)
Definition: Entity.h:551
View encapsulates the set of entities currently visible to an Avatar, as well as those that have rece...
Definition: View.h:34
unsigned int numContained() const
Gets the number of contained entities, i.e.
Definition: Entity.h:596
virtual void shutdown()
Shuts down the entity.
Definition: Entity.cpp:65
virtual void onImaginary(const Atlas::Objects::Root &act)
Over-rideable hook when this entity is seen to emit an imginary op.
Definition: Entity.cpp:337
WFMath::Point< 3 > getPredictedPos() const
Retrieve the predicted position of this entity, based on it's velocity and acceleration.
Definition: Entity.cpp:191
sigc::signal< void, bool > VisibilityChanged
Emitted when the visibility of the entity changes.
Definition: Entity.h:326
TypeInfoArray getUseOperations() const
Get a list of operations supported by this entity (tool) If the entity does no provide an operations ...
Definition: Entity.cpp:226
sigc::signal< void, bool > Moving
Emitted when an entity starts or stops moving (as determined by the 'inMotion' method.
Definition: Entity.h:283
virtual void onAction(const Atlas::Objects::Operation::RootOperation &act)
Over-rideable hook when this entity is seen to perform an action.
Definition: Entity.cpp:327