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> 21 #include <unordered_map> 22 #include <boost/optional.hpp> 27 typedef std::map<std::string, Element> MapType;
40 typedef std::vector<Entity*> EntityArray;
41 typedef std::vector<TypeInfoPtr> TypeInfoArray;
58 class Entity :
virtual public sigc::trackable
61 typedef std::map<std::string, Atlas::Message::Element> AttrMap;
71 virtual void shutdown();
79 size_t numContained()
const;
86 Entity* getContained(
size_t index)
const;
95 const Atlas::Message::Element& valueOfAttr(
const std::string& attr)
const;
102 bool hasAttr(
const std::string &p)
const;
111 const Atlas::Message::Element* ptrOfAttr(
const std::string& attr)
const;
125 sigc::connection observe(
const std::string& attr,
const AttrChangedSlot& aslot);
132 const std::string& getId()
const;
139 const std::string& getName()
const;
145 float getStamp()
const;
157 Entity* getLocation()
const;
163 WFMath::Point<3> getPosition()
const;
172 const AttrMap getAttributes()
const;
181 const AttrMap& getInstanceAttributes()
const;
187 bool isMoving()
const;
194 const WFMath::Point<3>& getPredictedPos()
const;
201 const WFMath::Vector<3>& getPredictedVelocity()
const;
207 const WFMath::Quaternion& getPredictedOrientation()
const;
210 WFMath::Point<3> getViewPosition()
const;
213 WFMath::Quaternion getViewOrientation()
const;
216 const WFMath::Vector< 3 > & getVelocity()
const;
219 const WFMath::Vector< 3 > & getAngularVelocity()
const;
222 const WFMath::Quaternion & getOrientation()
const;
225 const WFMath::AxisBox< 3 > & getBBox()
const;
232 bool hasBBox()
const;
238 const std::map<std::string, Task*>& getTasks()
const;
240 bool hasChild(
const std::string& eid)
const;
243 bool isVisible()
const;
257 static boost::optional<std::string> extractEntityId(
const Atlas::Message::Element& element);
261 C toLocationCoords(
const C& c)
const;
264 C fromLocationCoords(
const C& c)
const;
272 WFMath::Vector<3> toLocationCoords(
const WFMath::Vector<3>& v)
const;
274 WFMath::Vector<3> fromLocationCoords(
const WFMath::Vector<3>& v)
const;
277 sigc::signal<void, Entity*> ChildAdded;
278 sigc::signal<void, Entity*> ChildRemoved;
313 sigc::signal< void, const Atlas::Objects::Root & >
Say;
319 sigc::signal<void, const std::string&>
Emote;
326 sigc::signal<void, const Atlas::Objects::Operation::RootOperation&>
Acted;
333 sigc::signal<void, const Atlas::Objects::Root&>
Noise;
360 virtual void init(
const Atlas::Objects::Entity::RootEntity &ge,
bool fromCreateOp);
365 virtual void onTalk(
const Atlas::Objects::Operation::RootOperation& talk);
367 virtual void onAttrChanged(
const std::string& attr,
const Atlas::Message::Element &v);
369 virtual void onLocationChanged(
Entity* oldLoc);
373 virtual void onMoved();
378 virtual void onVisibilityChanged(
bool vis);
384 virtual void onAction(
const Atlas::Objects::Operation::RootOperation& act);
390 virtual void onSoundAction(
const Atlas::Objects::Operation::RootOperation& op);
396 virtual void onImaginary(
const Atlas::Objects::Root& act);
403 virtual void setMoving(
bool moving);
409 virtual void onChildAdded(
Entity* child);
415 virtual void onChildRemoved(
Entity* child);
421 virtual void onTaskAdded(
Task* task);
431 void sight(
const Atlas::Objects::Entity::RootEntity& gent);
440 void setFromRoot(
const Atlas::Objects::Root& obj,
bool allowMotion,
bool includeTypeInfoAttributes =
false);
444 void setVisible(
bool vis);
446 void setAttr(
const std::string &p,
const Atlas::Message::Element &v);
452 bool nativeAttrChanged(
const std::string &p,
const Atlas::Message::Element &v);
460 void typeInfo_AttributeChanges(
const std::string& attributeName,
const Atlas::Message::Element& element);
468 virtual void attrChangedFromTypeInfo(
const std::string& attributeName,
const Atlas::Message::Element& element);
477 void fillAttributesFromType(Entity::AttrMap& attributes,
TypeInfo* typeInfo)
const;
480 void addToUpdate(
const std::string& attr);
485 void setLocationFromAtlas(
const std::string& locId);
490 void setLocation(
Entity* newLocation);
494 void setContentsFromAtlas(
const StringList& contents);
500 void filterMoveAttrs(Atlas::Message::MapType& attrs)
const;
502 typedef std::unordered_map<std::string, Entity*> IdEntityMap;
503 void buildEntityDictFromContents(IdEntityMap& dict);
506 void removeChild(
Entity* e);
508 void addToLocation();
509 void removeFromLocation();
511 void updateTasks(
const Atlas::Message::Element& e);
515 void updateCalculatedVisibility(
bool wasVisible);
520 WFMath::Point<3> position;
521 WFMath::Vector<3> velocity;
522 WFMath::Quaternion orientation;
525 void updatePredictedState(
const WFMath::TimeStamp& t);
537 virtual void removeFromMovementPrediction() = 0;
543 virtual void addToMovementPredition() = 0;
549 virtual Entity* getEntity(
const std::string&
id) = 0;
558 EntityArray m_contents;
563 std::string m_description;
567 WFMath::Vector<3> m_scale;
568 WFMath::AxisBox<3> m_bbox;
569 WFMath::AxisBox<3> m_bboxUnscaled;
570 WFMath::Point<3> m_position;
571 WFMath::Vector<3> m_velocity;
572 WFMath::Quaternion m_orientation;
573 WFMath::Vector<3> m_acc;
598 typedef sigc::signal<void, const Atlas::Message::Element&> AttrChangedSignal;
600 typedef std::unordered_map<std::string, AttrChangedSignal> ObserverMap;
601 ObserverMap m_observers;
608 WFMath::TimeStamp m_lastMoveTime;
613 std::map<std::string, Task*> m_tasks;
618 inline size_t Entity::numContained()
const {
619 return m_contents.size();
622 inline Entity* Entity::getContained(
size_t index)
const {
623 return m_contents[index];
626 inline const std::string& Entity::getId()
const 631 inline const std::string& Entity::getName()
const 636 inline float Entity::getStamp()
const 647 inline Entity* Entity::getLocation()
const 653 inline WFMath::Point<3> Entity::getPosition()
const 658 inline const WFMath::Vector< 3 > & Entity::getVelocity()
const 663 inline const WFMath::Vector< 3 > & Entity::getAngularVelocity()
const 665 return m_angularVelocity;
669 inline const WFMath::Quaternion & Entity::getOrientation()
const 671 return m_orientation;
675 inline const WFMath::AxisBox< 3 > & Entity::getBBox()
const 680 inline bool Entity::hasBBox()
const 685 inline const std::map<std::string, Task*>& Entity::getTasks()
const 691 inline C Entity::toLocationCoords(
const C& c)
const 693 return c.toParentCoords(getPredictedPos(), m_orientation);
697 inline C Entity::fromLocationCoords(
const C& c)
const 699 return c.toLocalCoords(getPredictedPos(), m_orientation);
702 inline WFMath::Vector<3> Entity::toLocationCoords(
const WFMath::Vector<3>& v)
const 704 return WFMath::Vector<3>(v).rotate(m_orientation);
707 inline WFMath::Vector<3> Entity::fromLocationCoords(
const WFMath::Vector<3>& v)
const 709 return WFMath::Vector<3>(v).rotate(m_orientation.inverse());
sigc::signal< void, Task * > TaskAdded
Emitted when a task has been added to the entity.
Definition: Entity.h:351
sigc::signal< void > Moved
Emitted when then entity's position, orientation or velocity change.
Definition: Entity.h:292
sigc::signal< void, const Atlas::Objects::Root & > Noise
Emitted when this entity performs an action which causes a noise.
Definition: Entity.h:333
sigc::signal< void, const StringSet & > Changed
Emitted when one or more attributes change.
Definition: Entity.h:289
WFMath::Vector< 3 > m_angularVelocity
Angular velocity.
Definition: Entity.h:578
std::string m_name
a human readable name
Definition: Entity.h:561
The representation of an Atlas type (i.e a class or operation definition).
Definition: TypeInfo.h:31
sigc::slot< void, const Atlas::Message::Element & > AttrChangedSlot
A slot which can be used for receiving attribute update signals.
Definition: Entity.h:116
View encapsulates the set of entities currently visible to an Avatar, as well as those that have rece...
Definition: View.h:37
sigc::signal< void > BeingDeleted
Emitted prior to deletion.
Definition: Entity.h:346
bool m_limbo
waiting for parent bind
Definition: Entity.h:565
Definition: IGRouter.h:13
sigc::signal< void, Entity * > LocationChanged
Signal that the entity's container changed.
Definition: Entity.h:285
const std::string m_id
the Atlas object ID
Definition: Entity.h:560
sigc::signal< void, const Atlas::Objects::Root &> Say
Emitted with the entity speaks.
Definition: Entity.h:313
float m_stamp
last modification time (in seconds)
Definition: Entity.h:562
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
bool m_moving
flag recording if this entity is current considered in-motion
Definition: Entity.h:609
sigc::signal< void, bool > VisibilityChanged
Emitted when the visibility of the entity changes.
Definition: Entity.h:339
bool m_recentlyCreated
flag set if this entity was the subject of a sight(create)
Definition: Entity.h:611
sigc::signal< void, bool > Moving
Emitted when an entity starts or stops moving (as determined by the 'setMoving' method.
Definition: Entity.h:296
sigc::signal< void, Task * > TaskRemoved
Emitted when a task has been removed from the entity.
Definition: Entity.h:355
StringSet m_modifiedAttrs
When a batched property update is in progress, the set tracks the names of each modified property...
Definition: Entity.h:596
sigc::signal< void, const Atlas::Objects::Operation::RootOperation & > Acted
Emitted when this entity performs an action.
Definition: Entity.h:326
A service class querying and caching types.
Definition: TypeService.h:24
Entity is a concrete (instantiable) class representing one game entity.
Definition: Entity.h:58
sigc::signal< void, const std::string & > Emote
Emitted when this entity emits an imaginary operation (also known as an emote.
Definition: Entity.h:319
int m_updateLevel
If greater than zero, we are doing a batched update.
Definition: Entity.h:590
bool m_hasBBox
This flag should be set when the server notifies that this entity has a bounding box.
Definition: Entity.h:606
Definition: BaseConnection.h:18
float m_angularMag
The magnitude of the angular velocity.
Definition: Entity.h:582