00001 #ifndef ERIS_VIEW_H
00002 #define ERIS_VIEW_H
00003
00004
00005 #include <Eris/Factory.h>
00006 #include <Atlas/Objects/ObjectsFwd.h>
00007 #include <wfmath/timestamp.h>
00008
00009
00010 #include <sigc++/trackable.h>
00011 #include <sigc++/signal.h>
00012 #include <sigc++/slot.h>
00013 #include <sigc++/connection.h>
00014
00015
00016 #include <deque>
00017 #include <map>
00018 #include <set>
00019
00020 namespace Eris
00021 {
00022
00023 class Avatar;
00024 class ViewEntity;
00025 class Entity;
00026 class Connection;
00027 class Task;
00028
00033 class View : public sigc::trackable
00034 {
00035 public:
00036 View(Avatar* av);
00037 ~View();
00038
00043 Entity* getEntity(const std::string& eid) const;
00044
00045 Avatar* getAvatar() const
00046 {
00047 return m_owner;
00048 }
00049
00052 Entity* getTopLevel() const
00053 {
00054 return m_topLevel;
00055 }
00056
00062 void update();
00063
00067 void registerFactory(Factory*);
00068
00069 typedef sigc::slot<void, Entity*> EntitySightSlot;
00070
00075 sigc::connection notifyWhenEntitySeen(const std::string& eid, const EntitySightSlot& slot);
00076
00079 sigc::signal<void, Entity*> EntitySeen;
00080
00082 sigc::signal<void, Entity*> EntityCreated;
00083
00085 sigc::signal<void, Entity*> EntityDeleted;
00086
00087 sigc::signal<void, Entity*> Appearance;
00088 sigc::signal<void, Entity*> Disappearance;
00089
00091 sigc::signal<void> TopLevelEntityChanged;
00092
00093 void dumpLookQueue();
00094
00099 unsigned int lookQueueSize() const
00100 {
00101 return m_lookQueue.size();
00102 }
00103 protected:
00104
00105 friend class IGRouter;
00106 friend class ViewEntity;
00107 friend class Avatar;
00108 friend class Task;
00109
00110 void appear(const std::string& eid, float stamp);
00111 void disappear(const std::string& eid);
00112 void sight(const Atlas::Objects::Entity::RootEntity& ge);
00113 void create(const Atlas::Objects::Entity::RootEntity& ge);
00114 void deleteEntity(const std::string& eid);
00115 void unseen(const std::string& eid);
00116
00117 void setEntityVisible(Entity* ent, bool vis);
00118
00120 bool isPending(const std::string& eid) const;
00121
00122 void addToPrediction(Entity* ent);
00123 void removeFromPrediction(Entity* ent);
00124
00128 void entityDeleted(Entity* ent);
00129
00136 void taskRateChanged(Task*);
00137 private:
00138 Entity* initialSight(const Atlas::Objects::Entity::RootEntity& ge);
00139
00140 Connection* getConnection() const;
00141 void getEntityFromServer(const std::string& eid);
00142
00144 void setTopLevelEntity(Entity* newTopLevel);
00145
00146 Entity* createEntity(const Atlas::Objects::Entity::RootEntity&);
00147
00153 void sendLookAt(const std::string& eid);
00154
00159 void issueQueuedLook();
00160
00161 void eraseFromLookQueue(const std::string& eid);
00162
00163 typedef std::map<std::string, Entity*> IdEntityMap;
00164
00165 Avatar* m_owner;
00166 IdEntityMap m_contents;
00167 Entity* m_topLevel;
00168 WFMath::TimeStamp m_lastUpdateTime;
00169
00170 sigc::signal<void, Entity*> InitialSightEntity;
00171
00175 typedef enum
00176 {
00177 SACTION_INVALID,
00178 SACTION_APPEAR,
00179 SACTION_HIDE,
00180 SACTION_DISCARD,
00181 SACTION_QUEUED
00182 } SightAction;
00183
00184 typedef std::map<std::string, SightAction> PendingSightMap;
00185 PendingSightMap m_pending;
00186
00194 std::deque<std::string> m_lookQueue;
00195
00196 unsigned int m_maxPendingCount;
00197
00198 typedef sigc::signal<void, Entity*> EntitySightSignal;
00199
00200 typedef std::map<std::string, EntitySightSignal> NotifySightMap;
00201 NotifySightMap m_notifySights;
00202
00203 typedef std::set<Entity*> EntitySet;
00204
00207 EntitySet m_moving;
00208
00209 class FactoryOrdering
00210 {
00211 public:
00212 bool operator()(Factory* a, Factory* b) const
00213 {
00214 return a->priority() > b->priority();
00215 }
00216 };
00217
00218 typedef std::multiset<Factory*, FactoryOrdering> FactoryStore;
00219 FactoryStore m_factories;
00220
00221 std::set<Task*> m_progressingTasks;
00222 };
00223
00224 }
00225
00226 #endif // of ERIS_VIEW_H