Commit 236d6c33 authored by hybrid's avatar hybrid

Changed from f64 C-array to core::array, some minor optimizations.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1793 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 7004d4a1
...@@ -57,8 +57,6 @@ namespace scene ...@@ -57,8 +57,6 @@ namespace scene
//! destructor //! destructor
CTerrainSceneNode::~CTerrainSceneNode ( ) CTerrainSceneNode::~CTerrainSceneNode ( )
{ {
delete [] TerrainData.LODDistanceThreshold;
delete [] TerrainData.Patches; delete [] TerrainData.Patches;
if (FileSystem) if (FileSystem)
...@@ -80,7 +78,7 @@ namespace scene ...@@ -80,7 +78,7 @@ namespace scene
if( !heightMap ) if( !heightMap )
{ {
os::Printer::print( "Was not able to load heightmap." ); os::Printer::print( "Unable to load heightmap." );
return false; return false;
} }
...@@ -182,7 +180,6 @@ namespace scene ...@@ -182,7 +180,6 @@ namespace scene
const u32 vertexCount = mb->getVertexCount(); const u32 vertexCount = mb->getVertexCount();
// We copy the data to the renderBuffer, after the normals have been calculated. // We copy the data to the renderBuffer, after the normals have been calculated.
RenderBuffer->getVertexBuffer().set_used( vertexCount ); RenderBuffer->getVertexBuffer().set_used( vertexCount );
for( u32 i = 0; i < vertexCount; ++i ) for( u32 i = 0; i < vertexCount; ++i )
...@@ -237,6 +234,7 @@ namespace scene ...@@ -237,6 +234,7 @@ namespace scene
// get file size // get file size
const long fileSize = file->getSize(); const long fileSize = file->getSize();
// TODO: Currently no floats are supported
const s32 bytesPerPixel = bitsPerPixel / 8; const s32 bytesPerPixel = bitsPerPixel / 8;
// Get the dimension of the heightmap data // Get the dimension of the heightmap data
...@@ -511,6 +509,7 @@ namespace scene ...@@ -511,6 +509,7 @@ namespace scene
} }
} }
void CTerrainSceneNode::preRenderIndicesCalculations() void CTerrainSceneNode::preRenderIndicesCalculations()
{ {
switch (RenderBuffer->getIndexBuffer().getType()) switch (RenderBuffer->getIndexBuffer().getType())
...@@ -532,32 +531,28 @@ namespace scene ...@@ -532,32 +531,28 @@ namespace scene
void CTerrainSceneNode::preRenderIndicesCalculationsDirect(INDEX_TYPE* IndexBuffer) void CTerrainSceneNode::preRenderIndicesCalculationsDirect(INDEX_TYPE* IndexBuffer)
{ {
IndicesToRender = 0; IndicesToRender = 0;
s32 index11;
s32 index21;
s32 index12;
s32 index22;
// Then generate the indices for all patches that are visible. // Then generate the indices for all patches that are visible.
for( s32 i = 0; i < TerrainData.PatchCount; ++i ) for( s32 i = 0; i < TerrainData.PatchCount; ++i )
{ {
for( s32 j = 0; j < TerrainData.PatchCount; ++j ) for( s32 j = 0; j < TerrainData.PatchCount; ++j )
{ {
s32 index = i * TerrainData.PatchCount + j; const s32 index = i * TerrainData.PatchCount + j;
if( TerrainData.Patches[index].CurrentLOD >= 0 ) if( TerrainData.Patches[index].CurrentLOD >= 0 )
{ {
s32 x = 0; s32 x = 0;
s32 z = 0; s32 z = 0;
// calculate the step we take this patch, based on the patches current LOD // calculate the step we take this patch, based on the patches current LOD
s32 step = 1 << TerrainData.Patches[index].CurrentLOD; const s32 step = 1 << TerrainData.Patches[index].CurrentLOD;
// Loop through patch and generate indices // Loop through patch and generate indices
while( z < TerrainData.CalcPatchSize ) while( z < TerrainData.CalcPatchSize )
{ {
index11 = getIndex( j, i, index, x, z ); const s32 index11 = getIndex( j, i, index, x, z );
index21 = getIndex( j, i, index, x + step, z ); const s32 index21 = getIndex( j, i, index, x + step, z );
index12 = getIndex( j, i, index, x, z + step ); const s32 index12 = getIndex( j, i, index, x, z + step );
index22 = getIndex( j, i, index, x + step, z + step ); const s32 index22 = getIndex( j, i, index, x + step, z + step );
IndexBuffer[IndicesToRender++]= index12; IndexBuffer[IndicesToRender++]= index12;
IndexBuffer[IndicesToRender++]= index11; IndexBuffer[IndicesToRender++]= index11;
...@@ -604,9 +599,7 @@ namespace scene ...@@ -604,9 +599,7 @@ namespace scene
video::IVideoDriver* driver = SceneManager->getVideoDriver(); video::IVideoDriver* driver = SceneManager->getVideoDriver();
core::matrix4 identity; driver->setTransform (video::ETS_WORLD, core::IdentityMatrix);
driver->setTransform (video::ETS_WORLD, identity);
driver->setMaterial(Mesh.getMeshBuffer(0)->getMaterial()); driver->setMaterial(Mesh.getMeshBuffer(0)->getMaterial());
RenderBuffer->getIndexBuffer().set_used(IndicesToRender); RenderBuffer->getIndexBuffer().set_used(IndicesToRender);
...@@ -623,16 +616,18 @@ namespace scene ...@@ -623,16 +616,18 @@ namespace scene
m.Lighting = false; m.Lighting = false;
driver->setMaterial(m); driver->setMaterial(m);
if ( DebugDataVisible & scene::EDS_BBOX ) if ( DebugDataVisible & scene::EDS_BBOX )
driver->draw3DBox( TerrainData.BoundingBox, video::SColor(0,255,255,255)); driver->draw3DBox( TerrainData.BoundingBox, video::SColor(255,255,255,255));
const s32 count = TerrainData.PatchCount * TerrainData.PatchCount; const s32 count = TerrainData.PatchCount * TerrainData.PatchCount;
s32 visible = 0; s32 visible = 0;
if ( DebugDataVisible & scene::EDS_BBOX_BUFFERS ) if ( DebugDataVisible & scene::EDS_BBOX_BUFFERS )
{
for( s32 j = 0; j < count; ++j ) for( s32 j = 0; j < count; ++j )
{ {
driver->draw3DBox( TerrainData.Patches[j].BoundingBox, video::SColor(0,255,0,0)); driver->draw3DBox( TerrainData.Patches[j].BoundingBox, video::SColor(255,255,0,0));
visible += ( TerrainData.Patches[j].CurrentLOD >= 0 ); visible += ( TerrainData.Patches[j].CurrentLOD >= 0 );
} }
}
static u32 lastTime = 0; static u32 lastTime = 0;
...@@ -668,32 +663,19 @@ namespace scene ...@@ -668,32 +663,19 @@ namespace scene
if (!Mesh.getMeshBufferCount()) if (!Mesh.getMeshBufferCount())
return; return;
if ( LOD < 0 ) LOD = core::clamp(LOD, 0, TerrainData.MaxLOD - 1);
LOD = 0;
else if ( LOD > TerrainData.MaxLOD - 1 )
LOD = TerrainData.MaxLOD - 1;
//mb.setVertexBuffer( new CVertexBuffer( Mesh.getMeshBuffer(0)->getVertexBuffer() ));
u32 numVertices = Mesh.getMeshBuffer( 0 )->getVertexCount ( );
mb.getVertexBuffer().reallocate ( numVertices );
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)Mesh.getMeshBuffer ( 0 )->getVertices ( );
const u32 numVertices = Mesh.getMeshBuffer(0)->getVertexCount();
mb.getVertexBuffer().reallocate(numVertices);
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)Mesh.getMeshBuffer(0)->getVertices();
for (u32 n=0; n<numVertices; ++n) for (u32 n=0; n<numVertices; ++n)
mb.getVertexBuffer().push_back(vertices[n]); mb.getVertexBuffer().push_back(vertices[n]);
mb.getIndexBuffer().setType( RenderBuffer->getIndexBuffer().getType() ); mb.getIndexBuffer().setType( RenderBuffer->getIndexBuffer().getType() );
// calculate the step we take for all patches, since LOD is the same // calculate the step we take for all patches, since LOD is the same
s32 step = 1 << LOD; const s32 step = 1 << LOD;
u32 index11;
u32 index21;
u32 index12;
u32 index22;
// Generate the indices for all patches at the specified LOD // Generate the indices for all patches at the specified LOD
for (s32 i=0; i<TerrainData.PatchCount; ++i) for (s32 i=0; i<TerrainData.PatchCount; ++i)
...@@ -707,10 +689,10 @@ namespace scene ...@@ -707,10 +689,10 @@ namespace scene
// Loop through patch and generate indices // Loop through patch and generate indices
while (z < TerrainData.CalcPatchSize) while (z < TerrainData.CalcPatchSize)
{ {
index11 = getIndex( j, i, index, x, z ); const s32 index11 = getIndex( j, i, index, x, z );
index21 = getIndex( j, i, index, x + step, z ); const s32 index21 = getIndex( j, i, index, x + step, z );
index12 = getIndex( j, i, index, x, z + step ); const s32 index12 = getIndex( j, i, index, x, z + step );
index22 = getIndex( j, i, index, x + step, z + step ); const s32 index22 = getIndex( j, i, index, x + step, z + step );
mb.getIndexBuffer().push_back( index12 ); mb.getIndexBuffer().push_back( index12 );
mb.getIndexBuffer().push_back( index11 ); mb.getIndexBuffer().push_back( index11 );
...@@ -748,7 +730,6 @@ namespace scene ...@@ -748,7 +730,6 @@ namespace scene
if ( LOD < -1 || LOD > TerrainData.MaxLOD - 1 ) if ( LOD < -1 || LOD > TerrainData.MaxLOD - 1 )
return -1; return -1;
s32 rv = 0;
core::array<s32> cLODs; core::array<s32> cLODs;
bool setLODs = false; bool setLODs = false;
...@@ -768,27 +749,24 @@ namespace scene ...@@ -768,27 +749,24 @@ namespace scene
return -2; // Patch not visible, don't generate indices. return -2; // Patch not visible, don't generate indices.
// calculate the step we take for this LOD // calculate the step we take for this LOD
s32 step = 1 << LOD; const s32 step = 1 << LOD;
// Generate the indices for the specified patch at the specified LOD // Generate the indices for the specified patch at the specified LOD
s32 index = patchX * TerrainData.PatchCount + patchZ; const s32 index = patchX * TerrainData.PatchCount + patchZ;
s32 x = 0; s32 x = 0;
s32 z = 0; s32 z = 0;
s32 index11;
s32 index21;
s32 index12;
s32 index22;
indices.set_used ( TerrainData.PatchSize * TerrainData.PatchSize * 6 ); indices.set_used ( TerrainData.PatchSize * TerrainData.PatchSize * 6 );
// Loop through patch and generate indices // Loop through patch and generate indices
s32 rv=0;
while (z<TerrainData.CalcPatchSize) while (z<TerrainData.CalcPatchSize)
{ {
index11 = getIndex( patchZ, patchX, index, x, z ); const s32 index11 = getIndex( patchZ, patchX, index, x, z );
index21 = getIndex( patchZ, patchX, index, x + step, z ); const s32 index21 = getIndex( patchZ, patchX, index, x + step, z );
index12 = getIndex( patchZ, patchX, index, x, z + step ); const s32 index12 = getIndex( patchZ, patchX, index, x, z + step );
index22 = getIndex( patchZ, patchX, index, x + step, z + step ); const s32 index22 = getIndex( patchZ, patchX, index, x + step, z + step );
indices[rv++] = index12; indices[rv++] = index12;
indices[rv++] = index11; indices[rv++] = index11;
...@@ -978,7 +956,7 @@ namespace scene ...@@ -978,7 +956,7 @@ namespace scene
} }
//! calculate smooth normals //! calculate smooth normals
void CTerrainSceneNode::calculateNormals ( CDynamicMeshBuffer* mb ) void CTerrainSceneNode::calculateNormals( CDynamicMeshBuffer* mb )
{ {
s32 count; s32 count;
core::vector3df a, b, c, t; core::vector3df a, b, c, t;
...@@ -1121,7 +1099,7 @@ namespace scene ...@@ -1121,7 +1099,7 @@ namespace scene
{ {
for( s32 z = 0; z < TerrainData.PatchCount; ++z ) for( s32 z = 0; z < TerrainData.PatchCount; ++z )
{ {
s32 index = x * TerrainData.PatchCount + z; const s32 index = x * TerrainData.PatchCount + z;
TerrainData.Patches[index].CurrentLOD = 0; TerrainData.Patches[index].CurrentLOD = 0;
// For each patch, calculate the bounding box ( mins and maxes ) // For each patch, calculate the bounding box ( mins and maxes )
...@@ -1183,20 +1161,15 @@ namespace scene ...@@ -1183,20 +1161,15 @@ namespace scene
// Only update the LODDistanceThreshold if it's not manually changed // Only update the LODDistanceThreshold if it's not manually changed
if (!OverrideDistanceThreshold) if (!OverrideDistanceThreshold)
{ {
if( TerrainData.LODDistanceThreshold ) TerrainData.LODDistanceThreshold.set_used(0);
{
delete [] TerrainData.LODDistanceThreshold;
}
// Determine new distance threshold for determining what LOD to draw patches at // Determine new distance threshold for determining what LOD to draw patches at
TerrainData.LODDistanceThreshold = new f64[TerrainData.MaxLOD]; TerrainData.LODDistanceThreshold.reallocate(TerrainData.MaxLOD);
const f64 size = TerrainData.PatchSize * TerrainData.PatchSize *
TerrainData.Scale.X * TerrainData.Scale.Z;
for (s32 i=0; i<TerrainData.MaxLOD; ++i) for (s32 i=0; i<TerrainData.MaxLOD; ++i)
{ {
TerrainData.LODDistanceThreshold[i] = TerrainData.LODDistanceThreshold.push_back(size * ((i+1+ i / 2) * (i+1+ i / 2)));
(TerrainData.PatchSize * TerrainData.PatchSize) *
(TerrainData.Scale.X * TerrainData.Scale.Z) *
((i+1+ i / 2) * (i+1+ i / 2));
} }
} }
} }
...@@ -1236,7 +1209,7 @@ namespace scene ...@@ -1236,7 +1209,7 @@ namespace scene
if( X >= 0 && X < TerrainData.Size && Z >= 0 && Z < TerrainData.Size ) if( X >= 0 && X < TerrainData.Size && Z >= 0 && Z < TerrainData.Size )
{ {
const video::S3DVertex2TCoords* Vertices = (const video::S3DVertex2TCoords*)Mesh.getMeshBuffer( 0 )->getVertices(); const video::S3DVertex2TCoords* Vertices = (const video::S3DVertex2TCoords*)Mesh.getMeshBuffer(0)->getVertices();
const core::vector3df& a = Vertices[ X * TerrainData.Size + Z ].Pos; const core::vector3df& a = Vertices[ X * TerrainData.Size + Z ].Pos;
const core::vector3df& b = Vertices[ (X + 1) * TerrainData.Size + Z ].Pos; const core::vector3df& b = Vertices[ (X + 1) * TerrainData.Size + Z ].Pos;
const core::vector3df& c = Vertices[ X * TerrainData.Size + ( Z + 1 ) ].Pos; const core::vector3df& c = Vertices[ X * TerrainData.Size + ( Z + 1 ) ].Pos;
...@@ -1281,8 +1254,7 @@ namespace scene ...@@ -1281,8 +1254,7 @@ namespace scene
// set possible new heightmap // set possible new heightmap
if (newHeightmap.size() > 0 && if (newHeightmap.size() != 0 && newHeightmap != HeightmapFile)
newHeightmap != HeightmapFile)
{ {
io::IReadFile* file = FileSystem->createAndOpenFile(newHeightmap.c_str()); io::IReadFile* file = FileSystem->createAndOpenFile(newHeightmap.c_str());
if (file) if (file)
......
...@@ -195,11 +195,10 @@ namespace scene ...@@ -195,11 +195,10 @@ namespace scene
//! param bVal: Boolean value representing whether or not to update selector dynamically. //! param bVal: Boolean value representing whether or not to update selector dynamically.
//! NOTE: Temporarily disabled while working out issues with DynamicSelectorUpdate //! NOTE: Temporarily disabled while working out issues with DynamicSelectorUpdate
virtual void setDynamicSelectorUpdate(bool bVal ) { DynamicSelectorUpdate = false; } virtual void setDynamicSelectorUpdate(bool bVal ) { DynamicSelectorUpdate = false; }
//virtual void setDynamicSelectorUpdate ( bool bVal ) { DynamicSelectorUpdate = bVal; }
//! Override the default generation of distance thresholds for determining the LOD a patch //! Override the default generation of distance thresholds for determining the LOD a patch
//! is rendered at. If any LOD is overridden, then the scene node will no longer apply //! is rendered at. If any LOD is overridden, then the scene node will no longer apply
//! scaling factors to these values. If you override these distances, and then apply //! scaling factors to these values. If you override these distances and then apply
//! a scale to the scene node, it is your responsibility to update the new distances to //! a scale to the scene node, it is your responsibility to update the new distances to
//! work best with your new terrain size. //! work best with your new terrain size.
virtual bool overrideLODDistance( s32 LOD, f64 newDistance ); virtual bool overrideLODDistance( s32 LOD, f64 newDistance );
...@@ -248,7 +247,7 @@ namespace scene ...@@ -248,7 +247,7 @@ namespace scene
: Size(0), PatchSize(0), CalcPatchSize(0), : Size(0), PatchSize(0), CalcPatchSize(0),
PatchCount(0), MaxLOD(0), PatchCount(0), MaxLOD(0),
BoundingBox(core::aabbox3df( 99999.9f, 99999.9f, 99999.9f, -99999.9f, -99999.9f, -99999.9f)), BoundingBox(core::aabbox3df( 99999.9f, 99999.9f, 99999.9f, -99999.9f, -99999.9f, -99999.9f)),
LODDistanceThreshold(0), Patches(0) Patches(0)
{ {
} }
...@@ -257,7 +256,7 @@ namespace scene ...@@ -257,7 +256,7 @@ namespace scene
PatchSize(patchSize), CalcPatchSize(patchSize-1), PatchSize(patchSize), CalcPatchSize(patchSize-1),
PatchCount(0), MaxLOD(maxLOD), PatchCount(0), MaxLOD(maxLOD),
BoundingBox(core::aabbox3df( 99999.9f, 99999.9f, 99999.9f, -99999.9f, -99999.9f, -99999.9f)), BoundingBox(core::aabbox3df( 99999.9f, 99999.9f, 99999.9f, -99999.9f, -99999.9f, -99999.9f)),
LODDistanceThreshold(0), Patches(0) Patches(0)
{ {
} }
...@@ -272,7 +271,7 @@ namespace scene ...@@ -272,7 +271,7 @@ namespace scene
s32 PatchCount; s32 PatchCount;
s32 MaxLOD; s32 MaxLOD;
core::aabbox3df BoundingBox; core::aabbox3df BoundingBox;
f64* LODDistanceThreshold; core::array<f64> LODDistanceThreshold;
SPatch* Patches; SPatch* Patches;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment