Add infos into target window
[ryzomcore.git] / ryzom / client / src / scene_parser.h
blob706c5996594bff0a569186b4ebc176d1f9ecb95d
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/>.
20 #ifndef CL_SCENE_PARSER_H
21 #define CL_SCENE_PARSER_H
24 /////////////
25 // INCLUDE //
26 /////////////
27 // Misc
28 #include "nel/misc/types_nl.h"
29 #include "nel/misc/vector.h"
30 #include "nel/misc/quat.h"
31 // 3D Interface.
32 #include "nel/3d/u_animation_set.h"
33 #include "nel/3d/u_play_list_manager.h"
34 #include "nel/3d/u_play_list.h"
35 #include "nel/3d/u_instance_group.h"
36 // Std.
37 #include <string>
38 #include <fstream>
39 #include <list>
40 #include <vector>
41 #include <map>
42 #include <set>
45 ///////////
46 // USING //
47 ///////////
48 using NLMISC::CVector;
49 using NLMISC::CQuat;
50 using NL3D::UPlayListManager;
51 using NL3D::UAnimationSet;
52 using NL3D::UAnimation;
53 using NL3D::UPlayList;
54 using NL3D::UInstanceGroup;
55 /*using std::string;
56 using std::ifstream;
57 using std::list;
58 using std::vector;
59 using std::map;
60 using std::set;
61 using std::pair;*/
64 ///////////
65 // CLASS //
66 ///////////
67 /**
68 * Class to parse a scene.
69 * \author Guillaume PUZIN
70 * \author Nevrax France
71 * \date 2001
73 class CSceneParser
75 private:
76 static const uint MAX_LINE_SIZE;
77 static const char *delimiter;
79 /// Parse the file.
80 void parse(ifstream &file);
82 /// Skip empty lines and comment lines.
83 void getNextValidLine(ifstream &file, char *buff);
85 /// Day/Night.
86 void parseTime();
87 /// Parse the list of IG to load for the scene.
88 void parseIG(ifstream &file, char *buff);
89 /// Get the name of the IG to initialize entities.
90 void parseIGInit();
92 /// Parse Particle.
93 void parseParticle(ifstream &file, char *buff);
94 /// Parse Particle's Id.
95 void parseParticleId();
96 /// Parse Particle's IG.
97 void parseParticleIG();
98 /// Parse Particle's Cluster
99 void parseParticleCluster();
100 /// Parse Particle's Actor.
101 void parseParticleActor();
102 /// Parse Particle's anims.
103 void parseParticleAnims(ifstream &file, char *buff);
105 /// Parse an actor.
106 void parseActor(ifstream &file, char *buff);
107 /// Parse the current actor Id.
108 void parseId();
109 /// Parse the current actor Name.
110 void parseName();
111 /// Is the Actor a flyer.
112 void parseFly();
113 /// Parse Actor's Actor.
114 void parseActorActor();
115 /// Parse the current actor Skeleton Name.
116 void parseSkel();
117 /// Parse meshes used for the current actor.
118 void parseMeshes(ifstream &file, char *buff);
119 /// Parse anims used for the current actor.
120 void parseAnims(ifstream &file, char *buff);
122 /// Parse all anims used for the camera in all sequence.
123 void parseCamAnims(ifstream &file, char *buff);
125 /// Parse a sequence.
126 void parseSequence(ifstream &file, char *buff);
127 /// Parse the current sequence Id.
128 void parseSeqId();
129 /// Parse particle in the sequence.
130 void parseSeqParticle(ifstream &file, char *buff);
131 /// Parse the current particle's Id in the current sequence.
132 void parseSeqParticleId();
133 /// Parse anims used for the current particle in the current sequence.
134 void parseSeqParticleAnims(ifstream &file, char *buff);
135 /// Parse an actor in a sequence.
136 void parseSeqActor(ifstream &file, char *buff);
137 /// Parse the current actor's Id in the current sequence.
138 void parseSeqActorId();
139 /// Parse anims used for the current actor in the current sequence.
140 void parseSeqActorAnims(ifstream &file, char *buff);
141 /// Parse camera in the sequence.
142 void parseSeqCam(ifstream &file, char *buff);
144 /// Initialize Actors Position and rotation .
145 void initActors();
147 /// Reset the scene.
148 void reset();
149 /// Reset all particles.
150 void resetParticles();
151 /// Reset all actors.
152 void resetActors();
154 /// Initialize the Camera and reset it the second time.
155 void applyCamera();
156 /// Initialize IG for the scenery (IG present from start to end like trees or torch.
157 void applyIG();
158 /// Initialize the scene with the parameters loaded from the script for particles.
159 void applyParticles();
160 /// Initialize actors.
161 void applyActors();
163 protected:
164 bool _Apply;
165 sint _Line;
166 bool _Day;
167 string _IG_Init;
168 /// List of IG to load for the scene.
169 list<string> _IG;
170 double _TimeStart;
171 double _FrameRate;
173 /// Class to stock parameters for a particle (system).
174 class CParticle
176 public:
177 sint Id;
178 string IG;
179 string Cluster;
180 sint Actor;
181 list<string> Anims;
183 UInstanceGroup *IGPtr;
184 vector<CVector> IGPos;
186 map<string, uint> AnimToId;
187 UAnimationSet *AnimationSet;
188 UPlayList *PlayList;
190 CParticle()
192 AnimationSet = 0;
193 PlayList = 0;
196 void reset()
198 Id = -1;
199 Actor = -1;
200 Anims.clear();
201 AnimationSet = 0;
202 PlayList = 0;
203 AnimToId.clear();
207 /// Class to stock parameters for an actor.
208 class CActor
210 public:
211 sint Id;
212 string Name;
213 bool Fly;
214 string Skeleton;
215 list<string> Meshes;
216 list<string> Anims;
217 CVector Pos;
218 CQuat Rot;
219 sint Actor;
221 void reset()
223 Id = -1;
224 Actor = -1;
225 Fly = false;
226 Meshes.clear();
227 Anims.clear();
231 /// Class to stock parameters for an actor in a sequence.
232 class CParticleSeq
234 public:
235 sint Id;
236 list<string> Anims;
238 void reset()
240 Id = -1;
241 Anims.clear();
245 /// Class to stock parameters for an actor in a sequence.
246 class CActorSeq
248 public:
249 sint Id;
250 list<string> Anims;
252 void reset()
254 Id = -1;
255 Anims.clear();
259 /// Class to stock parameters for a sequence.
260 class CSequence
262 public:
263 sint Id;
264 map<uint, CParticleSeq> ParticlesSeq;
265 map<uint, CActorSeq> ActorsSeq;
266 list<string> CamAnims;
268 void reset()
270 Id = -1;
271 ActorsSeq.clear();
275 /// ...
276 list<string> _CamAnims;
277 /// Particle with the parse in progress.
278 CParticle _CurrentParticle;
279 /// All particles in the scene.
280 map<uint, CParticle> _Particles;
281 /// Actor with the parse in progress.
282 CActor _CurrentActor;
283 /// All actors in the scene.
284 map<uint, CActor> _Actors;
285 /// ...
286 CParticleSeq _CurParticleSeq;
287 /// ...
288 CActorSeq _CurrentActorSeq;
289 /// ...
290 CSequence _CurrentSequence;
291 /// All Sequences in the scene.
292 map<uint, CSequence> _Sequences;
294 /// ...
295 UPlayListManager *_PlayListManager;
296 UAnimationSet *_AnimationSet;
297 UPlayList *_PlayList;
298 map<string, uint> _AnimCamToId;
300 set<UInstanceGroup *> _IGInScene;
302 // Scene.
303 typedef list<pair<sint, double> > TScene;
304 TScene _Scene;
305 TScene::iterator _ItScene;
306 double _SceneStart;
309 /// Update the camera (position, target, roll, fov).
310 void updateCamera(double timeInSec);
311 /// Update actor position (for actor on another actor).
312 void updateActors();
313 /// Update particles.
314 void updateParticles(double timeInSec);
315 void updateParticlesNoActor(float difTime, CParticle &particle, UAnimation &animation);
316 void updateParticlesActor(float difTime, CParticle &particle, UAnimation &animation);
318 public:
319 /// Constructor
320 CSceneParser();
322 inline bool Time() {return _Day;}
324 /// Load the file with the scene.
325 void load(const string &filename);
327 /// Initialize the scene with the parameters loaded from the script.
328 void apply();
331 void update(double timeInSec);
333 /// Play the sequence with the ID 'seq'.
334 void playSeq(uint seq, double timeInSec);
336 inline double frameRate() {return _FrameRate;}
337 inline void frameRate(double fr) {_FrameRate = fr;}
339 /** \name SCENE
340 * Functions to manage a scene.
342 //@{
344 * Load a scene from a file and put it in memory.
345 * \param filename : filename for the file that contains the scene.
346 * \warning This function clear the old scene.
348 void loadScene(const string &filename);
350 * Play a scene in memory.
351 * \param timeInSec : current time in second.
353 void playScene(double timeInSec);
355 * Update the scene currently playing.
356 * \param timeInSec : current time in second.
358 void updateScene(double timeInSec);
360 * Stop the scene currently playing.
362 void stopScene();
364 * Function to know if there is a scene currently playing.
365 * \return bool : 'true' if there is a scene currently playing.
367 bool isScenePlaying();
368 //@}
372 #endif // CL_SCENE_PARSER_H
374 /* End of scene_parser.h */