9 #ifndef INCLUDE_FUNAPI_SERVICE_WORLD_H_ 10 #define INCLUDE_FUNAPI_SERVICE_WORLD_H_ 12 #include <boost/noncopyable.hpp> 19 class FUNAPI_DLL_VISIBILITY
World :
private boost::noncopyable {
25 struct FUNAPI_DLL_VISIBILITY
Point {
27 Point(
float x,
float y,
float z);
33 struct FUNAPI_DLL_VISIBILITY
Sphere {
35 Sphere(
const Point &coordinates,
float radius);
36 Sphere(
float x,
float y,
float z,
float radius);
43 Vector2(
float x,
float y);
50 FindOption(
bool use_distance_square,
51 bool use_sphere_center_for_distance =
false,
52 bool ignore_z_axis_in_block =
false,
53 bool use_ascending_order =
false,
54 size_t boundary_begin = 0,
55 size_t boundary_count = -1);
56 bool use_distance_square;
57 bool use_sphere_center_for_distance;
58 bool ignore_z_axis_in_block;
59 bool use_ascending_order;
60 size_t boundary_begin;
61 size_t boundary_count;
64 class FUNAPI_DLL_VISIBILITY
Object :
private boost::noncopyable {
71 explicit Object(
float radius);
73 explicit Object(int64_t
id);
74 Object(int64_t
id,
float radius);
78 int64_t GetId()
const;
80 const Point &GetCoordinates()
const;
81 const Sphere &GetSphere()
const;
83 const string &GetName()
const;
84 void SetName(
const string &name);
86 const float &GetRadius()
const;
87 void SetRadius(
float radius);
89 int64_t GetType()
const;
90 void SetType(int64_t type);
92 bool GetValueForKey(
const int64_t &key, int64_t *result)
const;
93 void SetKeyValue(
const int64_t &key,
const int64_t &value);
95 Ptr<Session> GetSession()
const;
96 void SetSession(
const Ptr<Session> &session);
101 friend class PrivateAccess;
105 typedef function<void(int64_t type, bool exist)> TypeExistenceCallback;
107 typedef function<bool(
const Point &,
109 const Ptr<Object> &)> FindFilter;
111 typedef function<bool(const Ptr<World::Object> &object)> ObjectFilter;
113 typedef std::vector<Ptr<Object> > ObjectVector;
114 typedef std::vector<Ptr<Session> > SessionVector;
115 typedef std::vector<float> DistanceVector;
117 static const int64_t kInvalidId;
119 static const FindFilter kNullFilter;
121 static FindFilter MakeFilter(int64_t type_mask);
122 static FindFilter MakeMovingSightFilter(
const Sphere &previous_coordinates,
123 int64_t type_mask = 0);
124 static FindFilter MakeRectangleFilter(
float front_gap,
129 bool is_sphere =
false,
130 int64_t type_mask = 0);
131 static FindFilter MakeCircularSectorFilter(
float front_gap,
134 float left_angle_in_degree,
135 float right_angle_in_degree,
137 bool is_sphere =
false,
138 int64_t type_mask = 0);
142 const string &GetName()
const;
144 void MonitorTypeExistence(int64_t type,
145 const TypeExistenceCallback &callback);
147 int64_t InsertObject(
const Point &coordinates,
148 const Ptr<Object> &
object) ASSERT_NO_ROLLBACK;
149 Ptr<Object> EraseObject(int64_t
id) ASSERT_NO_ROLLBACK;
150 Ptr<Object> GetObject(int64_t
id)
const;
152 size_t EraseAllObjects(ObjectVector *objects = NULL) ASSERT_NO_ROLLBACK;
154 void GetAllObjects(
const ObjectFilter &filter,
155 ObjectVector *objects)
const;
156 void GetAllObjects(ObjectVector *objects)
const;
158 size_t GetObjectCount()
const;
160 bool MoveObjectTo(int64_t
id,
const Point &coordinate) ASSERT_NO_ROLLBACK;
161 bool MoveObject(int64_t
id,
const Point &coordinates_delta,
162 Point *new_coordinates = NULL) ASSERT_NO_ROLLBACK;
164 void FindObject(
const Point &coordinates,
float distance,
165 ObjectVector *objects);
166 void FindObject(
const Point &coordinates,
float distance,
167 const FindOption &option, ObjectVector *objects,
168 DistanceVector *distances = NULL);
169 void FindObject(
const Point &coordinates,
float distance,
170 const FindOption &option,
const FindFilter &filter,
171 ObjectVector *objects, DistanceVector *distances = NULL);
173 void FindObject(int64_t
id,
float distance, ObjectVector *objects);
174 void FindObject(int64_t
id,
float distance,
const FindOption &option,
175 ObjectVector *objects, DistanceVector *distances = NULL);
176 void FindObject(int64_t
id,
float distance,
const FindOption &option,
177 const FindFilter &filter, ObjectVector *objects,
178 DistanceVector *distances = NULL);
180 void FindSession(
const Point &coordinates,
float distance,
182 void FindSession(
const Point &coordinates,
float distance,
183 const FindOption &option, SessionVector *out);
184 void FindSession(
const Point &coordinates,
float distance,
185 const FindOption &option,
const FindFilter &filter,
188 void FindSession(int64_t
id,
float distance, SessionVector *out);
189 void FindSession(int64_t
id,
float distance,
const FindOption &option,
191 void FindSession(int64_t
id,
float distance,
const FindOption &option,
192 const FindFilter &filter, SessionVector *out);
194 void Broadcast(
const Point &coordinates,
float distance,
195 const string &message_type,
const Json &message,
196 Encryption encryption, TransportProtocol protocol,
198 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
199 void Broadcast(
const Point &coordinates,
float distance,
200 const string &message_type,
const Ptr<FunMessage> &message,
201 Encryption encryption, TransportProtocol protocol,
203 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
204 void Broadcast(
const Point &coordinates,
float distance,
205 int32_t message_type,
const Ptr<FunMessage> &message,
206 Encryption encryption, TransportProtocol protocol,
208 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
209 void Broadcast(
const Point &coordinates,
float distance,
211 const Ptr<FunMessage> &message, Encryption encryption,
212 TransportProtocol protocol,
214 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
216 void Broadcast(int64_t
id,
float distance,
const string &message_type,
217 const Json &message, Encryption encryption,
218 TransportProtocol protocol,
220 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
221 void Broadcast(int64_t
id,
float distance,
const string &message_type,
222 const Ptr<FunMessage> &message, Encryption encryption,
223 TransportProtocol protocol,
225 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
226 void Broadcast(int64_t
id,
float distance, int32_t message_type,
227 const Ptr<FunMessage> &message, Encryption encryption,
228 TransportProtocol protocol,
230 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
231 void Broadcast(int64_t
id,
float distance,
233 const Ptr<FunMessage> &message, Encryption encryption,
234 TransportProtocol protocol,
236 const FindFilter &filter = kNullFilter) ASSERT_NO_ROLLBACK;
238 void Broadcast(
const string &message_type,
const Json &message,
239 Encryption encryption,
240 TransportProtocol protocol) ASSERT_NO_ROLLBACK;
241 void Broadcast(
const string &message_type,
const Ptr<FunMessage> &message,
242 Encryption encryption,
243 TransportProtocol protocol) ASSERT_NO_ROLLBACK;
244 void Broadcast(int32_t message_type,
const Ptr<FunMessage> &message,
245 Encryption encryption,
246 TransportProtocol protocol) ASSERT_NO_ROLLBACK;
248 const Ptr<FunMessage> &message, Encryption encryption,
249 TransportProtocol protocol) ASSERT_NO_ROLLBACK;
251 void InsertStaticObject(
const Point &coordinates,
252 const Ptr<Object> &
object);
253 void FindStaticObject(int64_t
id,
const FindOption &option,
254 const FindFilter &filter, ObjectVector *objects,
255 DistanceVector *distances = NULL);
256 void FindStaticObject(
const Point &coordinates,
const FindOption &option,
257 const FindFilter &filter, ObjectVector *objects,
258 DistanceVector *distances = NULL);
260 bool IsDeleted()
const;
262 void SetSingleThreadMode();
265 friend class PrivateAccess;
266 explicit World(
const string &name,
float index_block_length);
273 struct FUNAPI_DLL_VISIBILITY
Zone {
279 typedef std::vector<Zone> ZoneVector;
281 typedef function<void(const Ptr<World> &)> CreateCallback;
282 typedef function<void(
const Rpc::PeerId &)> FindServerCallback;
284 void(
const string &,
const string &,
285 const string &,
const Json &,
bool ,
286 const Ptr<World::Object> &)> ZoneHandler;
288 static void Create(
const string &name,
const ZoneVector &zones,
289 float index_block_length,
const CreateCallback &callback,
290 int64_t channel = 0) ASSERT_NO_ROLLBACK;
291 static Ptr<World> Get(
const string &name, int64_t channel = 0);
292 static bool Delete(
const string &name,
293 int64_t channel = 0) ASSERT_NO_ROLLBACK;
294 static void FindServer(
const string &name,
295 const FindServerCallback &callback,
296 int64_t channel = 0) ASSERT_NO_ROLLBACK;
298 static Ptr<World> CreateLocal(
const string &name,
const ZoneVector &zones,
299 float index_block_length,
300 int64_t channel = 0) ASSERT_NO_ROLLBACK;
301 static Ptr<World> GetLocal(
const string &name, int64_t channel = 0);
302 static bool DeleteLocal(
const string &name,
303 int64_t channel = 0) ASSERT_NO_ROLLBACK;
305 static void RegisterZoneHandler(
const ZoneHandler &handler);
309 FUNAPI_DLL_VISIBILITY
310 std::ostream &operator<<(std::ostream &out,
const World::Point &point);
312 FUNAPI_DLL_VISIBILITY
313 std::ostream &operator<<(std::ostream &out,
const World::Sphere &sphere);
317 #endif // INCLUDE_FUNAPI_SERVICE_WORLD_H_
Definition: session.h:624
#define DECLARE_CLASS_PTR(CLS)
Utility macro to forward-declare smart pointer types for a given class.
Definition: types.h:89