Add infos into target window
[ryzomcore.git] / ryzom / server / src / gpm_service / patat_subscribe_manager.h
blob49ffe80c73ff5b1447a9e9ae808ccafd3626314b
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef NL_PATAT_SUBSCRIBE_MANAGER_H
20 #define NL_PATAT_SUBSCRIBE_MANAGER_H
22 #include "nel/misc/types_nl.h"
23 #include "nel/misc/entity_id.h"
24 #include "nel/misc/vector.h"
25 #include "nel/misc/stream.h"
27 #include "patat_grid.h"
28 #include "nel/net/unified_network.h"
30 #include <map>
31 #include <set>
32 #include <vector>
33 #include <string>
35 namespace NLPACS
37 class UMoveContainer;
40 /**
41 * Patat event subscription management.
42 * Allows to be notified when an entity enters or leaves a patat.
44 * To use it, proceed this way :
45 * 1. \c init() with world bounds (in meters)
46 * 2. Load all needed patats with \c usePrim(<file>) where <file> points to a .prim file.
47 * 3. \c build() the manager.
49 * Once this is done, you can't add more patats (won't be inserted anyway.)
50 * Subscription is done by calling subscribe(), and removed by unsubscribe().
51 * Call getNewEntryIndex() to update the patats events, and call emitChanges() at each update.
53 * \author Benjamin Legros
54 * \author Nevrax France
55 * \date 2002
57 class CPatatSubscribeManager
59 public:
60 typedef uint16 TPatatId;
62 typedef std::pair<std::string, TPatatId> TPatatSubscription;
64 protected:
66 class CPatat;
67 class CSubscriber;
69 /// A Map of subscribed patats
70 typedef std::map<sint32, CPatat> TPatatMap;
72 /// A Map of subscribers
73 typedef std::map<NLNET::TServiceId, CSubscriber> TSubscriberMap;
75 /// A Map of id
76 typedef std::map<std::string, sint32> TTriggerIdMap;
78 /// A patat subscriber
79 class CPatatSubscriber
81 public:
82 NLNET::TServiceId Service;
83 TSubscriberMap::iterator SubscriberIterator;
84 TPatatId PatatId;
87 /// A patat
88 class CPatat
90 public:
91 CPatat() : Modified(false) {}
92 std::string Name;
93 sint32 InternalPatatId;
94 std::vector<CPatatSubscriber> Subscribers;
95 std::vector<NLMISC::CEntityId> Ins;
96 std::vector<NLMISC::CEntityId> Outs;
97 std::set<NLMISC::CEntityId> StillIns;
98 bool Modified;
100 void serial(NLMISC::IStream &f)
102 f.serial(Name);
103 f.serial(InternalPatatId);
107 /// A list of modified patats
108 typedef std::vector<TPatatMap::iterator> TModifiedPatats;
110 /// A subscribed patat
111 class CSubscribedPatat
113 public:
114 sint32 InternalPatatId;
115 TPatatId PatatId;
116 TPatatMap::iterator PatatIterator;
119 /// A subscriber
120 class CSubscriber
122 public:
123 CSubscriber() : OutsMessage("",false), InsMessage("",false) {} // always output messages
125 NLNET::TServiceId Service;
126 NLNET::CMessage OutsMessage;
127 uint32 OutsMsgSize;
128 NLNET::CMessage InsMessage;
129 uint32 InsMsgSize;
130 std::vector<CSubscribedPatat> Patats;
133 /// Patat grid
134 CPatatGrid _PatatGrid;
136 /// Subscribed patats
137 TPatatMap _PatatMap;
139 /// Subscribers
140 TSubscriberMap _SubscriberMap;
142 /// Triggers map
143 TTriggerIdMap _TriggerMap;
145 /// Modified patats
146 TModifiedPatats _ModifiedPatats;
148 public:
150 /// Constructor
151 CPatatSubscribeManager();
153 /// Destructor
154 ~CPatatSubscribeManager();
156 /// Init
157 void init();
159 /// Serial
160 void serial(NLMISC::IStream &f);
162 /// Use a prim file, patats in file will be processed at build() time.
163 void usePrim(const std::string &primFile);
165 /// Register a pacs trigger id
166 void usePacsTrigger(sint32 id, const std::string &name);
168 /// Checks if patat exists
169 bool exist(const std::string &name) const { return _PatatGrid.exist(name); }
171 /// Subscribe to a patat
172 void subscribe(NLNET::TServiceId service, const TPatatSubscription &patat);
174 /// Unsubscribe
175 void unsubscribe(NLNET::TServiceId service, TPatatId patat);
177 /// Unsubscribe for a whole service
178 void unsubscribe(NLNET::TServiceId service);
181 /// Get entry index at pos
182 uint32 getEntryIndex(const NLMISC::CVector &pos) { return _PatatGrid.getEntryIndex(pos); }
184 /// Move entity and get its new patats entry index
185 uint32 getNewEntryIndex(const NLMISC::CEntityId &id, const NLMISC::CVector &pos, uint32 previousEntryIndex);
187 /// Set entry index
188 void setNewEntryIndex(const NLMISC::CEntityId &id, uint32 newEntryIndex, uint32 previousEntryIndex);
190 /// Process pacs trigger collisions
191 void processPacsTriggers(NLPACS::UMoveContainer *moveContainer);
193 /// Emit changes
194 void emitChanges();
197 /// Display info for trigger
198 void displayTriggers(NLMISC::CLog *log = NLMISC::InfoLog);
200 /// Display info for trigger
201 void displayTriggerInfo(const std::string &name, NLMISC::CLog *log = NLMISC::InfoLog);
203 /// Display info for trigger
204 void displaySubscribers(NLMISC::CLog *log = NLMISC::InfoLog);
206 /// Display info for trigger
207 void displaySubscriberInfo(NLNET::TServiceId service, NLMISC::CLog *log = NLMISC::InfoLog);
209 /// Display patat grid info
210 void displayPatatGridInfo(NLMISC::CLog *log = NLMISC::InfoLog)
212 _PatatGrid.displayInfo(log);
216 /// Add CPrimZone class filter
217 void addPrimZoneFilter(const std::string &filter) { _PatatGrid.addPrimZoneFilter(filter); }
219 /// Remove CPrimZone class filter
220 void removePrimZoneFilter(const std::string &filter) { _PatatGrid.removePrimZoneFilter(filter); }
222 /// Reset CPrimZone class filter
223 void resetPrimZoneFilter() { _PatatGrid.resetPrimZoneFilter(); }
227 #endif // NL_PATAT_SUBSCRIBE_MANAGER_H
229 /* End of patat_subscribe_manager.h */