Eris  1.3.21
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 
87  sigc::signal<void, Entity*> Appearance;
88  sigc::signal<void, Entity*> Disappearance;
89 
91  sigc::signal<void> TopLevelEntityChanged;
92 
93  void dumpLookQueue();
94 
99  unsigned int lookQueueSize() const
100  {
101  return m_lookQueue.size();
102  }
103 protected:
104  // the router passes various relevant things to us directly
105  friend class IGRouter;
106  friend class ViewEntity;
107  friend class Avatar;
108  friend class Task;
109 
110  void appear(const std::string& eid, float stamp);
111  void disappear(const std::string& eid);
112  void sight(const Atlas::Objects::Entity::RootEntity& ge);
113  void create(const Atlas::Objects::Entity::RootEntity& ge);
114  void deleteEntity(const std::string& eid);
115  void unseen(const std::string& eid);
116 
117  void setEntityVisible(Entity* ent, bool vis);
118 
120  bool isPending(const std::string& eid) const;
121 
122  void addToPrediction(Entity* ent);
123  void removeFromPrediction(Entity* ent);
124 
128  void entityDeleted(Entity* ent);
129 
136  void taskRateChanged(Task*);
137 private:
138  Entity* initialSight(const Atlas::Objects::Entity::RootEntity& ge);
139 
140  Connection* getConnection() const;
141  void getEntityFromServer(const std::string& eid);
142 
144  void setTopLevelEntity(Entity* newTopLevel);
145 
146  Entity* createEntity(const Atlas::Objects::Entity::RootEntity&);
147 
153  void sendLookAt(const std::string& eid);
154 
159  void issueQueuedLook();
160 
161  void eraseFromLookQueue(const std::string& eid);
162 
163  typedef std::map<std::string, Entity*> IdEntityMap;
164 
165  Avatar* m_owner;
166  IdEntityMap m_contents;
167  Entity* m_topLevel;
168  WFMath::TimeStamp m_lastUpdateTime;
169 
170  sigc::signal<void, Entity*> InitialSightEntity;
171 
175  typedef enum
176  {
177  SACTION_INVALID,
178  SACTION_APPEAR,
179  SACTION_HIDE,
180  SACTION_DISCARD,
181  SACTION_QUEUED
182  } SightAction;
183 
184  typedef std::map<std::string, SightAction> PendingSightMap;
185  PendingSightMap m_pending;
186 
194  std::deque<std::string> m_lookQueue;
195 
196  unsigned int m_maxPendingCount;
197 
198  typedef sigc::signal<void, Entity*> EntitySightSignal;
199 
200  typedef std::map<std::string, EntitySightSignal> NotifySightMap;
201  NotifySightMap m_notifySights;
202 
203  typedef std::set<Entity*> EntitySet;
204 
207  EntitySet m_moving;
208 
209  class FactoryOrdering
210  {
211  public:
212  bool operator()(Factory* a, Factory* b) const
213  { // higher priority factories are placed nearer the start
214  return a->priority() > b->priority();
215  }
216  };
217 
218  typedef std::multiset<Factory*, FactoryOrdering> FactoryStore;
219  FactoryStore m_factories;
220 
221  std::set<Task*> m_progressingTasks;
222 };
223 
224 } // of namespace Eris
225 
226 #endif // of ERIS_VIEW_H