00001 #ifndef ERIS_VIEW_H
00002 #define ERIS_VIEW_H
00003
00004 #include <Eris/Types.h>
00005 #include <Eris/Factory.h>
00006 #include <Atlas/Objects/ObjectsFwd.h>
00007
00008 #include <sigc++/trackable.h>
00009 #include <sigc++/signal.h>
00010 #include <sigc++/slot.h>
00011 #include <sigc++/connection.h>
00012
00013 #include <map>
00014 #include <deque>
00015
00016 namespace Eris
00017 {
00018
00019 class Avatar;
00020 class Entity;
00021 class Connection;
00022
00027 class View : public sigc::trackable
00028 {
00029 public:
00030 View(Avatar* av);
00031 ~View();
00032
00037 Entity* getEntity(const std::string& eid) const;
00038
00039 Avatar* getAvatar() const
00040 {
00041 return m_owner;
00042 }
00043
00046 Entity* getTopLevel() const
00047 {
00048 return m_topLevel;
00049 }
00050
00056 void update();
00057
00061 void registerFactory(Factory*);
00062
00063 typedef sigc::slot<void, Entity*> EntitySightSlot;
00064
00069 sigc::connection notifyWhenEntitySeen(const std::string& eid, const EntitySightSlot& slot);
00070
00073 SigC::Signal1<void, Entity*> EntitySeen;
00074
00076 SigC::Signal1<void, Entity*> EntityCreated;
00077
00079 sigc::signal<void, Entity*> EntityDeleted;
00080
00081 sigc::signal<void, Entity*> Appearance;
00082 sigc::signal<void, Entity*> Disappearance;
00083
00085 sigc::signal<void> TopLevelEntityChanged;
00086
00087 void dumpLookQueue();
00088
00093 unsigned int lookQueueSize() const
00094 {
00095 return m_lookQueue.size();
00096 }
00097 protected:
00098
00099 friend class IGRouter;
00100 friend class Entity;
00101 friend class Avatar;
00102
00103 void appear(const std::string& eid, float stamp);
00104 void disappear(const std::string& eid);
00105 void sight(const Atlas::Objects::Entity::RootEntity& ge);
00106 void create(const Atlas::Objects::Entity::RootEntity& ge);
00107 void deleteEntity(const std::string& eid);
00108 void unseen(const std::string& eid);
00109
00110 void setEntityVisible(Entity* ent, bool vis);
00111
00113 bool isPending(const std::string& eid) const;
00114
00115 void addToPrediction(Entity* ent);
00116 void removeFromPrediction(Entity* ent);
00117
00121 void entityDeleted(Entity* ent);
00122
00123 private:
00124 Entity* initialSight(const Atlas::Objects::Entity::RootEntity& ge);
00125
00126 Connection* getConnection() const;
00127 void getEntityFromServer(const std::string& eid);
00128
00130 void setTopLevelEntity(Entity* newTopLevel);
00131
00132 Entity* createEntity(const Atlas::Objects::Entity::RootEntity&);
00133
00139 void sendLookAt(const std::string& eid);
00140
00145 void issueQueuedLook();
00146
00147 void eraseFromLookQueue(const std::string& eid);
00148
00149 typedef std::map<std::string, Entity*> IdEntityMap;
00150
00151 Avatar* m_owner;
00152 IdEntityMap m_contents;
00153 Entity* m_topLevel;
00154
00155 sigc::signal<void, Entity*> InitialSightEntity;
00156
00160 typedef enum
00161 {
00162 SACTION_INVALID,
00163 SACTION_APPEAR,
00164 SACTION_HIDE,
00165 SACTION_DISCARD,
00166 SACTION_QUEUED
00167 } SightAction;
00168
00169 typedef std::map<std::string, SightAction> PendingSightMap;
00170 PendingSightMap m_pending;
00171
00179 std::deque<std::string> m_lookQueue;
00180
00181 unsigned int m_maxPendingCount;
00182
00183 typedef sigc::signal<void, Entity*> EntitySightSignal;
00184
00185 typedef std::map<std::string, EntitySightSignal> NotifySightMap;
00186 NotifySightMap m_notifySights;
00187
00188 typedef std::set<Entity*> EntitySet;
00189
00192 EntitySet m_moving;
00193
00194 class FactoryOrdering
00195 {
00196 public:
00197 bool operator()(Factory* a, Factory* b) const
00198 {
00199 return a->priority() > b->priority();
00200 }
00201 };
00202
00203 typedef std::multiset<Factory*, FactoryOrdering> FactoryStore;
00204 FactoryStore m_factories;
00205 };
00206
00207 }
00208
00209 #endif // of ERIS_VIEW_H