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_REYNOLDS_MANAGER_H
20 #define NL_REYNOLDS_MANAGER_H
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"
30 #include "game_share/continent_container.h"
43 * \author Benjamin Legros
44 * \author Nevrax France
47 class CReynoldsManager
49 friend CTrack::~CTrack();
54 * User Motion controlled Callback type
55 * \param track is the base track
57 typedef void (*TUserCallback
) (CTrackBase
*track
);
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
73 * Called when manager needs a sheet for an entity.
74 * Reply using setSheet(CEntityId)
76 virtual void requestSheet(const NLMISC::CEntityId
&id
) = 0;
79 * Called when manager needs a position for an entity.
80 * Reply using setPosition(CEntityId)
82 virtual void requestPosition(const NLMISC::CEntityId
&id
) = 0;
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;
91 * Called when manager doesn't need more position updates
93 virtual void unrequestPositionUpdates(const NLMISC::CEntityId
&id
) = 0;
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;
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;
117 * Called when manager leave control of an entity
119 virtual void stopTrack(const NLMISC::CEntityId
&id
) = 0;
124 /// @name Reynolds Manager inits/update/release
128 static void init(const std::string
&packSheetFile
= "reynolds.packed_sheets");
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
; }
147 static void update(double dt
= 0.1);
151 static void release();
158 /// @name Control methods over tracks
162 static void follow(const NLMISC::CEntityId
&entity
, const NLMISC::CEntityId
&target
);
165 static void goTo(const NLMISC::CEntityId
&entity
, const NLMISC::CVectorD
&position
);
168 static void leaveMove(const NLMISC::CEntityId
&entity
);
171 static void destroy(const NLMISC::CEntityId
&entity
);
178 /// @name Tracks requests and state towards interface
182 static void requestSheet(const NLMISC::CEntityId
&entity
);
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
);
194 static void requestVision(const NLMISC::CEntityId
&entity
);
197 static void unrequestVision(const NLMISC::CEntityId
&entity
);
199 /// Track stopped following
200 static void trackStop(CTrack
*track
);
203 static void updatedPosition(const NLMISC::CEntityId
&entity
, const NLMISC::CVectorD
&position
, float heading
);
206 static void stateChanged(const NLMISC::CEntityId
&entity
, CTrackBase::TTrackState state
);
211 static void initUserMotion(CTrack
*track
)
213 if (_UserInitCallback
!= NULL
)
214 _UserInitCallback((CTrackBase
*)track
);
218 static void applyUserMotion(CTrack
*track
, NLMISC::CVectorD
&motion
)
220 if (_UserMotionCallback
!= NULL
)
221 _UserMotionCallback((CTrackBase
*)track
, motion
);
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
);
237 static const CTrack::CSheet
*lookup(const NLMISC::CSheetId
&sheet
);
244 /// @name Answers to tracks requests
248 static void setSheet(const NLMISC::CEntityId
&id
, const NLMISC::CSheetId
&sheet
);
251 static void setPosition(const NLMISC::CEntityId
&id
, const NLMISC::CVectorD
&position
, float heading
);
254 static void setVision(const NLMISC::CEntityId
&id
, const std::vector
<NLMISC::CEntityId
> &in
, const std::vector
<NLMISC::CEntityId
> &out
);
257 static void setVision(const NLMISC::CEntityId
&id
, const std::vector
<NLMISC::CEntityId
> &vision
);
260 static CTrack
*getTrack(const NLMISC::CEntityId
&entity
)
262 TTrackMap::iterator it
= _TrackMap
.find(entity
);
263 return (it
== _TrackMap
.end()) ? NULL
: (*it
).second
;
267 static uint32
getCycle() { return _Cycle
; }
274 /// Create a non controlled track, referenced in _TrackMap
275 static CTrack
*createTrack(const NLMISC::CEntityId
&entity
);
280 /// Constructor. Not to be used.
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");
298 static void initSheets(const std::string
&packSheetFilnamePrefix
);
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
;
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
;
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 */