OgreTerrainGroup.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_TerrainGroup_H__
#define __Ogre_TerrainGroup_H__
#include "OgreTerrainPrerequisites.h"
#include "OgreTerrain.h"
#include "OgreWorkQueue.h"
#include "OgreIteratorWrappers.h"
#include "OgreTerrainAutoUpdateLod.h"
namespace Ogre
{
class _OgreTerrainExport TerrainGroup : public WorkQueue::RequestHandler,
public WorkQueue::ResponseHandler, public TerrainAlloc
{
public:
TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize,
Real terrainWorldSize);
TerrainGroup(SceneManager* sm);
virtual ~TerrainGroup();
virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; }
virtual void setOrigin(const Vector3& pos);
virtual const Vector3& getOrigin() const { return mOrigin; }
virtual Terrain::Alignment getAlignment() const { return mAlignment; }
virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; }
virtual void setTerrainWorldSize(Real newWorldSize);
virtual uint16 getTerrainSize() const { return mTerrainSize; }
virtual void setTerrainSize(uint16 newTerrainSize);
virtual SceneManager* getSceneManager() const { return mSceneManager; }
void setFilenameConvention(const String& prefix, const String& extension);
void setFilenamePrefix(const String& prefix);
void setFilenameExtension(const String& extension);
const String& getFilenamePrefix() const { return mFilenamePrefix; }
const String& getFilenameExtension() const { return mFilenameExtension; }
void setResourceGroup(const String& grp) { mResourceGroup = grp; }
const String& getResourceGroup() const { return mResourceGroup; }
virtual void defineTerrain(long x, long y);
virtual void defineTerrain(long x, long y, float constantHeight);
virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
virtual void defineTerrain(long x, long y, const String& filename);
virtual void loadAllTerrains(bool synchronous = false);
virtual void loadTerrain(long x, long y, bool synchronous = false);
virtual void unloadTerrain(long x, long y);
virtual void removeTerrain(long x, long y);
void removeAllTerrains();
void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
struct _OgreTerrainExport TerrainSlotDefinition
{
String filename;
Terrain::ImportData* importData;
TerrainSlotDefinition() :importData(0) {}
~TerrainSlotDefinition();
void useImportData();
void useFilename();
void freeImportData();
};
struct _OgreTerrainExport TerrainSlot : public TerrainAlloc
{
long x, y;
TerrainSlotDefinition def;
Terrain* instance;
TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
virtual ~TerrainSlot();
void freeInstance();
};
virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
virtual Terrain* getTerrain(long x, long y) const;
void freeTemporaryResources();
void update(bool synchronous = false);
void updateGeometry();
void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
struct _OgreTerrainExport RayResult
{
bool hit;
Terrain* terrain;
Vector3 position;
RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
: hit(_hit), terrain(_terrain), position(_pos) {}
};
float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
typedef vector<Terrain*>::type TerrainList;
void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
bool isDerivedDataUpdateInProgress() const;
typedef map<uint32, TerrainSlot*>::type TerrainSlotMap;
typedef MapIterator<TerrainSlotMap> TerrainIterator;
typedef ConstMapIterator<TerrainSlotMap> ConstTerrainIterator;
TerrainIterator getTerrainIterator();
ConstTerrainIterator getTerrainIterator() const;
bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
uint32 packIndex(long x, long y) const;
void unpackIndex(uint32 key, long *x, long *y);
String generateFilename(long x, long y) const;
void saveGroupDefinition(const String& filename);
void saveGroupDefinition(StreamSerialiser& stream);
void loadGroupDefinition(const String& filename);
void loadGroupDefinition(StreamSerialiser& stream);
static const uint16 WORKQUEUE_LOAD_REQUEST;
static const uint32 CHUNK_ID;
static const uint16 CHUNK_VERSION;
void increaseLodLevel(long x, long y, bool synchronous = false);
void decreaseLodLevel(long x, long y);
void setAutoUpdateLod(TerrainAutoUpdateLod* updater);
void autoUpdateLod(long x, long y, bool synchronous, const Any &data);
void autoUpdateLodAll(bool synchronous, const Any &data);
protected:
SceneManager *mSceneManager;
Terrain::Alignment mAlignment;
uint16 mTerrainSize;
Real mTerrainWorldSize;
Terrain::ImportData mDefaultImportData;
Vector3 mOrigin;
TerrainSlotMap mTerrainSlots;
uint16 mWorkQueueChannel;
String mFilenamePrefix;
String mFilenameExtension;
String mResourceGroup;
TerrainAutoUpdateLod *mAutoUpdateLod;
Terrain::DefaultGpuBufferAllocator mBufferAllocator;
Vector3 getTerrainSlotPosition(long x, long y);
TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
TerrainSlot* getTerrainSlot(long x, long y) const;
void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
struct LoadRequest
{
TerrainSlot* slot;
TerrainGroup* origin;
static uint loadingTaskNum;
_OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
{ return o; }
};
};
}
#endif
Ogre::TerrainGroup::mAlignment
Terrain::Alignment mAlignment
Definition: OgreTerrainGroup.h:516
Ogre::TerrainGroup::TerrainSlot::TerrainSlot
TerrainSlot(long _x, long _y)
Definition: OgreTerrainGroup.h:331
OgreWorkQueue.h
Ogre::TerrainGroup::RayResult::position
Vector3 position
Position at which the intersection occurred.
Definition: OgreTerrainGroup.h:384
Ogre::TerrainGroup::TerrainSlot
Slot for a terrain instance, together with its definition.
Definition: OgreTerrainGroup.h:322
Ogre::TerrainGroup::getOrigin
virtual const Vector3 & getOrigin() const
Retrieve the centre position of the grid of terrain.
Definition: OgreTerrainGroup.h:115
Ogre::TerrainGroup::TerrainSlot::y
long y
Definition: OgreTerrainGroup.h:325
Ogre::Terrain::LayerInstanceList
vector< LayerInstance >::type LayerInstanceList
Definition: OgreTerrain.h:308
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
Ogre::TerrainGroup::mTerrainSize
uint16 mTerrainSize
Definition: OgreTerrainGroup.h:517
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::WorkQueue
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:70
Ogre::TerrainGroup::TerrainIterator
MapIterator< TerrainSlotMap > TerrainIterator
Definition: OgreTerrainGroup.h:460
Ogre::TerrainGroup::mResourceGroup
String mResourceGroup
Definition: OgreTerrainGroup.h:525
Ogre::TerrainAutoUpdateLod
Terrain automatic LOD loading.
Definition: OgreTerrainAutoUpdateLod.h:54
Ogre::Sphere
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
Ogre::TerrainGroup::RayResult::hit
bool hit
Whether an intersection occurred.
Definition: OgreTerrainGroup.h:380
Ogre::MapIterator
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:319
Ogre::TerrainGroup::setResourceGroup
void setResourceGroup(const String &grp)
Set the resource group in which files will be located.
Definition: OgreTerrainGroup.h:162
Ogre::ConstMapIterator
Concrete IteratorWrapper for const access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:352
Ogre::TerrainGroup::getDefaultImportSettings
virtual Terrain::ImportData & getDefaultImportSettings()
Retrieve a shared structure which will provide the base settings for all terrains created via this gr...
Definition: OgreTerrainGroup.h:107
OgreTerrainAutoUpdateLod.h
Ogre::TerrainGroup::LoadRequest
Structure for holding the load request.
Definition: OgreTerrainGroup.h:539
Ogre::TerrainGroup::WORKQUEUE_LOAD_REQUEST
static const uint16 WORKQUEUE_LOAD_REQUEST
Definition: OgreTerrainGroup.h:500
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::TerrainGroup::TerrainSlotDefinition::importData
Terrain::ImportData * importData
Import data, if this is to be defined based on importing.
Definition: OgreTerrainGroup.h:308
Ogre::TerrainGroup::mSceneManager
SceneManager * mSceneManager
Definition: OgreTerrainGroup.h:515
Ogre::TerrainGroup::mFilenameExtension
String mFilenameExtension
Definition: OgreTerrainGroup.h:524
Ogre::TerrainGroup::getSceneManager
virtual SceneManager * getSceneManager() const
Retrieve the SceneManager being used for this group.
Definition: OgreTerrainGroup.h:140
Ogre::TerrainGroup::ConstTerrainIterator
ConstMapIterator< TerrainSlotMap > ConstTerrainIterator
Definition: OgreTerrainGroup.h:461
Ogre::TerrainGroup::getFilenameExtension
const String & getFilenameExtension() const
Definition: OgreTerrainGroup.h:159
Ogre::TerrainGroup::getTerrainSize
virtual uint16 getTerrainSize() const
Retrieve the size of each terrain instance in number of vertices down one side.
Definition: OgreTerrainGroup.h:131
Ogre::Any
Variant type that can hold Any other type.
Definition: OgreAny.h:56
Ogre::TerrainGroup::getTerrainWorldSize
virtual Real getTerrainWorldSize() const
Retrieve the world size of each terrain instance.
Definition: OgreTerrainGroup.h:123
Ogre::TerrainGroup::mTerrainWorldSize
Real mTerrainWorldSize
Definition: OgreTerrainGroup.h:518
Ogre::TerrainGroup::LoadRequest::origin
TerrainGroup * origin
Definition: OgreTerrainGroup.h:542
Ogre::TerrainGroup::TerrainSlot::instance
Terrain * instance
Actual terrain instance.
Definition: OgreTerrainGroup.h:329
Ogre::Terrain
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::WorkQueue::Request
General purpose request structure.
Definition: OgreWorkQueue.h:83
Ogre::TerrainGroup::RayResult
Result from a terrain ray intersection with the terrain group.
Definition: OgreTerrainGroup.h:377
Ogre::TerrainGroup::getAlignment
virtual Terrain::Alignment getAlignment() const
Retrieve the alignment of the grid of terrain (cannot be modified after construction).
Definition: OgreTerrainGroup.h:119
Ogre::TerrainGroup
Helper class to assist you in managing multiple terrain instances that are connected to each other...
Definition: OgreTerrainGroup.h:70
Ogre::WorkQueue::Response
General purpose response structure.
Definition: OgreWorkQueue.h:122
Ogre::uint8
unsigned char uint8
Definition: OgrePlatform.h:361
Ogre::TerrainGroup::mBufferAllocator
Terrain::DefaultGpuBufferAllocator mBufferAllocator
Definition: OgreTerrainGroup.h:527
Ogre::TerrainGroup::TerrainSlot::def
TerrainSlotDefinition def
Definition used to load the terrain.
Definition: OgreTerrainGroup.h:327
Ogre::TerrainGroup::CHUNK_VERSION
static const uint16 CHUNK_VERSION
Definition: OgreTerrainGroup.h:502
_OgreTerrainExport
#define _OgreTerrainExport
Definition: OgreTerrainPrerequisites.h:58
Ogre::Terrain::Alignment
Alignment
The alignment of the terrain.
Definition: OgreTerrain.h:311
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::TerrainGroup::mAutoUpdateLod
TerrainAutoUpdateLod * mAutoUpdateLod
Definition: OgreTerrainGroup.h:526
Ogre::TerrainGroup::mFilenamePrefix
String mFilenamePrefix
Definition: OgreTerrainGroup.h:523
Ogre::TerrainGroup::TerrainList
vector< Terrain * >::type TerrainList
Definition: OgreTerrainGroup.h:419
Ogre::TerrainGroup::RayResult::terrain
Terrain * terrain
Which terrain instance was hit, if any.
Definition: OgreTerrainGroup.h:382
Ogre::TerrainGroup::LoadRequest::operator<<
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const LoadRequest &r)
Definition: OgreTerrainGroup.h:544
Ogre::TerrainGroup::mWorkQueueChannel
uint16 mWorkQueueChannel
Definition: OgreTerrainGroup.h:522
Ogre::StreamSerialiser
Utility class providing helper methods for reading / writing structured data held in a DataStream...
Definition: OgreStreamSerialiser.h:66
Ogre::TerrainGroup::RayResult::RayResult
RayResult(bool _hit, Terrain *_terrain, const Vector3 &_pos)
Definition: OgreTerrainGroup.h:386
Ogre::TerrainGroup::TerrainSlotDefinition::filename
String filename
Filename, if this is to be loaded from a file.
Definition: OgreTerrainGroup.h:306
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::Image
Class representing an image file.
Definition: OgreImage.h:61
Ogre::TerrainGroup::TerrainSlotMap
map< uint32, TerrainSlot * >::type TerrainSlotMap
Packed map, signed 16 bits for each axis from -32767 to +32767.
Definition: OgreTerrainGroup.h:459
OgreIteratorWrappers.h
Ogre::WorkQueue::ResponseHandler
Interface definition for a handler of responses.
Definition: OgreWorkQueue.h:196
OgreTerrain.h
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::TerrainGroup::CHUNK_ID
static const uint32 CHUNK_ID
Definition: OgreTerrainGroup.h:501
Ogre::TerrainGroup::getResourceGroup
const String & getResourceGroup() const
Get the resource group in which files will be located.
Definition: OgreTerrainGroup.h:164
Ogre::Terrain::ImportData
Structure encapsulating import data that you may use to bootstrap the terrain without loading from a ...
Definition: OgreTerrain.h:324
Ogre::TerrainGroup::LoadRequest::slot
TerrainSlot * slot
Definition: OgreTerrainGroup.h:541
Ogre::TerrainGroup::TerrainSlotDefinition
Definition of how to populate a &#39;slot&#39; in the terrain group.
Definition: OgreTerrainGroup.h:303
Ogre::TerrainGroup::mOrigin
Vector3 mOrigin
Definition: OgreTerrainGroup.h:520
OgreTerrainPrerequisites.h
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::TerrainGroup::mTerrainSlots
TerrainSlotMap mTerrainSlots
Definition: OgreTerrainGroup.h:521
Ogre::TerrainGroup::mDefaultImportData
Terrain::ImportData mDefaultImportData
Definition: OgreTerrainGroup.h:519
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::TerrainGroup::LoadRequest::loadingTaskNum
static uint loadingTaskNum
Definition: OgreTerrainGroup.h:543
Ogre::Terrain::DefaultGpuBufferAllocator
Standard implementation of a buffer allocator which re-uses buffers.
Definition: OgreTerrain.h:572
Ogre::WorkQueue::RequestHandler
Interface definition for a handler of requests.
Definition: OgreWorkQueue.h:161
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::TerrainGroup::getFilenamePrefix
const String & getFilenamePrefix() const
Definition: OgreTerrainGroup.h:157
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Ray
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
Ogre::TerrainGroup::TerrainSlotDefinition::TerrainSlotDefinition
TerrainSlotDefinition()
Definition: OgreTerrainGroup.h:310

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.