eris 1.4.0
A WorldForge client library.
View.h
1#ifndef ERIS_VIEW_H
2#define ERIS_VIEW_H
3
4// WF
5#include "Factory.h"
6#include "ViewEntity.h"
7#include <Atlas/Objects/ObjectsFwd.h>
8#include <wfmath/timestamp.h>
9
10// sigc++
11#include <sigc++/trackable.h>
12#include <sigc++/signal.h>
13#include <sigc++/slot.h>
14#include <sigc++/connection.h>
15
16// std
17#include <string>
18#include <deque>
19#include <map>
20#include <set>
21#include <unordered_map>
22#include <Atlas/Message/Element.h>
23#include <memory>
24#include <chrono>
25
26namespace Eris
27{
28
29class Avatar;
30class Entity;
31class Connection;
32class Task;
33class TypeService;
34class EventService;
35
40class View : public sigc::trackable
41{
42public:
43 explicit View(Avatar& av);
44 ~View();
45
50 ViewEntity* getEntity(const std::string& eid) const;
51
52 Avatar& getAvatar() const
53 {
54 return m_owner;
55 }
56
60 {
61 return m_topLevel;
62 }
63
69
75
81
87
93 void update();
94
98 void registerFactory(std::unique_ptr<Factory> factory);
99
100 double getSimulationSpeed() const;
101
102 typedef sigc::slot<void, ViewEntity*> EntitySightSlot;
103
108 sigc::connection notifyWhenEntitySeen(const std::string& eid, const EntitySightSlot& slot);
109
112 sigc::signal<void, ViewEntity*> EntitySeen;
113
115 sigc::signal<void, ViewEntity*> EntityCreated;
116
118 sigc::signal<void, ViewEntity*> EntityDeleted;
119
121 sigc::signal<void> TopLevelEntityChanged;
122
129 sigc::signal<void, ViewEntity*> InitialSightEntity;
130
131 void dumpLookQueue();
132
137 std::size_t lookQueueSize() const
138 {
139 return m_lookQueue.size();
140 }
141
147 void sendLookAt(const std::string& eid);
148
149 size_t pruneAbandonedPendingEntities();
150 Connection& getConnection() const;
151
152protected:
153 // the router passes various relevant things to us directly
154 friend class IGRouter;
155 friend class ViewEntity;
156 friend class Avatar;
157 friend class Task;
158
159 void appear(const std::string& eid, double stamp);
160 void disappear(const std::string& eid);
161 void sight(const Atlas::Objects::Entity::RootEntity& ge);
162 void deleteEntity(const std::string& eid);
163 void unseen(const std::string& eid);
164
166 bool isPending(const std::string& eid) const;
167
168 void addToPrediction(ViewEntity* ent);
169 void removeFromPrediction(ViewEntity* ent);
170
177 void taskRateChanged(Task*);
178private:
179 ViewEntity* initialSight(const Atlas::Objects::Entity::RootEntity& ge);
180
181 void getEntityFromServer(const std::string& eid);
182
184 void setTopLevelEntity(Entity* newTopLevel);
185
186 std::unique_ptr<ViewEntity> createEntity(const Atlas::Objects::Entity::RootEntity&);
187
188 void parseSimulationSpeed(const Atlas::Message::Element& element);
189
194 void issueQueuedLook();
195
196 void eraseFromLookQueue(const std::string& eid);
197
198 typedef std::unordered_map<std::string, std::unique_ptr<ViewEntity>> IdEntityMap;
199
200 Avatar& m_owner;
201
202 struct EntityEntry {
203 std::unique_ptr<ViewEntity> entity;
204 std::unique_ptr<EntityRouter> entityRouter;
205 };
206 std::unordered_map<std::string, EntityEntry> m_contents;
207 Entity* m_topLevel;
208 WFMath::TimeStamp m_lastUpdateTime;
209
213 double m_simulationSpeed;
214
218 enum class SightAction
219 {
220 INVALID,
221 APPEAR,
222 HIDE,
223 DISCARD,
224 QUEUED
225 };
226
227 struct PendingStatus {
228 SightAction sightAction;
229 std::chrono::steady_clock::time_point registrationTime = std::chrono::steady_clock::now();
230 };
231
232 std::map<std::string, PendingStatus> m_pending;
233
241 std::deque<std::string> m_lookQueue;
242
243 sigc::connection m_simulationSpeedConnection;
244
245 unsigned int m_maxPendingCount;
246
247 typedef sigc::signal<void, ViewEntity*> EntitySightSignal;
248
249 typedef std::unordered_map<std::string, EntitySightSignal> NotifySightMap;
250 NotifySightMap m_notifySights;
251
252 typedef std::set<ViewEntity*> EntitySet;
253
256 EntitySet m_moving;
257
258 struct FactoryOrdering
259 {
260 bool operator()(const std::unique_ptr<Factory>& a, const std::unique_ptr<Factory>& b) const
261 { // higher priority factories are placed nearer the start
262 return a->priority() > b->priority();
263 }
264 };
265
266 typedef std::multiset<std::unique_ptr<Factory>, FactoryOrdering> FactoryStore;
267 FactoryStore m_factories;
268
269 std::set<Task*> m_progressingTasks;
270};
271
272} // of namespace Eris
273
274#endif // of ERIS_VIEW_H
Entity is a concrete (instantiable) class representing one game entity.
Definition: Entity.h:56
Handles polling of the IO system as well as making sure that registered handlers are run on the main ...
Definition: EventService.h:43
An entity which is bound to an Eris::View. This subclass of Eris::Entity is intimately bound to a Vie...
Definition: ViewEntity.h:21
void registerFactory(std::unique_ptr< Factory > factory)
Definition: View.cpp:54
sigc::signal< void, ViewEntity * > InitialSightEntity
Definition: View.h:129
EventService & getEventService()
Gets the EventService used by the view.
Definition: View.cpp:77
void update()
Definition: View.cpp:89
sigc::signal< void, ViewEntity * > EntityCreated
Definition: View.h:115
Entity * getTopLevel() const
Definition: View.h:59
std::size_t lookQueueSize() const
Definition: View.h:137
sigc::signal< void, ViewEntity * > EntityDeleted
Definition: View.h:118
ViewEntity * getEntity(const std::string &eid) const
Definition: View.cpp:45
void sendLookAt(const std::string &eid)
Definition: View.cpp:375
sigc::connection notifyWhenEntitySeen(const std::string &eid, const EntitySightSlot &slot)
Definition: View.cpp:58
bool isPending(const std::string &eid) const
test if the specified entity ID is pending initial sight on the View
Definition: View.cpp:336
void taskRateChanged(Task *)
Definition: View.cpp:134
sigc::signal< void > TopLevelEntityChanged
emitted when the TLVE changes
Definition: View.h:121
TypeService & getTypeService()
Gets the TypeService attached to the view.
Definition: View.cpp:69
sigc::signal< void, ViewEntity * > EntitySeen
Definition: View.h:112
Definition: Account.cpp:33