Eris  1.3.23
View.h
1 #ifndef ERIS_VIEW_H
2 #define ERIS_VIEW_H
3 
4 // WF
5 #include <Eris/Factory.h>
6 #include <Atlas/Objects/ObjectsFwd.h>
7 #include <wfmath/timestamp.h>
8 
9 // sigc++
10 #include <sigc++/trackable.h>
11 #include <sigc++/signal.h>
12 #include <sigc++/slot.h>
13 #include <sigc++/connection.h>
14 
15 // std
16 #include <deque>
17 #include <map>
18 #include <set>
19 
20 namespace Eris
21 {
22 
23 class Avatar;
24 class ViewEntity;
25 class Entity;
26 class Connection;
27 class Task;
28 
33 class View : public sigc::trackable
34 {
35 public:
36  View(Avatar* av);
37  ~View();
38 
43  Entity* getEntity(const std::string& eid) const;
44 
45  Avatar* getAvatar() const
46  {
47  return m_owner;
48  }
49 
53  {
54  return m_topLevel;
55  }
56 
62  void update();
63 
67  void registerFactory(Factory*);
68 
69  typedef sigc::slot<void, Entity*> EntitySightSlot;
70 
75  sigc::connection notifyWhenEntitySeen(const std::string& eid, const EntitySightSlot& slot);
76 
79  sigc::signal<void, Entity*> EntitySeen;
80 
82  sigc::signal<void, Entity*> EntityCreated;
83 
85  sigc::signal<void, Entity*> EntityDeleted;
86 
88  sigc::signal<void> AvatarEntityDeleted;
89 
90  sigc::signal<void, Entity*> Appearance;
91  sigc::signal<void, Entity*> Disappearance;
92 
94  sigc::signal<void> TopLevelEntityChanged;
95 
102  sigc::signal<void, Entity*> InitialSightEntity;
103 
104  void dumpLookQueue();
105 
110  unsigned int lookQueueSize() const
111  {
112  return m_lookQueue.size();
113  }
114 protected:
115  // the router passes various relevant things to us directly
116  friend class IGRouter;
117  friend class ViewEntity;
118  friend class Avatar;
119  friend class Task;
120 
121  void appear(const std::string& eid, float stamp);
122  void disappear(const std::string& eid);
123  void sight(const Atlas::Objects::Entity::RootEntity& ge);
124  void create(const Atlas::Objects::Entity::RootEntity& ge);
125  void deleteEntity(const std::string& eid);
126  void unseen(const std::string& eid);
127 
128  void setEntityVisible(Entity* ent, bool vis);
129 
131  bool isPending(const std::string& eid) const;
132 
133  void addToPrediction(Entity* ent);
134  void removeFromPrediction(Entity* ent);
135 
139  void entityDeleted(Entity* ent);
140 
147  void taskRateChanged(Task*);
148 private:
149  Entity* initialSight(const Atlas::Objects::Entity::RootEntity& ge);
150 
151  Connection* getConnection() const;
152  void getEntityFromServer(const std::string& eid);
153 
155  void setTopLevelEntity(Entity* newTopLevel);
156 
157  Entity* createEntity(const Atlas::Objects::Entity::RootEntity&);
158 
164  void sendLookAt(const std::string& eid);
165 
170  void issueQueuedLook();
171 
172  void eraseFromLookQueue(const std::string& eid);
173 
174  typedef std::map<std::string, Entity*> IdEntityMap;
175 
176  Avatar* m_owner;
177  IdEntityMap m_contents;
178  Entity* m_topLevel;
179  WFMath::TimeStamp m_lastUpdateTime;
180 
184  typedef enum
185  {
186  SACTION_INVALID,
187  SACTION_APPEAR,
188  SACTION_HIDE,
189  SACTION_DISCARD,
190  SACTION_QUEUED
191  } SightAction;
192 
193  typedef std::map<std::string, SightAction> PendingSightMap;
194  PendingSightMap m_pending;
195 
203  std::deque<std::string> m_lookQueue;
204 
205  unsigned int m_maxPendingCount;
206 
207  typedef sigc::signal<void, Entity*> EntitySightSignal;
208 
209  typedef std::map<std::string, EntitySightSignal> NotifySightMap;
210  NotifySightMap m_notifySights;
211 
212  typedef std::set<Entity*> EntitySet;
213 
216  EntitySet m_moving;
217 
218  class FactoryOrdering
219  {
220  public:
221  bool operator()(Factory* a, Factory* b) const
222  { // higher priority factories are placed nearer the start
223  return a->priority() > b->priority();
224  }
225  };
226 
227  typedef std::multiset<Factory*, FactoryOrdering> FactoryStore;
228  FactoryStore m_factories;
229 
230  std::set<Task*> m_progressingTasks;
231 };
232 
233 } // of namespace Eris
234 
235 #endif // of ERIS_VIEW_H
Eris::Entity::isVisible
bool isVisible() const
determine if this entity is visible.
Definition: Entity.cpp:785
Eris::ViewEntity
An entity which is bound to an Eris::View.
Definition: ViewEntity.h:21
Eris::Entity
Entity is a concrete (instantiable) class representing one game entity.
Definition: Entity.h:58
Eris::View::getTopLevel
Entity * getTopLevel() const
return the current top-level entity.
Definition: View.h:52
Eris::Factory
Factory is used to allow custom entity creation by client libraries.
Definition: Factory.h:15
Eris::View::update
void update()
once-per-frame update of the View - clients should call this method once per game loop (or similar),...
Definition: View.cpp:90
Eris::Entity::isMoving
bool isMoving() const
Test if this entity has a non-zero velocity vector.
Definition: Entity.cpp:206
Eris::IGRouter
Definition: IGRouter.h:14
Eris::View::lookQueueSize
unsigned int lookQueueSize() const
Retrieve the current look queue size, for debugging / statistics purposes.
Definition: View.h:110
Eris::View::EntitySeen
sigc::signal< void, Entity * > EntitySeen
emitted whenever the View creates a new Entity instance.
Definition: View.h:79
Eris::Avatar
The player's avatar representation.
Definition: Avatar.h:32
Eris::View::AvatarEntityDeleted
sigc::signal< void > AvatarEntityDeleted
emitted AFTER the avatar entity was deleted due to a SIGHT(DELETE) op is received
Definition: View.h:88
Eris::error
Definition: LogStream.h:56
Eris::Entity::getStamp
float getStamp() const
Access the current time-stamp of the entity.
Definition: Entity.h:614
Eris::View::taskRateChanged
void taskRateChanged(Task *)
Method to register and unregister tasks with with view, so they can have their progress updated autom...
Definition: View.cpp:126
Eris::View::InitialSightEntity
sigc::signal< void, Entity * > InitialSightEntity
Emitted after a new Entity has been created and initialized.
Definition: View.h:102
Eris::Entity::getId
const std::string & getId() const
Retrieve the unique entity ID.
Definition: Entity.h:604
Eris::View::entityDeleted
void entityDeleted(Entity *ent)
this is a hook that Entity's destructor calls to remove itself from the View's content map.
Definition: View.cpp:444
Eris::View::isPending
bool isPending(const std::string &eid) const
test if the specified entity ID is pending initial sight on the View
Definition: View.cpp:356
Eris::Entity::setVisible
void setVisible(bool vis)
the View calls this to change local entity visibility.
Definition: Entity.cpp:773
Eris::View::EntityCreated
sigc::signal< void, Entity * > EntityCreated
emitted when a SIGHT(CREATE) op is received for an entity
Definition: View.h:82
Eris::View::TopLevelEntityChanged
sigc::signal< void > TopLevelEntityChanged
emitted when the TLVE changes
Definition: View.h:94
Eris::Entity::m_recentlyCreated
bool m_recentlyCreated
flag set if this entity was the subject of a sight(create)
Definition: Entity.h:589
Eris::View::getEntity
Entity * getEntity(const std::string &eid) const
Retrieve an entity in the view by id.
Definition: View.cpp:53
Eris::Connection
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:40
Eris::View::EntityDeleted
sigc::signal< void, Entity * > EntityDeleted
emitted when a SIGHT(DELETE) op is received for an entity
Definition: View.h:85
Eris::Task
Definition: Task.h:26
Eris::View
View encapsulates the set of entities currently visible to an Avatar, as well as those that have rece...
Definition: View.h:34
Eris::View::registerFactory
void registerFactory(Factory *)
Register an Entity Factory with this view.
Definition: View.cpp:71
Eris::View::notifyWhenEntitySeen
sigc::connection notifyWhenEntitySeen(const std::string &eid, const EntitySightSlot &slot)
Conenct up a slot to be fired when an Entity with the specified ID is seen.
Definition: View.cpp:76