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