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/>.
20 #include "nel/misc/types_nl.h"
22 #include "nel/misc/md5.h"
23 #include "nel/misc/sheet_id.h"
24 #include "nel/misc/sheet_id.h"
25 #include "nel/misc/entity_id.h"
26 #include "nel/misc/smart_ptr.h"
32 #include "game_share/r2_types.h"
34 #include "r2_share_itf.h"
36 //#include "game_share/far_position.h"
52 /*! Access Time optimised container Object Tree.
53 * Transforms an object tree into a map for time access optimization to the different nodes.
54 * The key used to find an element is set in the ctor
59 /// Set the id Name (b.e. if "InstanceId" is used then look at the "InstanceId" attribute to Identify a node)
60 CInstanceMap(const std::string
& idName
):_IdName(idName
){}
62 /// Sets the initial tree (clear the container and add)
63 void set(CObject
* root
);
65 /// Add a new tree (register all its node)
66 void add(CObject
* root
);
68 /// Remove a tree (unregister all its node)
69 void remove(CObject
* root
);
71 /// Find a element by its id
72 CObject
* find (const std::string
& instanceId
);
75 //:XXX: Global functionality and specific must be in two different class
77 /// Returns the maximum of id used by a character .
78 sint32
getMaxId(const std::string
& eid
);
80 void setMaxId(const std::string
&eid
, sint32 maxId
);
83 std::map
<std::string
, CObject
*> _Map
;
85 //:XXX: Must not be here
86 /// UserId -> maximum id used
87 std::map
<std::string
, sint32
> _MapEids
;
89 // The Name of the attribute used to identify a node.
90 const std::string _IdName
;
97 * - Edition data / Animation data
98 * - Palette used to create elements
99 * - InstanceMap to give quick access to tree Node
100 * - List of Current characters connect to this scenario
103 //:XXX: _CurrentUsers will still be useful after session manager?
104 class CScenario
: public NLMISC::CRefCount
112 * /param property the CObject node of the edition data.
114 explicit CScenario(CObject
* property
, TScenarioSessionType sessionType
= st_edit
);
117 virtual ~CScenario();
121 /*! Reset the Edition data.
122 * /param /highLevle the edition data
124 void setHighLevel(CObject
* highLevel
);
126 /*! Reset the Animation data.
127 * /param /highLevle the edition data
129 void setRtData(CObject
* rtScenario
);
134 Add, set, erase, move node of a scenario
135 /see CObject definition
139 bool setNode( const std::string
& instanceId
, const std::string
& attrName
, CObject
* value
);
141 bool insertNode(const std::string
& instanceId
, const std::string
& attrName
, sint32 position
,
142 const std::string
& key
, CObject
* value
);
144 bool eraseNode(const std::string
& instanceId
, const std::string
& attrName
, sint32 position
);
146 bool moveNode( const std::string
& instanceId1
, const std::string
& attrName1
, int position1
,
147 const std::string
& instanceId2
, const std::string
& attrName2
, int position2
);
151 /// Find a node from the scenario tree by its InstanceId.
152 CObject
*find(const std::string
& instanceId
, const std::string
& attrName
= "", sint32 position
= -1, const std::string
&key
="");
154 /// Get the Edition Data tree
155 CObject
* getHighLevel() const;
157 /// Get the Animation Data tree
158 CObject
* getRtData() const;
160 /*! return the maxId used by a specific user
161 * /param eid the id of the pioneer
162 * /return The max InstanceId used by this user
164 sint32
getMaxId(const std::string
& eid
);
166 void setMaxId(const std::string
& eid
, sint32 range
);
170 uint32
getMode() const { return _Mode
; }
172 void setMode(uint32 mode
) { _Mode
= mode
; }
174 bool isEditing() const;
176 bool isRunning() const;
178 bool isWaiting() const;
180 void setSessionType(const TScenarioSessionType
& sessionType
) { _SessionType
= sessionType
; }
182 void registerUserComponent(const NLMISC::CHashKeyMD5
& md5
) { _CUserComponent
.insert(md5
); }
184 void unregisterUserComponent(const NLMISC::CHashKeyMD5
& md5
) { _CUserComponent
.erase(md5
); }
186 uint32
getInitialActIndex() const { return _InitialActIndex
;}
188 void setInitialActIndex(uint32 initialActIndex
) { _InitialActIndex
= initialActIndex
; }
190 void serial( NLMISC::IStream
&f
);
192 void setClean(bool clean
){ _Clean
= clean
; }
193 bool getClean() const { return _Clean
; }
207 CObject
* _BasicBricks
;
211 CInstanceMap
* _InstanceMap
;
212 TScenarioSessionType _SessionType
;
213 uint32 _InitialActIndex
;
217 struct CHashKeyMD5Less
: public std::binary_function
<NLMISC::CHashKeyMD5
, NLMISC::CHashKeyMD5
, bool>
219 bool operator()(const NLMISC::CHashKeyMD5
& x
, const NLMISC::CHashKeyMD5
& y
) const { return x
.operator<(y
); }
223 std::set
<NLMISC::CHashKeyMD5
, CHashKeyMD5Less
> _CUserComponent
;
232 public: //public type
233 enum TComponentType
{Compressed
, Dev
} ;
235 public://public functions
238 CUserComponent(const std::string
&filename
,
239 uint8
* uncompressedData
, uint32 uncompressedDataLength
,
240 uint8
* compressedData
= 0, uint32 compressedDataLength
= 0
247 void serial(NLMISC::IStream
&f
);
249 uint8
* getUncompressedData() const;
251 uint32
getUncompressedDataLength() const;
253 void setType(TComponentType type
) { ComponentType
= type
; }
255 TComponentType
GetComponentType() const { return ComponentType
; }
257 std::string
getFilename() const { return Filename
; }
260 public: //public value
261 NLMISC::CHashKeyMD5 Md5
;
262 NLMISC::CHashKeyMD5 Md5Id
;
264 TComponentType ComponentType
;
265 std::string Filename
;
267 std::string Description
;
268 uint8
* UncompressedData
; //uncompressed
269 uint32 UncompressedDataLength
;
270 uint8
* CompressedData
;
271 uint32 CompressedDataLength
;
279 std::string
get(const std::string
& emoteId
) const;
285 mutable std::map
<std::string
, std::string
> _EmotesMap
;
290 class CScenarioValidatorLoadSuccededCallback
;
292 class CScenarioValidator
295 typedef std::vector
< std::pair
<std::string
, std::string
> > TValues
;
298 static std::string AutoSaveSignature
;
302 CScenarioValidator(CScenarioValidatorLoadSuccededCallback
* loadCb
= 0 );
303 ~CScenarioValidator();
304 bool setScenarioToSave(const std::string
& filename
, CObject
* scenario
, const CScenarioValidator::TValues
& value
, std::string
& md5
);
305 bool setScenarioToLoad(const std::string
& filename
, CScenarioValidator::TValues
& values
, std::string
& md5
, std::string
& signature
, bool checkMD5
);
307 bool applySave(const std::string
& signature
);
308 void applyLoad(std::string
& filename
, std::string
& body
, CScenarioValidator::TValues
& values
);
309 std::string
getBodyMd5() const { return _BodyMd5
; }
312 std::string _HeaderBody
;
313 std::string _ScenarioBody
;
314 std::string _HeaderMd5
;
315 std::string _Filename
;
316 std::string _BodyMd5
;
317 CScenarioValidatorLoadSuccededCallback
* _LoadCb
;
322 // Verify that a scenario is not alterated by user
324 class CScenarioValidatorLoadSuccededCallback
327 virtual ~CScenarioValidatorLoadSuccededCallback(){}
328 virtual void doOperation(const std::string
& filename
, const std::string
& body
, const CScenarioValidator::TValues
& values
) = 0;
333 class CUserComponentValidatorLoadSuccededCallback
;
335 class CUserComponentValidator
338 typedef std::vector
< std::pair
<std::string
, std::string
> > TValues
;
341 static std::string AutoSaveSignature
;
345 CUserComponentValidator(CUserComponentValidatorLoadSuccededCallback
* loadCb
= 0 );
346 ~CUserComponentValidator();
347 bool setUserComponentToSave(const std::string
& filename
, const CUserComponentValidator::TValues
& value
, std::string
& md5
, const std::string
&body
);
348 bool setUserComponentToLoad(const std::string
& filename
, CUserComponentValidator::TValues
& values
, std::string
& md5
, std::string
& signature
, bool checkMD5
);
350 bool applySave(const std::string
& signature
);
351 void applyLoad(std::string
& filename
, std::string
& body
, CScenarioValidator::TValues
& values
);
352 std::string
getBodyMd5() const { return _BodyMd5
; }
354 std::string
getFilename() const{ return _Filename
;}
357 std::string _HeaderBody
;
358 std::string _UserComponentBody
;
359 std::string _HeaderMd5
;
360 std::string _Filename
;
361 std::string _BodyMd5
;
362 CUserComponentValidatorLoadSuccededCallback
* _LoadCb
;
367 class CUserComponentValidatorLoadSuccededCallback
370 virtual ~CUserComponentValidatorLoadSuccededCallback(){}
371 virtual void doOperation(const std::string
& filename
, const std::string
& body
, const CUserComponentValidator::TValues
& values
) = 0;
377 #endif //R2_SCENARIO_H