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;
55 class Entity :
virtual public sigc::trackable
59 typedef std::map<std::string, Atlas::Message::Element> PropertyMap;
70 size_t numContained()
const;
77 Entity* getContained(
size_t index)
const;
102 const Atlas::Message::Element& valueOfProperty(
const std::string& name)
const;
109 bool hasProperty(
const std::string &p)
const;
118 const Atlas::Message::Element* ptrOfProperty(
const std::string& name)
const;
133 sigc::connection observe(
const std::string& propertyName,
const PropertyChangedSlot& aslot,
bool evaluateNow);
140 const std::string& getId()
const;
147 const std::string& getName()
const;
153 double getStamp()
const;
165 Entity* getLocation()
const;
171 const WFMath::Point<3>& getPosition()
const;
184 PropertyMap getProperties()
const;
197 const PropertyMap& getInstanceProperties()
const;
203 bool isMoving()
const;
210 const WFMath::Point<3>& getPredictedPos()
const;
217 const WFMath::Vector<3>& getPredictedVelocity()
const;
223 const WFMath::Quaternion& getPredictedOrientation()
const;
226 const WFMath::Vector<3> & getVelocity()
const;
229 const WFMath::Vector<3> & getAngularVelocity()
const;
232 const WFMath::Quaternion & getOrientation()
const;
235 const WFMath::AxisBox<3> & getBBox()
const;
242 bool hasBBox()
const;
248 const std::map<std::string, std::unique_ptr<Task>>& getTasks()
const;
250 bool hasChild(
const std::string& eid)
const;
253 bool isVisible()
const;
267 static boost::optional<std::string> extractEntityId(
const Atlas::Message::Element& element);
271 C toLocationCoords(
const C& c)
const;
274 C fromLocationCoords(
const C& c)
const;
277 const std::vector<Entity*>& getContent()
const {
287 WFMath::Vector<3> toLocationCoords(
const WFMath::Vector<3>& v)
const;
289 WFMath::Vector<3> fromLocationCoords(
const WFMath::Vector<3>& v)
const;
292 sigc::signal<void, Entity*> ChildAdded;
293 sigc::signal<void, Entity*> ChildRemoved;
304 sigc::signal<void, const std::set<std::string>&>
Changed;
327 sigc::signal< void, const Atlas::Objects::Root & >
Say;
333 sigc::signal<void, const std::string&>
Emote;
340 sigc::signal<void, const Atlas::Objects::Operation::RootOperation&, const TypeInfo&>
Acted;
345 sigc::signal<void, const Atlas::Objects::Operation::Hit&, const TypeInfo&>
Hit;
352 sigc::signal<void, const Atlas::Objects::Root&, const TypeInfo&>
Noise;
370 sigc::signal<void, const std::string&, Task*>
TaskAdded;
379 virtual void init(
const Atlas::Objects::Entity::RootEntity &ge,
bool fromCreateOp);
391 virtual void onTalk(
const Atlas::Objects::Operation::RootOperation& talk);
393 virtual void onPropertyChanged(
const std::string& propertyName,
const Atlas::Message::Element &v);
395 virtual void onLocationChanged(
Entity* oldLoc);
399 virtual void onMoved(
const WFMath::TimeStamp& timeStamp);
404 virtual void onVisibilityChanged(
bool vis);
410 virtual void onAction(
const Atlas::Objects::Operation::RootOperation& act,
const TypeInfo& typeInfo);
416 virtual void onHit(
const Atlas::Objects::Operation::Hit& hit,
const TypeInfo& typeInfo);
422 virtual void onSoundAction(
const Atlas::Objects::Operation::RootOperation& op,
const TypeInfo& typeInfo);
428 virtual void onImaginary(
const Atlas::Objects::Root& act);
435 virtual void setMoving(
bool moving);
441 virtual void onChildAdded(
Entity* child);
447 virtual void onChildRemoved(
Entity* child);
454 virtual void onTaskAdded(
const std::string&
id,
Task* task);
466 void firstSight(
const Atlas::Objects::Entity::RootEntity& gent);
474 void setFromRoot(
const Atlas::Objects::Root& obj,
bool includeTypeInfoProperties =
false);
478 void setVisible(
bool vis);
480 void setProperty(
const std::string &p,
const Atlas::Message::Element &v);
486 bool nativePropertyChanged(
const std::string &p,
const Atlas::Message::Element &v);
494 void typeInfo_PropertyChanges(
const std::string& propertyName,
const Atlas::Message::Element& element);
503 virtual void propertyChangedFromTypeInfo(
const std::string& propertyName,
const Atlas::Message::Element& element);
512 void fillPropertiesFromType(Entity::PropertyMap& properties,
const TypeInfo& typeInfo)
const;
515 void addToUpdate(
const std::string& propertyName);
520 void setLocationFromAtlas(
const std::string& locId);
525 void setLocation(
Entity* newLocation,
bool removeFromOldLocation =
true);
529 void setContentsFromAtlas(
const std::vector<std::string>& contents);
531 typedef std::unordered_map<std::string, Entity*> IdEntityMap;
532 void buildEntityDictFromContents(IdEntityMap& dict);
535 void removeChild(
Entity* e);
537 void addToLocation();
538 void removeFromLocation();
540 void updateTasks(
const Atlas::Message::Element& e);
544 void updateCalculatedVisibility(
bool wasVisible);
549 WFMath::Point<3> position;
550 WFMath::Vector<3> velocity;
551 WFMath::Quaternion orientation;
554 void updatePredictedState(
const WFMath::TimeStamp& t,
double simulationSpeed);
560 virtual Entity* getEntity(
const std::string&
id) = 0;
563 PropertyMap m_properties;
569 EntityArray m_contents;
577 WFMath::Vector<3> m_scale;
578 WFMath::AxisBox<3> m_bbox;
579 WFMath::AxisBox<3> m_bboxUnscaled;
580 WFMath::Point<3> m_position;
581 WFMath::Vector<3> m_velocity;
582 WFMath::Quaternion m_orientation;
583 WFMath::Vector<3> m_acc;
608 typedef sigc::signal<void, const Atlas::Message::Element&> PropertyChangedSignal;
610 typedef std::unordered_map<std::string, PropertyChangedSignal> ObserverMap;
611 ObserverMap m_observers;
618 WFMath::TimeStamp m_lastPosTime;
619 WFMath::TimeStamp m_lastOrientationTime;
624 std::map<std::string, std::unique_ptr<Task>> m_tasks;
627 inline size_t Entity::numContained()
const {
628 return m_contents.size();
631 inline Entity* Entity::getContained(
size_t index)
const {
632 return m_contents[index];
635 inline const std::string& Entity::getId()
const 640 inline const std::string& Entity::getName()
const 645 inline double Entity::getStamp()
const 656 inline Entity* Entity::getLocation()
const 662 inline const WFMath::Point<3>& Entity::getPosition()
const 667 inline const WFMath::Vector< 3 > & Entity::getVelocity()
const 672 inline const WFMath::Vector< 3 > & Entity::getAngularVelocity()
const 674 return m_angularVelocity;
678 inline const WFMath::Quaternion & Entity::getOrientation()
const 680 return m_orientation;
684 inline const WFMath::AxisBox< 3 > & Entity::getBBox()
const 689 inline bool Entity::hasBBox()
const 694 inline const std::map<std::string, std::unique_ptr<Task>>& Entity::getTasks()
const 700 inline C Entity::toLocationCoords(
const C& c)
const 702 return c.toParentCoords(getPredictedPos(), m_orientation);
706 inline C Entity::fromLocationCoords(
const C& c)
const 708 return c.toLocalCoords(getPredictedPos(), m_orientation);
711 inline WFMath::Vector<3> Entity::toLocationCoords(
const WFMath::Vector<3>& v)
const 713 return WFMath::Vector<3>(v).rotate(m_orientation);
716 inline WFMath::Vector<3> Entity::fromLocationCoords(
const WFMath::Vector<3>& v)
const 718 return WFMath::Vector<3>(v).rotate(m_orientation.inverse());
sigc::signal< void, const Atlas::Objects::Operation::Hit &, const TypeInfo & > Hit
sigc::signal< void > Moved
WFMath::Vector< 3 > m_angularVelocity
std::string m_name
a human readable name
The representation of an Atlas type (i.e a class or operation definition). This class supports effice...
sigc::signal< void > BeingDeleted
sigc::signal< void, const std::string &, Task * > TaskAdded
sigc::signal< void, Entity * > LocationChanged
Signal that the entity's container changed.
const std::string m_id
the Atlas object ID
sigc::signal< void, const Atlas::Objects::Root & > Say
Emitted with the entity speaks.
sigc::slot< void, const Atlas::Message::Element & > PropertyChangedSlot
A slot which can be used for receiving property update signals.
bool m_moving
flag recording if this entity is current considered in-motion
sigc::signal< void, const std::set< std::string > & > Changed
sigc::signal< void, bool > VisibilityChanged
bool m_recentlyCreated
flag set if this entity was the subject of a sight(create)
sigc::signal< void, bool > Moving
Entity is a concrete (instantiable) class representing one game entity.
sigc::signal< void, const std::string & > Emote
bool m_waitingForParentBind
waiting for parent bind
std::set< std::string > m_modifiedProperties
sigc::signal< void, const Atlas::Objects::Operation::RootOperation &, const TypeInfo & > Acted
double m_stamp
last modification time (in seconds)
sigc::signal< void, const Atlas::Objects::Root &, const TypeInfo & > Noise
sigc::signal< void, const std::string &, Task * > TaskRemoved