TerrainBlock Class Reference

#include <terrData.h>

Inheritance diagram for TerrainBlock:

Inheritance graph
[legend]
List of all members.

Public Types

 BlockSize = 256
 BlockShift = 8
 LightmapSize = 1024
 LightmapShift = 10
 ChunkSquareWidth = 64
 ChunkSize = 4
 ChunkDownShift = 2
 ChunkShift = BlockShift - ChunkDownShift
 BlockSquareWidth = 256
 SquareMaxPoints = 1024
 BlockMask = 255
 GridMapSize = 0x15555
 FlagMapWidth = 128
 Flags that map is for 2x2 squares.
 FlagMapMask = 127
 MaxMipLevel = 6
 NumBaseTextures = 16
 MaterialGroups = 8
 MaxEmptyRunPairs = 100
 InitMask = BIT(1)
 VisibilityMask = BIT(2)
 TerrainChangedMask = BIT(3)
 EmptyMask = BIT(4)
 MoveMask = BIT(5)
 LightmapUpdate = BIT(0)
 HeightmapUpdate = BIT(1)
 OpacityUpdate = BIT(2)
 EmptyUpdate = BIT(3)
enum  {
  BlockSize = 256,
  BlockShift = 8,
  LightmapSize = 1024,
  LightmapShift = 10,
  ChunkSquareWidth = 64,
  ChunkSize = 4,
  ChunkDownShift = 2,
  ChunkShift = BlockShift - ChunkDownShift,
  BlockSquareWidth = 256,
  SquareMaxPoints = 1024,
  BlockMask = 255,
  GridMapSize = 0x15555,
  FlagMapWidth = 128,
  FlagMapMask = 127,
  MaxMipLevel = 6,
  NumBaseTextures = 16,
  MaterialGroups = 8,
  MaxEmptyRunPairs = 100
}
enum  UpdateMaskBits {
  InitMask = BIT(1),
  VisibilityMask = BIT(2),
  TerrainChangedMask = BIT(3),
  EmptyMask = BIT(4),
  MoveMask = BIT(5)
}
enum  {
  LightmapUpdate = BIT(0),
  HeightmapUpdate = BIT(1),
  OpacityUpdate = BIT(2),
  EmptyUpdate = BIT(3)
}

Public Member Functions

void updateOpacity ()
void addOpacitySources ()
 TerrainBlock ()
 ~TerrainBlock ()
void buildChunkDeviance (S32 x, S32 y)
void buildGridMap ()
U32 getCRC () const
Resource< TerrainFilegetFile () const
bool onAdd ()
 Called when the object is added to the sim.
void onRemove ()
 Called when the object is removed from the sim.
void refreshMaterialLists ()
void onEditorEnable ()
 Called when the editor is activated.
void onEditorDisable ()
 Called when the editor is deactivated.
void rebuildEmptyFlags ()
bool unpackEmptySquares ()
void packEmptySquares ()
void inspectPostApply ()
 Called after any property of the object is changed in the world editor.
MaterialgetMaterial (U32 x, U32 y)
BaseMatInstancegetMaterialInst (U32 x, U32 y)
GridSquarefindSquare (U32 level, const Point2I &pos)
GridSquarefindSquare (U32 level, S32 x, S32 y)
GridChunkfindChunk (const Point2I &pos)
void calcBounds ()
void setHeight (const Point2I &pos, F32 height)
void updateGrid (const Point2I &minPt, const Point2I &maxPt)
void updateGridMaterials (const Point2I &minPt, const Point2I &maxPt)
U16 getHeight (U32 x, U32 y) const
Point2I getGridPos (const Point3F &worldPos)
U16getHeightAddress (U32 x, U32 y)
void setBaseMaterial (U32 x, U32 y, U8 matGroup)
U8getMaterialAlphaMap (U32 matIndex)
U8getBaseMaterialAddress (U32 x, U32 y)
U8 getBaseMaterial (U32 x, U32 y)
U16getFlagMapPtr (S32 x, S32 y)
void getMaterialAlpha (const Point2I &pos, U8 alphas[MaterialGroups]) const
void setMaterialAlpha (const Point2I &pos, const U8 alphas[MaterialGroups])
bool getHeight (const Point2F &pos, F32 *height)
void getMinMaxHeight (F32 *minHeight, F32 *maxHeight) const
bool getNormal (const Point2F &pos, Point3F *normal, bool normalize=true)
bool getNormalAndHeight (const Point2F &pos, Point3F *normal, F32 *height, bool normalize=true)
bool collideBox (const Point3F &start, const Point3F &end, RayInfo *info)
S32 getMaterialAlphaIndex (const String &materialName)
void setFile (Resource< TerrainFile > file)
void createNewTerrainFile (StringTableEntry filename, U16 *hmap=NULL, Vector< StringTableEntry > *materials=NULL)
bool save (const char *filename)
S32 getSquareSize () const
void setSquareSize (S32 squareSize)
bool isTiling () const
void setTiling (bool tiling)
void refillClipmap ()
void buildConvex (const Box3F &box, Convex *convex)
 Builds a convex hull for this object.
bool buildPolyList (AbstractPolyList *polyList, const Box3F &box, const SphereF &sphere)
 Builds a list of polygons which intersect a bounding volume.
bool castRay (const Point3F &start, const Point3F &end, RayInfo *info)
 Casts a ray and obtain collision information, returns true if RayInfo is modified.
bool castRayI (const Point3F &start, const Point3F &end, RayInfo *info, bool emptyCollide)
bool castRayBlock (const Point3F &pStart, const Point3F &pEnd, const Point2I &blockPos, U32 level, F32 invDeltaX, F32 invDeltaY, F32 startT, F32 endT, RayInfo *info, bool)
bool buildMaterialMap ()
void buildMipMap ()
void setBaseMaterials (S32 argc, const char *argv[])
bool loadBaseMaterials ()
bool initMMXBlender ()
void setOverrideMaterial (BaseMatInstance *overrideMaterial)
const FileNamegetDetailTexture () const
void setDetailTexture (const FileName &newValue)
const FileNamegetTerrainFile () const
void setTerrainFile (const FileName &newValue)
String getMaterial (S32 idx)
void setMaterial (S32 idx, const String &newValue)
S32 getMaterialCount () const
void postLight (Vector< TerrainBlock * > &terrBlocks)
 DECLARE_CONOBJECT (TerrainBlock)
U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream)
 Instructs this object to pack its state for transfer over the network.
void unpackUpdate (NetConnection *conn, BitStream *stream)
 Instructs this object to read state data previously packed with packUpdate.

Static Public Member Functions

static void texManagerCallback (GFXTexCallbackCode code, void *userData)
static void flushCache ()
static void initPersistFields ()
 Register dynamic fields in a subclass of ConsoleObject.

Public Attributes

GFXTexHandle baseTextures [NumBaseTextures]
GFXTexHandle mBaseMaterials [MaterialGroups]
GFXTexHandle mAlphaMaterials [MaterialGroups]
Box3F mBounds
GBitmaplightMap
GBitmapmSwizzledLightMap
StringmMaterialFileName
 Array from the file.
S32 mTexCallback
U8mBaseMaterialMap
MaterialmaterialMap
U16heightMap
U16flagMap
FileName mDetailTextureName
GFXTexHandle mDetailTextureHandle
FileName mTerrFileName
Vector< S32mEmptySquareRuns
bool mHasRendered
F32 mDetailDistance
F32 mDetailBrightness
F32 mDetailScale
S32 mVertexBuffer
VectorPtr< GBitmap * > mOpacityMaps
VectorPtr< TerrClipMapImageSource * > mOpacitySources
TerrClipMapImageSourcemLightmapSource
ClipMapBlenderCachemClipBlender
ClipMapmClipMap

Static Public Attributes

static Signal< void(U32, TerrainBlock *,
const Point2I &,const Point2I &)> 
smUpdateSignal

Protected Member Functions

void setTransform (const MatrixF &mat)
 Sets the Object -> World transform.
bool prepRenderImage (SceneState *state, const U32 stateKey, const U32 startZone, const bool modifyBaseZoneState=false)
 Called when the SceneGraph is ready for the registration of RenderImages.
void renderObject (ObjectRenderInst *ri, BaseMatInstance *overrideMat)

Protected Attributes

ObjectRenderInst::RenderDelegate mRenderDelegate

Private Types

typedef SceneObject Parent

Private Attributes

Resource< TerrainFilemFile
GridSquaregridMap [BlockShift+1]
GridChunkmChunkMap
U32 mCRC
BaseMatInstancemTerrainMaterial
S32 mSquareSize
S32 mTexelsPerMeter
S32 mClipMapSizeLog2
bool mTile
S32 mHeightMin
S32 mHeightMax
bool mCollideEmpty

Classes

struct  Material

Member Typedef Documentation

typedef SceneObject TerrainBlock::Parent [private]

Reimplemented from SceneObject.


Member Enumeration Documentation

anonymous enum

Enumerator:
BlockSize 
BlockShift 
LightmapSize 
LightmapShift 
ChunkSquareWidth 
ChunkSize 
ChunkDownShift 
ChunkShift 
BlockSquareWidth 
SquareMaxPoints 
BlockMask 
GridMapSize 
FlagMapWidth  Flags that map is for 2x2 squares.
FlagMapMask 
MaxMipLevel 
NumBaseTextures 
MaterialGroups 
MaxEmptyRunPairs 

Enumerator:
InitMask 
VisibilityMask 
TerrainChangedMask 
EmptyMask 
MoveMask 

anonymous enum

Enumerator:
LightmapUpdate 
HeightmapUpdate 
OpacityUpdate 
EmptyUpdate 


Constructor & Destructor Documentation

TerrainBlock::TerrainBlock (  ) 

TerrainBlock::~TerrainBlock (  ) 


Member Function Documentation

static void TerrainBlock::texManagerCallback ( GFXTexCallbackCode  code,
void userData 
) [static]

void TerrainBlock::updateOpacity (  ) 

void TerrainBlock::addOpacitySources (  ) 

void TerrainBlock::buildChunkDeviance ( S32  x,
S32  y 
)

void TerrainBlock::buildGridMap (  ) 

U32 TerrainBlock::getCRC (  )  const [inline]

Resource<TerrainFile> TerrainBlock::getFile (  )  const [inline]

bool TerrainBlock::onAdd (  )  [virtual]

Called when the object is added to the sim.

Reimplemented from SceneObject.

void TerrainBlock::onRemove (  )  [virtual]

Called when the object is removed from the sim.

Reimplemented from SceneObject.

void TerrainBlock::refreshMaterialLists (  ) 

void TerrainBlock::onEditorEnable (  )  [virtual]

Called when the editor is activated.

Reimplemented from SimObject.

void TerrainBlock::onEditorDisable (  )  [virtual]

Called when the editor is deactivated.

Reimplemented from SimObject.

void TerrainBlock::rebuildEmptyFlags (  ) 

bool TerrainBlock::unpackEmptySquares (  ) 

void TerrainBlock::packEmptySquares (  ) 

void TerrainBlock::inspectPostApply (  )  [virtual]

Called after any property of the object is changed in the world editor.

See also:
inspectPreApply

Reimplemented from SceneObject.

TerrainBlock::Material * TerrainBlock::getMaterial ( U32  x,
U32  y 
) [inline]

BaseMatInstance* TerrainBlock::getMaterialInst ( U32  x,
U32  y 
)

GridSquare * TerrainBlock::findSquare ( U32  level,
const Point2I pos 
) [inline]

GridSquare * TerrainBlock::findSquare ( U32  level,
S32  x,
S32  y 
) [inline]

GridChunk * TerrainBlock::findChunk ( const Point2I pos  )  [inline]

void TerrainBlock::calcBounds (  ) 

void TerrainBlock::setHeight ( const Point2I pos,
F32  height 
)

void TerrainBlock::updateGrid ( const Point2I minPt,
const Point2I maxPt 
)

void TerrainBlock::updateGridMaterials ( const Point2I minPt,
const Point2I maxPt 
)

U16 TerrainBlock::getHeight ( U32  x,
U32  y 
) const

Point2I TerrainBlock::getGridPos ( const Point3F worldPos  ) 

U16* TerrainBlock::getHeightAddress ( U32  x,
U32  y 
) [inline]

void TerrainBlock::setBaseMaterial ( U32  x,
U32  y,
U8  matGroup 
)

U8 * TerrainBlock::getMaterialAlphaMap ( U32  matIndex  )  [inline]

U8 * TerrainBlock::getBaseMaterialAddress ( U32  x,
U32  y 
) [inline]

U8 TerrainBlock::getBaseMaterial ( U32  x,
U32  y 
) [inline]

U16 * TerrainBlock::getFlagMapPtr ( S32  x,
S32  y 
) [inline]

void TerrainBlock::getMaterialAlpha ( const Point2I pos,
U8  alphas[MaterialGroups] 
) const

void TerrainBlock::setMaterialAlpha ( const Point2I pos,
const U8  alphas[MaterialGroups] 
)

bool TerrainBlock::getHeight ( const Point2F pos,
F32 height 
)

void TerrainBlock::getMinMaxHeight ( F32 minHeight,
F32 maxHeight 
) const

bool TerrainBlock::getNormal ( const Point2F pos,
Point3F normal,
bool  normalize = true 
)

bool TerrainBlock::getNormalAndHeight ( const Point2F pos,
Point3F normal,
F32 height,
bool  normalize = true 
)

bool TerrainBlock::collideBox ( const Point3F start,
const Point3F end,
RayInfo info 
) [inline, virtual]

Reimplemented from SceneObject.

S32 TerrainBlock::getMaterialAlphaIndex ( const String materialName  ) 

void TerrainBlock::setFile ( Resource< TerrainFile file  ) 

void TerrainBlock::createNewTerrainFile ( StringTableEntry  filename,
U16 hmap = NULL,
Vector< StringTableEntry > *  materials = NULL 
)

bool TerrainBlock::save ( const char *  filename  ) 

static void TerrainBlock::flushCache (  )  [static]

S32 TerrainBlock::getSquareSize (  )  const [inline]

void TerrainBlock::setSquareSize ( S32  squareSize  )  [inline]

bool TerrainBlock::isTiling (  )  const

void TerrainBlock::setTiling ( bool  tiling  )  [inline]

void TerrainBlock::refillClipmap (  ) 

void TerrainBlock::setTransform ( const MatrixF mat  )  [protected, virtual]

Sets the Object -> World transform.

Parameters:
mat New transform matrix

Reimplemented from SceneObject.

bool TerrainBlock::prepRenderImage ( SceneState state,
const U32  stateKey,
const U32  startZone,
const bool  modifyBaseZoneState = false 
) [protected, virtual]

Called when the SceneGraph is ready for the registration of RenderImages.

See also:
SceneState
Parameters:
state SceneState
stateKey State key of the current SceneState
startZone Base zone index
modifyBaseZoneState If true, the object needs to modify the zone state.

Reimplemented from SceneObject.

void TerrainBlock::renderObject ( ObjectRenderInst ri,
BaseMatInstance overrideMat 
) [protected]

void TerrainBlock::buildConvex ( const Box3F box,
Convex convex 
) [virtual]

Builds a convex hull for this object.

Think of a convex hull as a low-res mesh which covers, as tightly as possible, the object mesh, and is used as a collision mesh.

Parameters:
box 
convex Convex mesh generated (out)

Reimplemented from SceneObject.

bool TerrainBlock::buildPolyList ( AbstractPolyList polyList,
const Box3F box,
const SphereF sphere 
) [virtual]

Builds a list of polygons which intersect a bounding volume.

This will use either the sphere or the box, not both, the SceneObject implimentation ignores sphere.

See also:
AbstractPolyList
Parameters:
polyList Poly list build (out)
box Box bounding volume
sphere Sphere bounding volume

Reimplemented from SceneObject.

bool TerrainBlock::castRay ( const Point3F start,
const Point3F end,
RayInfo info 
) [virtual]

Casts a ray and obtain collision information, returns true if RayInfo is modified.

Parameters:
start Start point of ray
end End point of ray
info Collision information obtained (out)

Reimplemented from SceneObject.

bool TerrainBlock::castRayI ( const Point3F start,
const Point3F end,
RayInfo info,
bool  emptyCollide 
)

bool TerrainBlock::castRayBlock ( const Point3F pStart,
const Point3F pEnd,
const Point2I blockPos,
U32  level,
F32  invDeltaX,
F32  invDeltaY,
F32  startT,
F32  endT,
RayInfo info,
bool   
)

bool TerrainBlock::buildMaterialMap (  ) 

void TerrainBlock::buildMipMap (  ) 

void TerrainBlock::setBaseMaterials ( S32  argc,
const char *  argv[] 
)

bool TerrainBlock::loadBaseMaterials (  ) 

bool TerrainBlock::initMMXBlender (  ) 

void TerrainBlock::setOverrideMaterial ( BaseMatInstance overrideMaterial  ) 

const FileName& TerrainBlock::getDetailTexture (  )  const [inline]

void TerrainBlock::setDetailTexture ( const FileName newValue  )  [inline]

const FileName& TerrainBlock::getTerrainFile (  )  const [inline]

void TerrainBlock::setTerrainFile ( const FileName newValue  )  [inline]

String TerrainBlock::getMaterial ( S32  idx  )  [inline]

void TerrainBlock::setMaterial ( S32  idx,
const String newValue 
)

S32 TerrainBlock::getMaterialCount (  )  const [inline]

void TerrainBlock::postLight ( Vector< TerrainBlock * > &  terrBlocks  )  [inline]

TerrainBlock::DECLARE_CONOBJECT ( TerrainBlock   ) 

static void TerrainBlock::initPersistFields (  )  [static]

Register dynamic fields in a subclass of ConsoleObject.

See also:
addField(), addFieldV(), addDeprecatedField(), addGroup(), endGroup()

Reimplemented from SceneObject.

U32 TerrainBlock::packUpdate ( NetConnection conn,
U32  mask,
BitStream stream 
) [virtual]

Instructs this object to pack its state for transfer over the network.

Parameters:
conn Net connection being used
mask Mask indicating fields to transmit.
stream Bitstream to pack data to
Returns:
Any bits which were not dealt with. The value is stored by the networking system. Don't set bits you weren't passed.

Reimplemented from NetObject.

void TerrainBlock::unpackUpdate ( NetConnection conn,
BitStream stream 
) [virtual]

Instructs this object to read state data previously packed with packUpdate.

Parameters:
conn Net connection being used
stream stream to read from

Reimplemented from NetObject.


Member Data Documentation

Array from the file.

Signal<void(U32,TerrainBlock*,const Point2I& ,const Point2I&)> TerrainBlock::smUpdateSignal [static]

GridSquare* TerrainBlock::gridMap[BlockShift+1] [private]