eris
1.4.0
A WorldForge client library.
|
An entity which is bound to an Eris::View. This subclass of Eris::Entity is intimately bound to a View. As Atlas messages are received from the server these will be routed into an instance of this class. More...
#include <ViewEntity.h>
Public Types | |
typedef std::map< std::string, Atlas::Message::Element > | PropertyMap |
typedef sigc::slot< void, const Atlas::Message::Element & > | PropertyChangedSlot |
A slot which can be used for receiving property update signals. More... | |
Public Member Functions | |
ViewEntity (std::string id, TypeInfo *ty, View &view) | |
Ctor. More... | |
virtual View * | getView () const |
Gets the view to which this entity belongs, if any. More... | |
size_t | numContained () const |
Gets the number of contained entities, i.e. entities that are direct children of this. The number returned is only for direct children, so the number of nested entities can be larger. More... | |
Entity * | getContained (size_t index) const |
Gets the child entity at the specified index. More... | |
Entity * | getTopEntity () |
Gets the top level entity for this entity, i.e. the parent location which has no parent. Will return null if any parent isn't resolved yet. More... | |
bool | isAncestorTo (Eris::Entity &entity) const |
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 InvalidOperation exception will be thrown. Therefore always first call hasProperty to make sure that the property exists. More... | |
bool | hasProperty (const std::string &p) const |
Checks whether an property exists. More... | |
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 be found null will be returned. This is thus a more efficient method than calling both "hasProperty(...)" and "valueOfProperty(...)" in sequence. More... | |
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. More... | |
const std::string & | getId () const |
Retrieve the unique entity ID. More... | |
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 set. More... | |
double | getStamp () const |
Access the current time-stamp of the entity. More... | |
TypeInfo * | getType () const |
Gets the type of this entity. More... | |
Entity * | getLocation () const |
The containing entity, or null if this is a top-level visible entity. More... | |
const WFMath::Point< 3 > & | getPosition () const |
Returns the Entity's position inside it's parent in the parent's local system coordinates. More... | |
PropertyMap | getProperties () const |
Gets all properties defined for this entity. The collection of entities returned will include both local properties as well as the defaults set in the TypeInfo (and all of its parents) of this entity. More... | |
const PropertyMap & | getInstanceProperties () const |
Gets all locally defined properties. This will only return those properties that are locally defined for this entity. In practice it will in most cases mean those properties that have been changed by the defaults as defined in the TypeInfo instance. More... | |
bool | isMoving () const |
Test if this entity has a non-zero velocity vector. More... | |
const WFMath::Point< 3 > & | getPredictedPos () const |
Retrieve the predicted position of this entity, based on it's velocity and acceleration. If the entity is not moving, this is the same as calling getPosition(). More... | |
const WFMath::Vector< 3 > & | getPredictedVelocity () const |
Retrieve the current predicted velocity of an entity. If the entity have no acceleration, this is the same as calling getVelocity(). More... | |
const WFMath::Quaternion & | getPredictedOrientation () const |
Retrieve the current predicted orientation of an entity. More... | |
const WFMath::Vector< 3 > & | getVelocity () const |
const WFMath::Vector< 3 > & | getAngularVelocity () const |
const WFMath::Quaternion & | getOrientation () const |
const WFMath::AxisBox< 3 > & | getBBox () const |
bool | hasBBox () const |
Returns true if the entity has a bounding box. Not all entities have bounding boxes, but those that are represented as physical objects in the world usually do. More... | |
const std::map< std::string, std::unique_ptr< Task > > & | getTasks () const |
Gets the tasks associated with this entity. More... | |
bool | hasChild (const std::string &eid) const |
bool | isVisible () const |
template<class C > | |
C | toLocationCoords (const C &c) const |
WFMath::Vector< 3 > | toLocationCoords (const WFMath::Vector< 3 > &v) const |
template<class C > | |
C | fromLocationCoords (const C &c) const |
WFMath::Vector< 3 > | fromLocationCoords (const WFMath::Vector< 3 > &v) const |
const std::vector< Entity * > & | getContent () const |
Static Public Member Functions | |
static boost::optional< std::string > | extractEntityId (const Atlas::Message::Element &element) |
Extracts an entity id from the supplied element. More... | |
Public Attributes | |
sigc::signal< void, Entity * > | ChildAdded |
sigc::signal< void, Entity * > | ChildRemoved |
sigc::signal< void, Entity * > | LocationChanged |
Signal that the entity's container changed. More... | |
sigc::signal< void, const std::set< std::string > & > | Changed |
sigc::signal< void > | Moved |
sigc::signal< void, bool > | Moving |
sigc::signal< void, const Atlas::Objects::Root &> | Say |
Emitted with the entity speaks. More... | |
sigc::signal< void, const std::string & > | Emote |
sigc::signal< void, const Atlas::Objects::Operation::RootOperation &, const TypeInfo & > | Acted |
sigc::signal< void, const Atlas::Objects::Operation::Hit &, const TypeInfo & > | Hit |
sigc::signal< void, const Atlas::Objects::Root &, const TypeInfo & > | Noise |
sigc::signal< void, bool > | VisibilityChanged |
sigc::signal< void > | BeingDeleted |
sigc::signal< void, const std::string &, Task * > | TaskAdded |
sigc::signal< void, const std::string &, Task * > | TaskRemoved |
Protected Types | |
typedef std::unordered_map< std::string, Entity * > | IdEntityMap |
typedef sigc::signal< void, const Atlas::Message::Element & > | PropertyChangedSignal |
typedef std::unordered_map< std::string, PropertyChangedSignal > | ObserverMap |
Protected Member Functions | |
void | onTaskAdded (const std::string &id, Task *task) override |
Over-rideable hook for when tasks are added. More... | |
Entity * | getEntity (const std::string &id) override |
Gets an entity with the supplied id from the system. More... | |
void | task_ProgressRateChanged (Task *task) |
Listen to task progress rates updates and send to the view. More... | |
virtual void | init (const Atlas::Objects::Entity::RootEntity &ge, bool fromCreateOp) |
void | shutdown () |
virtual void | onTalk (const Atlas::Objects::Operation::RootOperation &talk) |
virtual void | onPropertyChanged (const std::string &propertyName, const Atlas::Message::Element &v) |
virtual void | onLocationChanged (Entity *oldLoc) |
virtual void | onMoved (const WFMath::TimeStamp &timeStamp) |
virtual void | onVisibilityChanged (bool vis) |
virtual void | onAction (const Atlas::Objects::Operation::RootOperation &act, const TypeInfo &typeInfo) |
virtual void | onHit (const Atlas::Objects::Operation::Hit &hit, const TypeInfo &typeInfo) |
virtual void | onSoundAction (const Atlas::Objects::Operation::RootOperation &op, const TypeInfo &typeInfo) |
virtual void | onImaginary (const Atlas::Objects::Root &act) |
virtual void | setMoving (bool moving) |
virtual void | onChildAdded (Entity *child) |
virtual void | onChildRemoved (Entity *child) |
void | firstSight (const Atlas::Objects::Entity::RootEntity &gent) |
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 exclude all properties related to motion. More... | |
void | setVisible (bool vis) |
void | setProperty (const std::string &p, const Atlas::Message::Element &v) |
bool | nativePropertyChanged (const std::string &p, const Atlas::Message::Element &v) |
void | typeInfo_PropertyChanges (const std::string &propertyName, const Atlas::Message::Element &element) |
Connected to the TypeInfo::PropertyeChanges event. This will in turn call the propertyChangedFromTypeInfo, which is overridable in a subclass if so desired. More... | |
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 have an instance value local to this entity the event will be processed just like a call to setProperty but without the property being saved in the map of instance properties. More... | |
void | fillPropertiesFromType (Entity::PropertyMap &properties, const TypeInfo &typeInfo) const |
Utility method for recursively filling a map of properties from a TypeInfo instance. The method will recursively call itself to make sure that the topmost TypeInfo is used first. This makes sure that properties are overwritten by newer values, if duplicates exists. More... | |
void | beginUpdate () |
void | addToUpdate (const std::string &propertyName) |
void | endUpdate () |
void | setLocationFromAtlas (const std::string &locId) |
void | setLocation (Entity *newLocation, bool removeFromOldLocation=true) |
void | setContentsFromAtlas (const std::vector< std::string > &contents) |
void | buildEntityDictFromContents (IdEntityMap &dict) |
void | addChild (Entity *e) |
void | removeChild (Entity *e) |
void | addToLocation () |
void | removeFromLocation () |
void | updateTasks (const Atlas::Message::Element &e) |
void | updateCalculatedVisibility (bool wasVisible) |
void | updatePredictedState (const WFMath::TimeStamp &t, double simulationSpeed) |
Protected Attributes | |
View & | m_view |
The View which owns this Entity. More... | |
PropertyMap | m_properties |
TypeInfo * | m_type |
Entity * | m_location |
EntityArray | m_contents |
const std::string | m_id |
the Atlas object ID More... | |
std::string | m_name |
a human readable name More... | |
double | m_stamp |
last modification time (in seconds) More... | |
bool | m_visible |
bool | m_waitingForParentBind |
waiting for parent bind More... | |
WFMath::Vector< 3 > | m_scale |
WFMath::AxisBox< 3 > | m_bbox |
WFMath::AxisBox< 3 > | m_bboxUnscaled |
WFMath::Point< 3 > | m_position |
WFMath::Vector< 3 > | m_velocity |
WFMath::Quaternion | m_orientation |
WFMath::Vector< 3 > | m_acc |
WFMath::Vector< 3 > | m_angularVelocity |
double | m_angularMag |
DynamicState | m_predicted |
int | m_updateLevel |
std::set< std::string > | m_modifiedProperties |
ObserverMap | m_observers |
bool | m_hasBBox |
WFMath::TimeStamp | m_lastPosTime |
WFMath::TimeStamp | m_lastOrientationTime |
bool | m_moving |
flag recording if this entity is current considered in-motion More... | |
bool | m_recentlyCreated |
flag set if this entity was the subject of a sight(create) More... | |
std::map< std::string, std::unique_ptr< Task > > | m_tasks |
Friends | |
class | EntityRouter |
An entity which is bound to an Eris::View. This subclass of Eris::Entity is intimately bound to a View. As Atlas messages are received from the server these will be routed into an instance of this class.
In your client this is the class you would want to work with for any entities which represents entities that are on the server. If you however are working with entities that aren't represented on the server (the typical example would be if you're allowing client side authoring where you want to create entities locally) you would instead want to implement a new class which inherits Eris::Entity.
Definition at line 21 of file ViewEntity.h.
|
inherited |
Ctor.
id | The id of the entity. |
ty | Type info for the entity. |
view | The view to which the entity belongs. |
Definition at line 14 of file ViewEntity.cpp.
|
staticinherited |
Extracts an entity id from the supplied element.
There are two ways to express entity ids; either as a string, or as a map with one entry named "$eid" (where the string is the value). The function parses the element for these two cases, if found fills the "id" parameter and then returns true.
element | The element which we want to extract from. |
id | The string where the id, if found, will be placed. |
Definition at line 816 of file Entity.cpp.
|
protectedinherited |
Utility method for recursively filling a map of properties from a TypeInfo instance. The method will recursively call itself to make sure that the topmost TypeInfo is used first. This makes sure that properties are overwritten by newer values, if duplicates exists.
properties | The map of properties to fill. |
typeInfo | The type info from which we will copy values, as well as its parents. |
Make sure to fill from the closest properties first, as insert won't replace an existing value
Definition at line 185 of file Entity.cpp.
References Eris::TypeInfo::getParent(), and Eris::TypeInfo::getProperties().
|
protectedinherited |
Fully initialise all entity state based on a RootEntity, including location and contents. This is only called once when the entity is first seen.
Definition at line 254 of file Entity.cpp.
Referenced by Eris::View::taskRateChanged().
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
overrideprotectedvirtual |
Gets an entity with the supplied id from the system.
id | The id of the entity to get. |
Implements Eris::Entity.
Definition at line 21 of file ViewEntity.cpp.
References Eris::View::getEntity(), and m_view.
|
inlineinherited |
Retrieve the unique entity ID.
Definition at line 635 of file Entity.h.
Referenced by Eris::Avatar::moveToPoint(), Eris::Avatar::place(), Eris::Entity::setContentsFromAtlas(), Eris::Avatar::touch(), and Eris::Avatar::useStop().
|
inherited |
Gets all locally defined properties. This will only return those properties that are locally defined for this entity. In practice it will in most cases mean those properties that have been changed by the defaults as defined in the TypeInfo instance.
Definition at line 180 of file Entity.cpp.
|
inlineinherited |
The containing entity, or null if this is a top-level visible entity.
the containing entity, or null if this is a top-level visible entity.
Definition at line 656 of file Entity.h.
Referenced by Eris::Entity::isAncestorTo(), Eris::Avatar::moveToPoint(), Eris::View::sendLookAt(), Eris::Entity::setContentsFromAtlas(), Eris::View::taskRateChanged(), and Eris::Avatar::useStop().
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inherited |
Retrieve the current predicted orientation of an entity.
Definition at line 219 of file Entity.cpp.
|
inherited |
Retrieve the predicted position of this entity, based on it's velocity and acceleration. If the entity is not moving, this is the same as calling getPosition().
Definition at line 209 of file Entity.cpp.
|
inherited |
Retrieve the current predicted velocity of an entity. If the entity have no acceleration, this is the same as calling getVelocity().
Definition at line 214 of file Entity.cpp.
|
inherited |
Gets all properties defined for this entity. The collection of entities returned will include both local properties as well as the defaults set in the TypeInfo (and all of its parents) of this entity.
Merge both the local properties and the type default properties.
Definition at line 169 of file Entity.cpp.
|
inlineinherited |
Access the current time-stamp of the entity.
Definition at line 645 of file Entity.h.
Referenced by Eris::View::taskRateChanged().
|
inlineinherited |
|
inherited |
Gets the top level entity for this entity, i.e. the parent location which has no parent. Will return null if any parent isn't resolved yet.
Definition at line 92 of file Entity.cpp.
References Eris::Entity::getTopEntity().
Referenced by Eris::Entity::getTopEntity().
|
inlineinherited |
Gets the type of this entity.
Definition at line 650 of file Entity.h.
Referenced by Eris::Avatar::useStop().
|
inlineinherited |
|
inlinevirtual |
Gets the view to which this entity belongs, if any.
Definition at line 62 of file ViewEntity.h.
References m_view.
|
inlineinherited |
|
inherited |
Checks whether an property exists.
p | The name of the property. |
first check with the instance properties
it wasn't locally defined, now check with typeinfo
Definition at line 135 of file Entity.cpp.
|
protectedvirtualinherited |
over-rideable initialisation helper. When subclassing, if you over-ride this method, take care to call the base implementation, or unfortunate things will happen.
Definition at line 80 of file Entity.cpp.
|
inherited |
Returns true if this entity is an ancestor to the supplied entity. I.e. that it's either a direct or indirect parent. Note that this might be incorrect if parents aren't bound yet.
entity |
Definition at line 103 of file Entity.cpp.
References Eris::Entity::getLocation().
|
inherited |
Test if this entity has a non-zero velocity vector.
Definition at line 224 of file Entity.cpp.
Referenced by Eris::View::update().
|
inherited |
determine if this entity is visible.
Definition at line 774 of file Entity.cpp.
Referenced by Eris::View::taskRateChanged().
|
protectedinherited |
Map Atlas properties to natively stored properties. Should be changed to use an integer hash in the future, since this called frequently.
Definition at line 400 of file Entity.cpp.
|
inlineinherited |
|
inherited |
Setup an observer so that the specified slot is fired when the named property's value changes.
propertyName | The name of the property to observe. |
aslot | The slot which will be fired when the property changes. |
evaluateNow | Whether the |
Definition at line 196 of file Entity.cpp.
Referenced by Eris::View::sendLookAt(), and Eris::Avatar::useStop().
|
protectedvirtualinherited |
Over-rideable hook when this entity is seen to perform an action. Default implementation emits the Action signal.
Definition at line 332 of file Entity.cpp.
|
protectedvirtualinherited |
Over-rideable hook when child entities are added. The default implementation emits the ChildAdded signal.
Definition at line 364 of file Entity.cpp.
|
protectedvirtualinherited |
Over-rideable hook when child entities are removed. The default implementation emits the Childremoved signal.
Definition at line 369 of file Entity.cpp.
|
protectedvirtualinherited |
Over-rideable hook when this entity is hit by something. Default implementation emits the Hit signal.
Definition at line 337 of file Entity.cpp.
|
protectedvirtualinherited |
Over-rideable hook when this entity is seen to emit an imginary op. Default implementation emits the Emote signal.
Definition at line 347 of file Entity.cpp.
|
protectedvirtualinherited |
over-rideable hook method when then Entity position, orientation or velocity change. The default implementation emits the Moved signal.
Definition at line 323 of file Entity.cpp.
|
protectedvirtualinherited |
Over-rideable hook when this entity is heard performing an action. Default implementation emits the Noise signal.
Definition at line 342 of file Entity.cpp.
|
protectedvirtualinherited |
process TALK data - default implementation emits the Say signal.
talk | The TALK operation |
Definition at line 303 of file Entity.cpp.
|
overrideprotectedvirtual |
Over-rideable hook for when tasks are added.
id | Id of the task. |
task | The new task. |
Reimplemented from Eris::Entity.
Definition at line 32 of file ViewEntity.cpp.
References m_view, Eris::Entity::onTaskAdded(), task_ProgressRateChanged(), and Eris::View::taskRateChanged().
|
protectedvirtualinherited |
over-rideable hook when the actual (computed) visiblity of this entity changed. The default implementation emits the VisiblityChanged signal.
Definition at line 811 of file Entity.cpp.
|
protectedvirtualinherited |
Called when an property has been changed in the TypeInfo for this entity. If the property doesn't have an instance value local to this entity the event will be processed just like a call to setProperty but without the property being saved in the map of instance properties.
propertyName | The name of the property which is to be changed. |
element | The new element data. |
Only fire the events if there's no property already defined for this entity
Definition at line 488 of file Entity.cpp.
|
inherited |
Gets the value of a named property, or null if none exists. If no property by the specified name can be found null will be returned. This is thus a more efficient method than calling both "hasProperty(...)" and "valueOfProperty(...)" in sequence.
name | The property name. |
first check with the instance properties
it wasn't locally defined, now check with typeinfo
Definition at line 149 of file Entity.cpp.
|
protectedinherited |
wrapper for setLocation with additional code the retrieve the location if it's not available right now
Definition at line 690 of file Entity.cpp.
References Eris::Entity::getId(), Eris::Entity::getLocation(), Eris::Entity::m_waitingForParentBind, Eris::Entity::setLocation(), and Eris::Entity::setVisible().
|
protectedinherited |
Initialise all simple state from a Root. This excludes location and contents, and may optionally exclude all properties related to motion.
obj | The atlas object containing the data. |
includeTypeInfoProperties | If true, the default properties of the type info will be used too. This is normally only desired when the entity is initially set up. |
Definition at line 267 of file Entity.cpp.
|
protectedinherited |
setLocation is the core of the entity hierarchy maintenance logic. We make setting location the 'fixup' action; addChild / removeChild are correspondingly simple.
Definition at line 644 of file Entity.cpp.
References Eris::Entity::m_waitingForParentBind.
Referenced by Eris::Entity::setContentsFromAtlas(), Eris::View::taskRateChanged(), and Eris::Avatar::useStop().
|
protectedinherited |
update the entity's location based on Atlas data. This is used by the MOVE handler to update the location information.
Definition at line 622 of file Entity.cpp.
|
protectedvirtualinherited |
over-rideable hook for when the entity changes from stationary to moving or vice-versa. This hook exists so a client can treat moving objects differently (eg, placing them in a different part of the scene graph). If you over-ride this, you must call the base version, or motion prediction will stop working for the entity.
Definition at line 355 of file Entity.cpp.
|
protectedinherited |
the View calls this to change local entity visibility. No one else should be calling it!
Definition at line 762 of file Entity.cpp.
Referenced by Eris::Entity::setContentsFromAtlas(), and Eris::View::taskRateChanged().
|
protectedinherited |
Shuts down the entity. This is called by the destructor, but if you extend this class you should call it in your subclass' destructor to make sure that vtables haven't been cleared yet.
Definition at line 65 of file Entity.cpp.
|
protected |
Listen to task progress rates updates and send to the view.
task | The task which is changed. |
Definition at line 39 of file ViewEntity.cpp.
References m_view, and Eris::View::taskRateChanged().
Referenced by onTaskAdded().
|
protectedinherited |
Connected to the TypeInfo::PropertyeChanges event. This will in turn call the propertyChangedFromTypeInfo, which is overridable in a subclass if so desired.
propertyName | The name of the property which is to be changed. |
element | The new element data. |
Definition at line 483 of file Entity.cpp.
|
protectedinherited |
recursively update the real visiblity of this entity, and fire appropriate signals.
Definition at line 785 of file Entity.cpp.
|
inherited |
Gets the value of a named property. If no property by the specified name can be found an InvalidOperation exception will be thrown. Therefore always first call hasProperty to make sure that the property exists.
name | The property name. |
InvalidOperation | If no property by the specified name can be found. |
first check with the instance properties
it wasn't locally defined, now check with typeinfo
Definition at line 115 of file Entity.cpp.
|
inherited |
|
inherited |
Emitted prior to deletion. Note that entity instances may be deleted for different reasons - passing out of the view, being deleted on the server, or during disconnection. This signal is emitted regardless.
Definition at line 365 of file Entity.h.
Referenced by Eris::Avatar::useStop().
|
inherited |
|
inherited |
|
inherited |
|
inherited |
Signal that the entity's container changed.
emitted when our location changes. First argument is the old location. The new location can be found via getLocation. Note either the old or new location might be nullptr.
Definition at line 300 of file Entity.h.
Referenced by Eris::Avatar::useStop().
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
flag set if this entity was the subject of a sight(create)
Definition at line 622 of file Entity.h.
Referenced by Eris::View::taskRateChanged().
|
protectedinherited |
|
protectedinherited |
|
protected |
The View which owns this Entity.
Definition at line 47 of file ViewEntity.h.
Referenced by getEntity(), getView(), onTaskAdded(), and task_ProgressRateChanged().
|
protectedinherited |
waiting for parent bind
Definition at line 575 of file Entity.h.
Referenced by Eris::Entity::setContentsFromAtlas(), and Eris::Entity::setLocation().
|
inherited |
|
inherited |
|
inherited |
|
inherited |
Emitted with the entity speaks.
The argument contains attributes that make up the content of the Say operation.
|
inherited |
|
inherited |
|
inherited |