1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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"
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
57 class CPatatSubscribeManager
60 typedef uint16 TPatatId
;
62 typedef std::pair
<std::string
, TPatatId
> TPatatSubscription
;
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
;
76 typedef std::map
<std::string
, sint32
> TTriggerIdMap
;
78 /// A patat subscriber
79 class CPatatSubscriber
82 NLNET::TServiceId Service
;
83 TSubscriberMap::iterator SubscriberIterator
;
91 CPatat() : Modified(false) {}
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
;
100 void serial(NLMISC::IStream
&f
)
103 f
.serial(InternalPatatId
);
107 /// A list of modified patats
108 typedef std::vector
<TPatatMap::iterator
> TModifiedPatats
;
110 /// A subscribed patat
111 class CSubscribedPatat
114 sint32 InternalPatatId
;
116 TPatatMap::iterator PatatIterator
;
123 CSubscriber() : OutsMessage("",false), InsMessage("",false) {} // always output messages
125 NLNET::TServiceId Service
;
126 NLNET::CMessage OutsMessage
;
128 NLNET::CMessage InsMessage
;
130 std::vector
<CSubscribedPatat
> Patats
;
134 CPatatGrid _PatatGrid
;
136 /// Subscribed patats
140 TSubscriberMap _SubscriberMap
;
143 TTriggerIdMap _TriggerMap
;
146 TModifiedPatats _ModifiedPatats
;
151 CPatatSubscribeManager();
154 ~CPatatSubscribeManager();
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
);
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
);
188 void setNewEntryIndex(const NLMISC::CEntityId
&id
, uint32 newEntryIndex
, uint32 previousEntryIndex
);
190 /// Process pacs trigger collisions
191 void processPacsTriggers(NLPACS::UMoveContainer
*moveContainer
);
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 */