Merge branch 'lua_versions' into main/rendor-staging
[ryzomcore.git] / ryzom / tools / reynolds / reynolds_manager.h
blob78f2eae2f8924c242aeeca6d9e436b713ff61952
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_REYNOLDS_MANAGER_H
20 #define NL_REYNOLDS_MANAGER_H
22 // NeL
23 #include "nel/misc/types_nl.h"
24 #include "nel/misc/smart_ptr.h"
26 #include "nel/georges/u_form.h"
27 #include "nel/georges/u_form_elm.h"
29 // Game share
30 #include "game_share/continent_container.h"
32 // ReynoldsLib
33 #include "track.h"
35 // Stl
36 #include <map>
41 /**
42 * Track manager
43 * \author Benjamin Legros
44 * \author Nevrax France
45 * \date 2002
47 class CReynoldsManager
49 friend CTrack::~CTrack();
51 public:
53 /**
54 * User Motion controlled Callback type
55 * \param track is the base track
57 typedef void (*TUserCallback) (CTrackBase *track);
59 /**
60 * User Motion Callback type
61 * Called each time a controlled track is updated
62 * \param track is the base track
63 * \param motion is the current motion to be applied -- WARNING do not crash this value, only add or substract value to it
65 typedef void (*TUserMotionCallback) (CTrackBase *track, NLMISC::CVectorD &motion);
68 /// The command interface
69 class ICommandInterface
71 public:
72 /**
73 * Called when manager needs a sheet for an entity.
74 * Reply using setSheet(CEntityId)
76 virtual void requestSheet(const NLMISC::CEntityId &id) = 0;
78 /**
79 * Called when manager needs a position for an entity.
80 * Reply using setPosition(CEntityId)
82 virtual void requestPosition(const NLMISC::CEntityId &id) = 0;
84 /**
85 * Called when manager needs a position to be updated evently
86 * Reply using setPosition(CEntityId) evently
88 virtual void requestPositionUpdates(const NLMISC::CEntityId &id) = 0;
90 /**
91 * Called when manager doesn't need more position updates
93 virtual void unrequestPositionUpdates(const NLMISC::CEntityId &id) = 0;
95 /**
96 * Called when manager needs an entity vision to be updated evently
97 * Reply using setVision() evently
99 virtual void requestVision(const NLMISC::CEntityId &id) = 0;
101 /**
102 * Called when manager doesn't need more entity vision updates
104 virtual void unrequestVision(const NLMISC::CEntityId &id) = 0;
107 * Called when a track position is updated
109 virtual void updatePosition(const NLMISC::CEntityId &id, const NLMISC::CVectorD &position, float &heading) = 0;
112 * Called when track state changed
114 virtual void stateChanged(const NLMISC::CEntityId &id, CTrackBase::TTrackState state) = 0;
116 /**
117 * Called when manager leave control of an entity
119 virtual void stopTrack(const NLMISC::CEntityId &id) = 0;
122 public:
124 /// @name Reynolds Manager inits/update/release
125 //@{
127 /// Init
128 static void init(const std::string &packSheetFile = "reynolds.packed_sheets");
131 /// Load continent
132 static void loadContinent(const std::string &name, const std::string &file, sint index);
134 /// Set Sheet request callback
135 static void setCommandInterface(ICommandInterface *commandInterface) { _CommandInterface = commandInterface; }
137 /// Set User init callback
138 static void setUserInitCallback(TUserCallback cb) { _UserInitCallback = cb; }
140 /// Set User motion callback
141 static void setUserMotionCallback(TUserMotionCallback cb) { _UserMotionCallback = cb; }
143 /// Set User release callback
144 static void setUserReleaseCallback(TUserCallback cb) { _UserReleaseCallback = cb; }
146 /// Update
147 static void update(double dt = 0.1);
150 /// Release
151 static void release();
153 //@}
158 /// @name Control methods over tracks
159 //@{
161 /// Follow
162 static void follow(const NLMISC::CEntityId &entity, const NLMISC::CEntityId &target);
164 /// Go to
165 static void goTo(const NLMISC::CEntityId &entity, const NLMISC::CVectorD &position);
167 /// Stop
168 static void leaveMove(const NLMISC::CEntityId &entity);
170 /// Destroy a track
171 static void destroy(const NLMISC::CEntityId &entity);
173 //@}
178 /// @name Tracks requests and state towards interface
179 //@{
181 /// Request Sheet
182 static void requestSheet(const NLMISC::CEntityId &entity);
184 /// Request Position
185 static void requestPosition(const NLMISC::CEntityId &entity);
187 /// Request Position Updates
188 static void requestPositionUpdates(const NLMISC::CEntityId &entity);
190 /// Unrequest Position Updates
191 static void unrequestPositionUpdates(const NLMISC::CEntityId &entity);
193 /// Request Vision
194 static void requestVision(const NLMISC::CEntityId &entity);
196 /// Unrequest Vision
197 static void unrequestVision(const NLMISC::CEntityId &entity);
199 /// Track stopped following
200 static void trackStop(CTrack *track);
202 /// Updated position
203 static void updatedPosition(const NLMISC::CEntityId &entity, const NLMISC::CVectorD &position, float heading);
205 /// Updated state
206 static void stateChanged(const NLMISC::CEntityId &entity, CTrackBase::TTrackState state);
210 /// User init
211 static void initUserMotion(CTrack *track)
213 if (_UserInitCallback != NULL)
214 _UserInitCallback((CTrackBase*)track);
217 /// User move
218 static void applyUserMotion(CTrack *track, NLMISC::CVectorD &motion)
220 if (_UserMotionCallback != NULL)
221 _UserMotionCallback((CTrackBase*)track, motion);
224 /// User release
225 static void releaseUserMotion(CTrack *track)
227 if (_UserReleaseCallback != NULL)
228 _UserReleaseCallback((CTrackBase*)track);
233 /// Create Move primitive
234 static void createMovePrimitive(const NLMISC::CVectorD &pos, NLPACS::UMovePrimitive *&primitive, NLPACS::UMoveContainer *&container);
236 /// Lookup a sheet
237 static const CTrack::CSheet *lookup(const NLMISC::CSheetId &sheet);
239 //@}
244 /// @name Answers to tracks requests
245 //@{
247 /// Set Sheet
248 static void setSheet(const NLMISC::CEntityId &id, const NLMISC::CSheetId &sheet);
250 /// Set Position
251 static void setPosition(const NLMISC::CEntityId &id, const NLMISC::CVectorD &position, float heading);
253 /// Update Vision
254 static void setVision(const NLMISC::CEntityId &id, const std::vector<NLMISC::CEntityId> &in, const std::vector<NLMISC::CEntityId> &out);
256 /// Update Vision
257 static void setVision(const NLMISC::CEntityId &id, const std::vector<NLMISC::CEntityId> &vision);
259 /// Get a track
260 static CTrack *getTrack(const NLMISC::CEntityId &entity)
262 TTrackMap::iterator it = _TrackMap.find(entity);
263 return (it == _TrackMap.end()) ? NULL : (*it).second;
266 /// Get cycle
267 static uint32 getCycle() { return _Cycle; }
269 //@}
274 /// Create a non controlled track, referenced in _TrackMap
275 static CTrack *createTrack(const NLMISC::CEntityId &entity);
278 protected:
280 /// Constructor. Not to be used.
281 CReynoldsManager();
283 /// Remove a track from the whole map -- only called by the CTrack destructor
284 static void removeTrackFromMap(const NLMISC::CEntityId &entity);
286 /// Checks interface is ok
287 static bool checkInterface()
289 if (_CommandInterface == NULL)
291 nlwarning("CReynoldsLib:checkInterface(): CommandInterface not set");
292 return false;
294 return true;
297 /// Init sheets
298 static void initSheets(const std::string &packSheetFilnamePrefix);
301 protected:
303 /// Whole track container
304 typedef std::map<NLMISC::CEntityId, CTrack* > TTrackMap;
306 /// Only controlled track container
307 typedef std::map<NLMISC::CEntityId, NLMISC::CSmartPtr<CTrack> > TControlledTrackMap;
312 protected:
314 /// Continents
315 static CContinentContainer _Continents;
317 /// Track Map, all tracks referenced, held by a simple pointer so when no one references a track, it is deleted
318 static TTrackMap _TrackMap;
320 /// Controlled Track Map, only controlled tracks, held by a smart pointer
321 static TControlledTrackMap _ControlledTrackMap;
324 /// Georges sheets
325 static std::map<NLMISC::CSheetId, CTrack::CSheet> _Sheets;
327 /// Sheets initialised ?
328 static bool _Initialised;
331 /// Command interface
332 static ICommandInterface *_CommandInterface;
334 /// User init callback
335 static TUserCallback _UserInitCallback;
337 /// User motion callback
338 static TUserMotionCallback _UserMotionCallback;
340 /// User release callback
341 static TUserCallback _UserReleaseCallback;
344 /// Current internal cycle
345 static uint32 _Cycle;
349 #endif // NL_REYNOLDS_MANAGER_H
351 /* End of reynolds_manager.h */