Eris  1.4.0
View.h
1 #ifndef ERIS_VIEW_H
2 #define ERIS_VIEW_H
3 
4 // WF
5 #include "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 <string>
17 #include <deque>
18 #include <map>
19 #include <set>
20 #include <unordered_map>
21 
22 namespace Eris
23 {
24 
25 class Avatar;
26 class ViewEntity;
27 class Entity;
28 class Connection;
29 class Task;
30 class TypeService;
31 class EventService;
32 
37 class View : public sigc::trackable
38 {
39 public:
40  View(Avatar* av);
41  ~View();
42 
47  Entity* getEntity(const std::string& eid) const;
48 
49  Avatar* getAvatar() const
50  {
51  return m_owner;
52  }
53 
57  {
58  return m_topLevel;
59  }
60 
66 
71  TypeService& getTypeService() const;
72 
78 
84 
90  void update();
91 
95  void registerFactory(Factory*);
96 
97  typedef sigc::slot<void, Entity*> EntitySightSlot;
98 
103  sigc::connection notifyWhenEntitySeen(const std::string& eid, const EntitySightSlot& slot);
104 
107  sigc::signal<void, Entity*> EntitySeen;
108 
110  sigc::signal<void, Entity*> EntityCreated;
111 
113  sigc::signal<void, Entity*> EntityDeleted;
114 
116  sigc::signal<void> AvatarEntityDeleted;
117 
118  sigc::signal<void, Entity*> Appearance;
119  sigc::signal<void, Entity*> Disappearance;
120 
122  sigc::signal<void> TopLevelEntityChanged;
123 
130  sigc::signal<void, Entity*> InitialSightEntity;
131 
132  void dumpLookQueue();
133 
138  unsigned int lookQueueSize() const
139  {
140  return m_lookQueue.size();
141  }
142 
148  void sendLookAt(const std::string& eid);
149 
150 protected:
151  // the router passes various relevant things to us directly
152  friend class IGRouter;
153  friend class ViewEntity;
154  friend class Avatar;
155  friend class Task;
156 
157  void appear(const std::string& eid, float stamp);
158  void disappear(const std::string& eid);
159  void sight(const Atlas::Objects::Entity::RootEntity& ge);
160  void create(const Atlas::Objects::Entity::RootEntity& ge);
161  void deleteEntity(const std::string& eid);
162  void unseen(const std::string& eid);
163 
164  void setEntityVisible(Entity* ent, bool vis);
165 
167  bool isPending(const std::string& eid) const;
168 
169  void addToPrediction(Entity* ent);
170  void removeFromPrediction(Entity* ent);
171 
175  void entityDeleted(Entity* ent);
176 
183  void taskRateChanged(Task*);
184 private:
185  Entity* initialSight(const Atlas::Objects::Entity::RootEntity& ge);
186 
187  Connection* getConnection() const;
188  void getEntityFromServer(const std::string& eid);
189 
191  void setTopLevelEntity(Entity* newTopLevel);
192 
193  Entity* createEntity(const Atlas::Objects::Entity::RootEntity&);
194 
199  void issueQueuedLook();
200 
201  void eraseFromLookQueue(const std::string& eid);
202 
203  typedef std::unordered_map<std::string, Entity*> IdEntityMap;
204 
205  Avatar* m_owner;
206  IdEntityMap m_contents;
207  Entity* m_topLevel;
208  WFMath::TimeStamp m_lastUpdateTime;
209 
213  typedef enum
214  {
215  SACTION_INVALID,
216  SACTION_APPEAR,
217  SACTION_HIDE,
218  SACTION_DISCARD,
219  SACTION_QUEUED
220  } SightAction;
221 
222  typedef std::unordered_map<std::string, SightAction> PendingSightMap;
223  PendingSightMap m_pending;
224 
232  std::deque<std::string> m_lookQueue;
233 
234  unsigned int m_maxPendingCount;
235 
236  typedef sigc::signal<void, Entity*> EntitySightSignal;
237 
238  typedef std::unordered_map<std::string, EntitySightSignal> NotifySightMap;
239  NotifySightMap m_notifySights;
240 
241  typedef std::set<Entity*> EntitySet;
242 
245  EntitySet m_moving;
246 
247  class FactoryOrdering
248  {
249  public:
250  bool operator()(Factory* a, Factory* b) const
251  { // higher priority factories are placed nearer the start
252  return a->priority() > b->priority();
253  }
254  };
255 
256  typedef std::multiset<Factory*, FactoryOrdering> FactoryStore;
257  FactoryStore m_factories;
258 
259  std::set<Task*> m_progressingTasks;
260 };
261 
262 } // of namespace Eris
263 
264 #endif // of ERIS_VIEW_H
void registerFactory(Factory *)
Register an Entity Factory with this view.
Definition: View.cpp:71
void entityDeleted(Entity *ent)
this is a hook that Entity&#39;s destructor calls to remove itself from the View&#39;s content map...
Definition: View.cpp:454
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
Factory is used to allow custom entity creation by client libraries.
Definition: Factory.h:14
bool isPending(const std::string &eid) const
test if the specified entity ID is pending initial sight on the View
Definition: View.cpp:366
Entity * getTopLevel() const
return the current top-level entity.
Definition: View.h:56
void update()
once-per-frame update of the View - clients should call this method once per game loop (or similar)...
Definition: View.cpp:105
sigc::signal< void, Entity * > EntityCreated
emitted when a SIGHT(CREATE) op is received for an entity
Definition: View.h:110
sigc::signal< void > TopLevelEntityChanged
emitted when the TLVE changes
Definition: View.h:122
View encapsulates the set of entities currently visible to an Avatar, as well as those that have rece...
Definition: View.h:37
Definition: IGRouter.h:13
void taskRateChanged(Task *)
Method to register and unregister tasks with with view, so they can have their progress updated autom...
Definition: View.cpp:139
sigc::signal< void, Entity * > EntityDeleted
emitted when a SIGHT(DELETE) op is received for an entity
Definition: View.h:113
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:36
void sendLookAt(const std::string &eid)
Issue a LOOK operation for the specified entity ID.
Definition: View.cpp:390
Handles polling of the IO system as well as making sure that registered handlers are run on the main ...
Definition: EventService.h:43
An entity which is bound to an Eris::View.
Definition: ViewEntity.h:21
TypeService & getTypeService()
Gets the TypeService attached to the view.
Definition: View.cpp:88
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
Definition: Task.h:25
unsigned int lookQueueSize() const
Retrieve the current look queue size, for debugging / statistics purposes.
Definition: View.h:138
Entity * getEntity(const std::string &eid) const
Retrieve an entity in the view by id.
Definition: View.cpp:53
The player&#39;s avatar representation.
Definition: Avatar.h:34
sigc::signal< void, Entity * > EntitySeen
emitted whenever the View creates a new Entity instance.
Definition: View.h:107
sigc::signal< void > AvatarEntityDeleted
emitted AFTER the avatar entity was deleted due to a SIGHT(DELETE) op is received ...
Definition: View.h:116
EventService & getEventService()
Gets the EventService used by the view.
Definition: View.cpp:96
virtual int priority()
retrieve this factory&#39;s priority level; higher priority factories get first chance to process a recei...
Definition: Factory.cpp:11
sigc::signal< void, Entity * > InitialSightEntity
Emitted after a new Entity has been created and initialized.
Definition: View.h:130