00001 #ifndef ERIS_WORLD_H
00002 #define ERIS_WORLD_H
00003
00004 #include <sigc++/object.h>
00005 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0
00006 #include <sigc++/basic_signal.h>
00007 #else
00008 #include <sigc++/signal.h>
00009 #endif
00010
00011 #include <map>
00012
00013
00014 #if defined(__GNUC__) && __GNUC__ < 3
00015 # include <multimap.h>
00016 #endif
00017
00018 namespace Atlas {
00019 namespace Objects {
00020 namespace Entity {
00021 class RootEntity;
00022 class GameEntity;
00023 }
00024
00025 namespace Operation {
00026 class Move;
00027 class Set;
00028 class Sound;
00029 class Talk;
00030 class Look;
00031 class Appearance;
00032 class Disappearance;
00033 class Info;
00034 class Delete;
00035 class Create;
00036 class Sight;
00037 }
00038 }
00039 }
00040
00041 #include <Eris/Types.h>
00042
00043 namespace Eris {
00044
00045
00046 class Connection;
00047 class Player;
00048 class Factory;
00049 class InvisibleEntityCache;
00050 class Avatar;
00051
00052
00053 typedef std::map<std::string, Entity*> EntityIDMap;
00054
00055 class UnknownEntity : public BaseException
00056 {
00057 public:
00058 UnknownEntity(const std::string &msg, const std::string &id) :
00059 BaseException(msg), _id(id) {;}
00060 virtual ~UnknownEntity() throw() { }
00061 std::string _id;
00062 };
00063
00065 class World : virtual public SigC::Object
00066 {
00067 public:
00068
00069 World(Player *p, Connection *c);
00070 ~World();
00071
00073 EntityPtr lookup(const std::string &id);
00074
00076 EntityPtr getRootEntity();
00077
00079 Connection* getConnection() const
00080 { return _con; }
00081
00086 void tick();
00087
00088
00090
00093 EntityPtr getFocusedEntity()
00094 { return _focused; }
00095
00098 const std::string& getFocusedEntityID();
00099
00100 const std::string& getDispatcherID() const {return _igID;}
00101
00102
00105
00106
00107 void registerFactory(Factory *f, unsigned int priority = 1);
00108
00110 void unregisterFactory(Factory *f);
00111
00113 Avatar* createAvatar(long refno, const std::string& id = "");
00115 Avatar* getPrimaryAvatar() {return _avatar;}
00116
00118 static World* getPrimary() {return _theWorld;}
00120 static World* Instance() {return _theWorld;}
00121
00122
00124
00125 for the first time (i.e basic setup is all complete) */
00126 SigC::Signal1<void, Entity*> EntityCreate;
00127
00129
00131 SigC::Signal1<void, Entity*> EntityDelete;
00132
00134 SigC::Signal1<void, Entity*> Entered;
00135
00137 SigC::Signal1<void, Entity*> Appearance;
00138
00140 SigC::Signal1<void, Entity*> Disappearance;
00141
00146 SigC::Signal1<void, Entity*> RootEntityChanged;
00147
00148
00149
00152 SigC::Signal0<void> Destroyed;
00153
00154 protected:
00155 friend class Entity;
00156 friend class Avatar;
00157
00158
00159 friend class InvisibleEntityCache;
00160
00161 void look(const std::string &id);
00162 EntityPtr create(const Atlas::Objects::Entity::GameEntity &ge);
00163
00164 bool isPendingInitialSight(const std::string &id)
00165 { return _pendingInitialSight.count(id); }
00166
00167 void registerCallbacks();
00168
00169 void setRootEntity(Entity* root);
00170
00175 void markInvisible(Entity *e);
00176
00179 void markVisible(Entity *e);
00180
00182 void flush(Entity *e);
00183
00184 void recvInfoCharacter(const Atlas::Objects::Operation::Info &ifo,
00185 const Atlas::Objects::Entity::GameEntity &character);
00186 void recvAppear(const Atlas::Objects::Operation::Appearance &ap);
00187 void recvDisappear(const Atlas::Objects::Operation::Disappearance &ds);
00188
00189
00190 void recvSightObject(const Atlas::Objects::Operation::Sight &sight,
00191 const Atlas::Objects::Entity::GameEntity &ent);
00192
00193 void recvSightCreate(const Atlas::Objects::Operation::Create &cr,
00194 const Atlas::Objects::Entity::GameEntity &ent);
00195 void recvSightDelete(const Atlas::Objects::Operation::Delete &del);
00196 void recvSightSet(const Atlas::Objects::Operation::Set &set);
00197 void recvSightMove(const Atlas::Objects::Operation::Move &mv);
00198
00199
00200 void recvSoundTalk(const Atlas::Objects::Operation::Sound &snd,
00201 const Atlas::Objects::Operation::Talk &tk);
00202
00203
00204 void recvErrorLook(const Atlas::Objects::Operation::Look &lk);
00205
00206 void lookupTimeout(std::string id);
00207
00209 void netConnect();
00210
00212 std::string _characterID;
00214
00217 std::string _igID;
00218 Connection* _con;
00219 Player* _player;
00220 bool _initialEntry;
00221
00222 EntityIDMap _lookup;
00223 EntityPtr _root,
00224 _focused;
00225
00226
00227 typedef std::multimap<unsigned int, Factory*> FactoryMap;
00228
00230 FactoryMap _efactories;
00231
00233 StringSet _pendingInitialSight;
00234
00236 InvisibleEntityCache* _ieCache;
00237
00239 Avatar* _avatar;
00240
00242 static World* _theWorld;
00243 };
00244
00245 }
00246 #endif