eris
1.4.0
A WorldForge client library.
|
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;
102 const Atlas::Message::Element&
valueOfProperty(
const std::string& name)
const;
118 const Atlas::Message::Element*
ptrOfProperty(
const std::string& name)
const;
140 const std::string&
getId()
const;
147 const std::string&
getName()
const;
235 const WFMath::AxisBox<3> &
getBBox()
const;
248 const std::map<std::string, std::unique_ptr<Task>>&
getTasks()
const;
250 bool hasChild(
const std::string& eid)
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);
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);
466 void firstSight(
const Atlas::Objects::Entity::RootEntity& gent);
474 void setFromRoot(
const Atlas::Objects::Root& obj,
bool includeTypeInfoProperties =
false);
480 void setProperty(
const std::string &p,
const Atlas::Message::Element &v);
515 void addToUpdate(
const std::string& propertyName);
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);
549 WFMath::Point<3> position;
550 WFMath::Vector<3> velocity;
551 WFMath::Quaternion orientation;
554 void updatePredictedState(
const WFMath::TimeStamp& t,
double simulationSpeed);
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;
628 return m_contents.size();
632 return m_contents[index];
680 return m_orientation;
700 inline C Entity::toLocationCoords(
const C& c)
const
706 inline C Entity::fromLocationCoords(
const C& c)
const
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());
double getStamp() const
Access the current time-stamp of the entity.
sigc::signal< void, const Atlas::Objects::Root &, const TypeInfo & > Noise
sigc::signal< void, const Atlas::Objects::Root & > Say
Emitted with the entity speaks.
virtual void onHit(const Atlas::Objects::Operation::Hit &hit, const TypeInfo &typeInfo)
void fillPropertiesFromType(Entity::PropertyMap &properties, const TypeInfo &typeInfo) const
Utility method for recursively filling a map of properties from a TypeInfo instance....
const WFMath::Point< 3 > & getPredictedPos() const
Retrieve the predicted position of this entity, based on it's velocity and acceleration....
virtual void onChildAdded(Entity *child)
sigc::signal< void, const Atlas::Objects::Operation::RootOperation &, const TypeInfo & > Acted
void setLocationFromAtlas(const std::string &locId)
Entity * getLocation() const
The containing entity, or null if this is a top-level visible entity.
void setContentsFromAtlas(const std::vector< std::string > &contents)
const WFMath::Vector< 3 > & getPredictedVelocity() const
Retrieve the current predicted velocity of an entity. If the entity have no acceleration,...
Entity is a concrete (instantiable) class representing one game entity.
const std::string m_id
the Atlas object ID
const WFMath::Quaternion & getOrientation() const
const WFMath::AxisBox< 3 > & getBBox() const
static boost::optional< std::string > extractEntityId(const Atlas::Message::Element &element)
Extracts an entity id from the supplied element.
sigc::signal< void, const std::string & > Emote
bool hasBBox() const
Returns true if the entity has a bounding box. Not all entities have bounding boxes,...
const Atlas::Message::Element * ptrOfProperty(const std::string &name) const
Gets the value of a named property, or null if none exists. If no property by the specified name can ...
const WFMath::Vector< 3 > & getAngularVelocity() const
Entity * getContained(size_t index) const
Gets the child entity at the specified index.
const WFMath::Point< 3 > & getPosition() const
Returns the Entity's position inside it's parent in the parent's local system coordinates.
double m_stamp
last modification time (in seconds)
sigc::signal< void, const std::string &, Task * > TaskAdded
sigc::connection observe(const std::string &propertyName, const PropertyChangedSlot &aslot, bool evaluateNow)
Setup an observer so that the specified slot is fired when the named property's value changes.
void updateCalculatedVisibility(bool wasVisible)
bool isMoving() const
Test if this entity has a non-zero velocity vector.
bool isAncestorTo(Eris::Entity &entity) const
virtual void onChildRemoved(Entity *child)
Entity * getTopEntity()
Gets the top level entity for this entity, i.e. the parent location which has no parent....
virtual void onTaskAdded(const std::string &id, Task *task)
Over-rideable hook for when tasks are added.
std::set< std::string > m_modifiedProperties
void setFromRoot(const Atlas::Objects::Root &obj, bool includeTypeInfoProperties=false)
Initialise all simple state from a Root. This excludes location and contents, and may optionally excl...
PropertyMap getProperties() const
Gets all properties defined for this entity. The collection of entities returned will include both lo...
TypeInfo * getType() const
Gets the type of this entity.
virtual void propertyChangedFromTypeInfo(const std::string &propertyName, const Atlas::Message::Element &element)
Called when an property has been changed in the TypeInfo for this entity. If the property doesn't hav...
virtual void onVisibilityChanged(bool vis)
sigc::signal< void > BeingDeleted
virtual void onSoundAction(const Atlas::Objects::Operation::RootOperation &op, const TypeInfo &typeInfo)
const std::string & getId() const
Retrieve the unique entity ID.
bool hasProperty(const std::string &p) const
Checks whether an property exists.
bool nativePropertyChanged(const std::string &p, const Atlas::Message::Element &v)
virtual void init(const Atlas::Objects::Entity::RootEntity &ge, bool fromCreateOp)
const WFMath::Quaternion & getPredictedOrientation() const
Retrieve the current predicted orientation of an entity.
sigc::signal< void > Moved
const std::map< std::string, std::unique_ptr< Task > > & getTasks() const
Gets the tasks associated with this entity.
virtual void onMoved(const WFMath::TimeStamp &timeStamp)
The representation of an Atlas type (i.e a class or operation definition). This class supports effice...
virtual void setMoving(bool moving)
const PropertyMap & getInstanceProperties() const
Gets all locally defined properties. This will only return those properties that are locally defined ...
void firstSight(const Atlas::Objects::Entity::RootEntity &gent)
void setVisible(bool vis)
std::string m_name
a human readable name
const WFMath::Vector< 3 > & getVelocity() const
bool m_recentlyCreated
flag set if this entity was the subject of a sight(create)
sigc::signal< void, Entity * > LocationChanged
Signal that the entity's container changed.
WFMath::Vector< 3 > m_angularVelocity
bool m_moving
flag recording if this entity is current considered in-motion
const Atlas::Message::Element & valueOfProperty(const std::string &name) const
Gets the value of a named property. If no property by the specified name can be found an InvalidOpera...
sigc::slot< void, const Atlas::Message::Element & > PropertyChangedSlot
A slot which can be used for receiving property update signals.
const std::string & getName() const
Gets the name of the entity. In contrast to getId() this is not unique, and doesn't even have to be s...
virtual void onAction(const Atlas::Objects::Operation::RootOperation &act, const TypeInfo &typeInfo)
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)
bool m_waitingForParentBind
waiting for parent bind
sigc::signal< void, const std::string &, Task * > TaskRemoved
void setLocation(Entity *newLocation, bool removeFromOldLocation=true)
sigc::signal< void, const Atlas::Objects::Operation::Hit &, const TypeInfo & > Hit
sigc::signal< void, const std::set< std::string > & > Changed
virtual void onImaginary(const Atlas::Objects::Root &act)
size_t numContained() const
Gets the number of contained entities, i.e. entities that are direct children of this....
void typeInfo_PropertyChanges(const std::string &propertyName, const Atlas::Message::Element &element)
Connected to the TypeInfo::PropertyeChanges event. This will in turn call the propertyChangedFromType...
sigc::signal< void, bool > VisibilityChanged
sigc::signal< void, bool > Moving