/src/ogre/Components/Terrain/include/OgreTerrainGroup.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | |
29 | | #ifndef __Ogre_TerrainGroup_H__ |
30 | | #define __Ogre_TerrainGroup_H__ |
31 | | |
32 | | #include "OgreTerrainPrerequisites.h" |
33 | | #include "OgreTerrain.h" |
34 | | #include "OgreWorkQueue.h" |
35 | | #include "OgreIteratorWrapper.h" |
36 | | #include "OgreConfigFile.h" |
37 | | |
38 | | namespace Ogre |
39 | | { |
40 | | class TerrainAutoUpdateLod; |
41 | | |
42 | | /** \addtogroup Optional |
43 | | * @{ |
44 | | */ |
45 | | /** \addtogroup Terrain |
46 | | * Some details on the terrain component |
47 | | * @{ |
48 | | */ |
49 | | |
50 | | /** Helper class to assist you in managing multiple terrain instances |
51 | | that are connected to each other. |
52 | | |
53 | | This class makes it easy to specify the same options for a group of |
54 | | terrain instances and have them positioned relative to each other and |
55 | | associated via each other's neighbour connections. You can do all this |
56 | | manually but this class just makes things easier, so that you only |
57 | | have to specify most options once. |
58 | | @par |
59 | | Terrains are maintained in a grid of entries, and for simplicity |
60 | | the grid cells are indexed from 0 as a 'centre' slot, supporting both |
61 | | positive and negative values. so (0,0) is the centre slot, (1,0) is the |
62 | | slot to the right of the centre, (1,0) is the slot above the centre, (-2,1) |
63 | | is the slot two to the left of the centre and one up, etc. The maximum |
64 | | extent of each axis is -32768 to +32767, so in other words enough for |
65 | | over 4 billion entries. That should be enough for anyone! |
66 | | @par |
67 | | Note that this is not a 'paging' class as such. It's simply a way to make it easier to |
68 | | perform common tasks with multiple terrain instances, which you choose when |
69 | | to define, load and remove. Automatic paging is handled separately by the Paging |
70 | | component. |
71 | | */ |
72 | | class _OgreTerrainExport TerrainGroup |
73 | | { |
74 | | public: |
75 | | /** Constructor. |
76 | | @param sm The SceneManager which will parent the terrain instances. |
77 | | @param align The alignment that all terrain instances will use |
78 | | @param terrainSize The size of each terrain down one edge in vertices (2^n+1) |
79 | | @param terrainWorldSize The world size of each terrain instance |
80 | | */ |
81 | | TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize, |
82 | | Real terrainWorldSize); |
83 | | /** Alternate constructor. |
84 | | |
85 | | You can ONLY use this constructor if you subsequently call loadGroupDefinition |
86 | | or loadLegacyTerrain to populate the rest. |
87 | | */ |
88 | | TerrainGroup(SceneManager* sm); |
89 | | virtual ~TerrainGroup(); |
90 | | |
91 | | /** Retrieve a shared structure which will provide the base settings for |
92 | | all terrains created via this group. |
93 | | |
94 | | All neighbouring terrains should have the same basic settings (particularly |
95 | | the size parameters) - to avoid having to set the terrain import information |
96 | | more than once, you can retrieve the standard settings for this group |
97 | | here and modify them to your needs. Once you've done that you can |
98 | | use the shortcut methods in this class to create new terrain instances |
99 | | using these base settings (plus any per-instance settings you might |
100 | | want to use). |
101 | | @note |
102 | | The structure returned from this method is intended for in-place modification, |
103 | | that's why it is not const and there is no equivalent 'set' method. |
104 | | You should not, however, change the alignment or any of the size parameters |
105 | | after you start constructing instances, since neighbouring terrains |
106 | | should have the same size & alignment. |
107 | | */ |
108 | 0 | virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; } |
109 | | |
110 | | /** Define the centre position of the grid of terrain. |
111 | | */ |
112 | | virtual void setOrigin(const Vector3& pos); |
113 | | |
114 | | /** Retrieve the centre position of the grid of terrain. |
115 | | */ |
116 | 0 | virtual const Vector3& getOrigin() const { return mOrigin; } |
117 | | |
118 | | /** Retrieve the alignment of the grid of terrain (cannot be modified after construction). |
119 | | */ |
120 | 0 | virtual Terrain::Alignment getAlignment() const { return mAlignment; } |
121 | | |
122 | | /** Retrieve the world size of each terrain instance |
123 | | */ |
124 | 0 | virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; } |
125 | | /** Set the world size of terrain. |
126 | | @note This will cause the terrains to change position due to their size change |
127 | | @param newWorldSize the new world size of each terrain instance |
128 | | */ |
129 | | virtual void setTerrainWorldSize(Real newWorldSize); |
130 | | /** Retrieve the size of each terrain instance in number of vertices down one side |
131 | | */ |
132 | 0 | virtual uint16 getTerrainSize() const { return mTerrainSize; } |
133 | | /** Set the size of each terrain instance in number of vertices down one side. |
134 | | @note This will cause the height data in each nested terrain to be bilinear |
135 | | filtered to fit the new data size. |
136 | | @param newTerrainSize the new map size of each terrain instance |
137 | | */ |
138 | | virtual void setTerrainSize(uint16 newTerrainSize); |
139 | | /** Retrieve the SceneManager being used for this group. |
140 | | */ |
141 | 0 | virtual SceneManager* getSceneManager() const { return mSceneManager; } |
142 | | |
143 | | /** Set the naming convention for file names in this terrain group. |
144 | | |
145 | | You can more easily generate file names for saved / loaded terrain slots |
146 | | if you define a naming prefix. When you call saveAllTerrains(), all the |
147 | | terrain instances currently loaded will be saved to a file named |
148 | | <prefix>_<index>.<extension>, where <index> is |
149 | | given by packing the x and y coordinates of the entry into a 32-bit |
150 | | index (@see packIndex). |
151 | | */ |
152 | | void setFilenameConvention(const String& prefix, const String& extension); |
153 | | /// @see setFilenameConvention |
154 | | void setFilenamePrefix(const String& prefix); |
155 | | /// @see setFilenameConvention |
156 | | void setFilenameExtension(const String& extension); |
157 | | /// @see setFilenameConvention |
158 | 0 | const String& getFilenamePrefix() const { return mFilenamePrefix; } |
159 | | /// @see setFilenameConvention |
160 | 0 | const String& getFilenameExtension() const { return mFilenameExtension; } |
161 | | |
162 | | /** Set the resource group in which files will be located. */ |
163 | 0 | void setResourceGroup(const String& grp) { mResourceGroup = grp; } |
164 | | /** Get the resource group in which files will be located. */ |
165 | 0 | const String& getResourceGroup() const { return mResourceGroup; } |
166 | | /** Define a 'slot' in the terrain grid - in this case to be loaded from |
167 | | a generated file name. |
168 | | |
169 | | At this stage the terrain instance isn't actually present in the grid, |
170 | | you're merely expressing an intention for it to take its place there |
171 | | once it's loaded. The reason we do it like this is to support |
172 | | background preparation of this terrain instance. |
173 | | @note This method assumes that you want a file name to be generated from |
174 | | the naming convention that you have supplied (@see setFilenameConvention). |
175 | | If a file of that name isn't found during loading, then a flat terrain is |
176 | | created instead at height 0. |
177 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
178 | | */ |
179 | | virtual void defineTerrain(long x, long y); |
180 | | |
181 | | /** Define a 'slot' in the terrain grid - in this case a flat terrain. |
182 | | |
183 | | At this stage the terrain instance isn't actually present in the grid, |
184 | | you're merely expressing an intention for it to take its place there |
185 | | once it's loaded. The reason we do it like this is to support |
186 | | background preparation of this terrain instance. |
187 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
188 | | @param constantHeight The constant, uniform height that you want the terrain |
189 | | to start at |
190 | | */ |
191 | | virtual void defineTerrain(long x, long y, float constantHeight); |
192 | | |
193 | | /** Define the content of a 'slot' in the terrain grid. |
194 | | |
195 | | At this stage the terrain instance isn't actually present in the grid, |
196 | | you're merely expressing an intention for it to take its place there |
197 | | once it's loaded. The reason we do it like this is to support |
198 | | background preparation of this terrain instance. |
199 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
200 | | @param importData Import data - this data is copied during the |
201 | | call so you may destroy your copy afterwards. |
202 | | */ |
203 | | virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData); |
204 | | |
205 | | /** Define the content of a 'slot' in the terrain grid. |
206 | | |
207 | | At this stage the terrain instance isn't actually present in the grid, |
208 | | you're merely expressing an intention for it to take its place there |
209 | | once it's loaded. The reason we do it like this is to support |
210 | | background preparation of this terrain instance. |
211 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
212 | | @param img Heightfield image - this data is copied during the call so you may destroy your copy afterwards. |
213 | | @param layers Optional texture layers to use (if not supplied, default import |
214 | | data layers will be used) - this data is copied during the |
215 | | call so you may destroy your copy afterwards. |
216 | | */ |
217 | | virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0); |
218 | | |
219 | | /** Define the content of a 'slot' in the terrain grid. |
220 | | |
221 | | At this stage the terrain instance isn't actually present in the grid, |
222 | | you're merely expressing an intention for it to take its place there |
223 | | once it's loaded. The reason we do it like this is to support |
224 | | background preparation of this terrain instance. |
225 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
226 | | @param pFloat Heights array |
227 | | @param layers Optional texture layers to use (if not supplied, default import |
228 | | data layers will be used) - this data is copied during the |
229 | | call so you may destroy your copy afterwards. |
230 | | */ |
231 | | virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0); |
232 | | |
233 | | /** Define the content of a 'slot' in the terrain grid. |
234 | | |
235 | | At this stage the terrain instance isn't actually present in the grid, |
236 | | you're merely expressing an intention for it to take its place there |
237 | | once it's loaded. The reason we do it like this is to support |
238 | | background preparation of this terrain instance. |
239 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
240 | | @param filename The name of a file which fully defines the terrain (as |
241 | | written by Terrain::save). Size settings from all files must agree. |
242 | | */ |
243 | | virtual void defineTerrain(long x, long y, const String& filename); |
244 | | |
245 | | |
246 | | /** Load any terrain instances that have been defined but not loaded yet. |
247 | | @param synchronous Whether we should force this to happen entirely in the |
248 | | primary thread |
249 | | */ |
250 | | virtual void loadAllTerrains(bool synchronous = false); |
251 | | |
252 | | /** Load a specific terrain slot based on the definition that has already |
253 | | been supplied. |
254 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
255 | | @copydetails loadAllTerrains |
256 | | */ |
257 | | virtual void loadTerrain(long x, long y, bool synchronous = false); |
258 | | |
259 | | /** Load a terrain.cfg as used by the terrain scene manager into a single terrain slot |
260 | | * |
261 | | * automatically configures the SM2Profile if it is used. |
262 | | * @attention not all of the legacy parameters/ parameter combinations are supported |
263 | | * @param cfgFilename .cfg file that specifices what textures/scale/mipmaps/etc to use. |
264 | | * @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
265 | | * @copydetails loadAllTerrains |
266 | | */ |
267 | | void loadLegacyTerrain(const String& cfgFilename, long x = 0, long y = 0, bool synchronous = true); |
268 | | |
269 | | /// @overload |
270 | | void loadLegacyTerrain(const ConfigFile& cfg, long x = 0, long y = 0, bool synchronous = true); |
271 | | |
272 | | /** Unload a specific terrain slot. |
273 | | |
274 | | This destroys the Terrain instance but retains the slot definition (so |
275 | | it would be reloaded next time you call loadAllTerrains() if you did not |
276 | | remove it beforehand). |
277 | | @note |
278 | | While the definition of the terrain is kept, if you used import data |
279 | | to populate it, this will have been lost so repeat loading cannot occur. |
280 | | The only way to support repeat loading is via the 'filename' option of |
281 | | defineTerrain instead. |
282 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
283 | | */ |
284 | | virtual void unloadTerrain(long x, long y); |
285 | | |
286 | | /** Remove a specific terrain slot. |
287 | | |
288 | | This destroys any Terrain instance at this position and also removes the |
289 | | definition, so it essentially no longer exists. |
290 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
291 | | */ |
292 | | virtual void removeTerrain(long x, long y); |
293 | | |
294 | | /** Remove all terrain instances. |
295 | | */ |
296 | | void removeAllTerrains(); |
297 | | |
298 | | /** Save all terrain instances using the assigned file names, or |
299 | | via the filename convention. |
300 | | @see setFilenameConvention |
301 | | @see setResourceGroup |
302 | | @param onlyIfModified If true, only terrains that have been modified since load(), |
303 | | or since the last save(), will be saved. You want to set this to true if |
304 | | you loaded the terrain from these same files, but false if you |
305 | | defined them using some other input data since the files wouldn't exist. |
306 | | @param replaceManualFilenames If true, replaces any manually defined filenames |
307 | | in the TerrainSlotDefinition with the generated names from the convention. |
308 | | This is recommended since it makes everything more consistent, although |
309 | | you might want to use manual filenames in the original definition to import |
310 | | previously separate data. |
311 | | */ |
312 | | void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true); |
313 | | |
314 | | /** Definition of how to populate a 'slot' in the terrain group. |
315 | | */ |
316 | | struct _OgreTerrainExport TerrainSlotDefinition |
317 | | { |
318 | | /// Filename, if this is to be loaded from a file |
319 | | String filename; |
320 | | /// Import data, if this is to be defined based on importing |
321 | | Terrain::ImportData* importData; |
322 | | |
323 | 0 | TerrainSlotDefinition() :importData(0) {} |
324 | | ~TerrainSlotDefinition(); |
325 | | |
326 | | /// Set to use import data |
327 | | void useImportData(); |
328 | | /// Set to use file name |
329 | | void useFilename(); |
330 | | /// Destroy temp import resources |
331 | | void freeImportData(); |
332 | | }; |
333 | | |
334 | | /** Slot for a terrain instance, together with its definition. */ |
335 | | struct _OgreTerrainExport TerrainSlot : public TerrainAlloc |
336 | | { |
337 | | /// The coordinates of the terrain slot relative to the centre slot (signed). |
338 | | long x, y; |
339 | | /// Definition used to load the terrain |
340 | | TerrainSlotDefinition def; |
341 | | /// Actual terrain instance |
342 | | Terrain* instance; |
343 | | |
344 | 0 | TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {} |
345 | | virtual ~TerrainSlot(); |
346 | | void freeInstance(); |
347 | | }; |
348 | | |
349 | | /** Get the definition of a slot in the terrain. |
350 | | |
351 | | Definitions exist before the actual instances to allow background loading. |
352 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
353 | | @return The definition, or null if nothing is in this slot. While this return value is |
354 | | not const, you should be careful about modifying it; it will have no effect unless you load |
355 | | the terrain afterwards, and can cause a race condition if you modify it while a background |
356 | | load is in progress. |
357 | | */ |
358 | | virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const; |
359 | | |
360 | | /** Get the terrain instance at a given slot, if loaded. |
361 | | @param x, y The coordinates of the terrain slot relative to the centre slot (signed). |
362 | | @return The terrain, or null if no terrain is loaded in this slot (call getTerrainDefinition if |
363 | | you want to access the definition before it is loaded). |
364 | | */ |
365 | | virtual Terrain* getTerrain(long x, long y) const; |
366 | | |
367 | | /** Free as many resources as possible for optimal run-time memory use for all |
368 | | terrain tiles. |
369 | | @see Terrain::freeTemporaryResources |
370 | | */ |
371 | | void freeTemporaryResources(); |
372 | | |
373 | | /** Trigger the update process for all terrain instances. |
374 | | @see Terrain::update |
375 | | */ |
376 | | void update(bool synchronous = false); |
377 | | |
378 | | /** Performs an update on all terrain geometry. |
379 | | @see Terrain::updateGeometry |
380 | | */ |
381 | | void updateGeometry(); |
382 | | |
383 | | /** Updates derived data for all terrains (LOD, lighting) to reflect changed height data. |
384 | | @see Terrain::updateDerivedData |
385 | | */ |
386 | | void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF); |
387 | | |
388 | | /** Result from a terrain ray intersection with the terrain group. |
389 | | */ |
390 | | struct _OgreTerrainExport RayResult |
391 | | { |
392 | | /// Whether an intersection occurred |
393 | | bool hit; |
394 | | /// Which terrain instance was hit, if any |
395 | | Terrain* terrain; |
396 | | /// Position at which the intersection occurred |
397 | | Vector3 position; |
398 | | |
399 | | RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos) |
400 | 0 | : hit(_hit), terrain(_terrain), position(_pos) {} |
401 | | }; |
402 | | |
403 | | /** Get the height data for a given world position (projecting the point |
404 | | down on to the terrain underneath). |
405 | | @param x, y,z Position in world space. Positions will be clamped to the edge |
406 | | of the terrain |
407 | | @param ppTerrain Pointer to a pointer to a terrain which will be completed |
408 | | with the terrain that was found to resolve this query, or null if none were |
409 | | */ |
410 | | float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0); |
411 | | |
412 | | /** Get the height data for a given world position (projecting the point |
413 | | down on to the terrain). |
414 | | @param pos Position in world space. Positions will be clamped to the edge |
415 | | of the terrain |
416 | | @param ppTerrain Pointer to a pointer to a terrain which will be completed |
417 | | with the terrain that was found to resolve this query, or null if none were |
418 | | */ |
419 | | float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0); |
420 | | |
421 | | /** Test for intersection of a given ray with any terrain in the group. If the ray hits |
422 | | a terrain, the point of intersection and terrain instance is returned. |
423 | | @param ray The ray to test for intersection |
424 | | @param distanceLimit The distance from the ray origin at which we will stop looking, |
425 | | 0 indicates no limit |
426 | | @return A result structure which contains whether the ray hit a terrain and if so, where. |
427 | | @remarks This can be called from any thread as long as no parallel write to |
428 | | the terrain data occurs. |
429 | | */ |
430 | | RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const; |
431 | | |
432 | | typedef std::vector<Terrain*> TerrainList; |
433 | | /** Test intersection of a box with the terrain. |
434 | | |
435 | | Tests an AABB for overlap with a terrain bounding box. Note that this does not mean that the box |
436 | | touches the terrain itself, just the bounding box for the terrain. You can use this to get region |
437 | | results for further testing or use (e.g. painting areas). |
438 | | @param box The AABB you want to test in world units |
439 | | @param resultList Pointer to a list of terrain pointers which will be updated to include just |
440 | | the terrains that overlap |
441 | | */ |
442 | | void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const; |
443 | | /** Test intersection of a sphere with the terrain. |
444 | | |
445 | | Tests a sphere for overlap with a terrain bounding box. Note that this does not mean that the sphere |
446 | | touches the terrain itself, just the bounding box for the terrain. You can use this to get region |
447 | | results for further testing or use (e.g. painting areas). |
448 | | @param sphere The sphere you want to test in world units |
449 | | @param resultList Pointer to a list of terrain pointers which will be updated to include just |
450 | | the terrains that overlap |
451 | | */ |
452 | | void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const; |
453 | | |
454 | | /** Convert a world position to terrain slot coordinates. |
455 | | @param pos The world position |
456 | | @param x,y Pointers to the coordinates to be completed. |
457 | | */ |
458 | | void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const; |
459 | | |
460 | | /** Convert a slot location to a world position at the centre |
461 | | @param x,y The slot coordinates |
462 | | @param pos Pointer to the world position to be completed |
463 | | */ |
464 | | void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const; |
465 | | |
466 | | /** Calls Terrain::isDerivedDataUpdateInProgress on each loaded instance and returns true |
467 | | if any of them are undergoing a derived update. |
468 | | */ |
469 | | bool isDerivedDataUpdateInProgress() const; |
470 | | |
471 | | /// Packed map, signed 16 bits for each axis from -32767 to +32767 |
472 | | typedef std::map<uint32, TerrainSlot*> TerrainSlotMap; |
473 | | typedef MapIterator<TerrainSlotMap> TerrainIterator; |
474 | | typedef ConstMapIterator<TerrainSlotMap> ConstTerrainIterator; |
475 | | |
476 | | /// @deprecated use getTerrainSlots() |
477 | | OGRE_DEPRECATED TerrainIterator getTerrainIterator(); |
478 | | /// @deprecated use getTerrainSlots() |
479 | | OGRE_DEPRECATED ConstTerrainIterator getTerrainIterator() const; |
480 | | |
481 | | /// Get the defined terrains |
482 | 0 | const TerrainSlotMap& getTerrainSlots() const { return mTerrainSlots; } |
483 | | |
484 | | /// Convert coordinates to a packed integer index |
485 | | uint32 packIndex(long x, long y) const; |
486 | | |
487 | | /// Convert a packed integer index to coordinates |
488 | | void unpackIndex(uint32 key, long *x, long *y); |
489 | | |
490 | | /// Generate a file name based on the current naming convention |
491 | | String generateFilename(long x, long y) const; |
492 | | |
493 | | /** Save the group data only in native form to a file. |
494 | | */ |
495 | | void saveGroupDefinition(const String& filename); |
496 | | /** Save the group data only in native form to a serializing stream. |
497 | | */ |
498 | | void saveGroupDefinition(StreamSerialiser& stream); |
499 | | /** Load the group definition only in native form from a file. |
500 | | */ |
501 | | void loadGroupDefinition(const String& filename); |
502 | | /** Load the group definition only in native form from a serializing stream. |
503 | | */ |
504 | | void loadGroupDefinition(StreamSerialiser& stream); |
505 | | |
506 | | static const uint32 CHUNK_ID; |
507 | | static const uint16 CHUNK_VERSION; |
508 | | |
509 | | /// Loads terrain's next LOD level. |
510 | | void increaseLodLevel(long x, long y, bool synchronous = false); |
511 | | /// Removes terrain's highest LOD level. |
512 | | void decreaseLodLevel(long x, long y); |
513 | | |
514 | | void setAutoUpdateLod(TerrainAutoUpdateLod* updater); |
515 | | /// Automatically checks if terrain's LOD level needs to be updated. |
516 | | void autoUpdateLod(long x, long y, bool synchronous, const Any &data); |
517 | | void autoUpdateLodAll(bool synchronous, const Any &data); |
518 | | |
519 | | /** Get the number of terrains that are still waiting for the Terrain::prepare() to be called. |
520 | | * |
521 | | * @note Terrain::prepare() happens in background thread so the actual call will be completed |
522 | | * a bit before this returns the reduced number. |
523 | | * |
524 | | * @return Amount of terrain prepare requests pending. |
525 | | */ |
526 | | size_t getNumTerrainPrepareRequests() const; |
527 | | |
528 | | private: |
529 | | typedef std::map<TerrainSlot*, WorkQueue::RequestID> TerrainPrepareRequestMap; |
530 | | SceneManager *mSceneManager; |
531 | | Terrain::Alignment mAlignment; |
532 | | uint16 mTerrainSize; |
533 | | Real mTerrainWorldSize; |
534 | | Terrain::ImportData mDefaultImportData; |
535 | | Vector3 mOrigin; |
536 | | TerrainSlotMap mTerrainSlots; |
537 | | TerrainPrepareRequestMap mTerrainPrepareRequests; |
538 | | String mFilenamePrefix; |
539 | | String mFilenameExtension; |
540 | | String mResourceGroup; |
541 | | TerrainAutoUpdateLod *mAutoUpdateLod; |
542 | | Terrain::DefaultGpuBufferAllocator mBufferAllocator; |
543 | | |
544 | | /// Get the position of a terrain instance |
545 | | Vector3 getTerrainSlotPosition(long x, long y); |
546 | | /// Retrieve a slot, potentially allocate one |
547 | | TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing); |
548 | | TerrainSlot* getTerrainSlot(long x, long y) const; |
549 | | void freeTerrainSlotInstance(TerrainSlot* slot); |
550 | | void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety); |
551 | | |
552 | | void loadTerrainImpl(TerrainSlot* slot, bool synchronous); |
553 | | |
554 | | /// WorkQueue::RequestHandler override |
555 | | WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ); |
556 | | /// WorkQueue::ResponseHandler override |
557 | | void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ); |
558 | | |
559 | | }; |
560 | | |
561 | | |
562 | | /** @} */ |
563 | | /** @} */ |
564 | | |
565 | | } |
566 | | |
567 | | #endif |
568 | | |