Commit ba58d26f authored by hybrid's avatar hybrid

Use core::array instead of C arrays.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2472 dfc29bdd-3216-0410-991c-e03cc46cb475
parent b8155bde
...@@ -17,10 +17,8 @@ namespace scene ...@@ -17,10 +17,8 @@ namespace scene
//! constructor //! constructor
CShadowVolumeSceneNode::CShadowVolumeSceneNode(const IMesh* shadowMesh, ISceneNode* parent, CShadowVolumeSceneNode::CShadowVolumeSceneNode(const IMesh* shadowMesh, ISceneNode* parent,
ISceneManager* mgr, s32 id, bool zfailmethod, f32 infinity) ISceneManager* mgr, s32 id, bool zfailmethod, f32 infinity)
: IShadowVolumeSceneNode(parent, mgr, id), Vertices(0), Indices(0), : IShadowVolumeSceneNode(parent, mgr, id),
Adjacency(0), Edges(0), FaceData(0), ShadowMesh(0), ShadowMesh(0), IndexCount(0), VertexCount(0), ShadowVolumesUsed(0),
IndexCountAllocated(0), VertexCountAllocated(0),
IndexCount(0), VertexCount(0), EdgeCount(0), ShadowVolumesUsed(0),
Infinity(infinity), UseZFailMethod(zfailmethod) Infinity(infinity), UseZFailMethod(zfailmethod)
{ {
#ifdef _DEBUG #ifdef _DEBUG
...@@ -37,15 +35,8 @@ CShadowVolumeSceneNode::~CShadowVolumeSceneNode() ...@@ -37,15 +35,8 @@ CShadowVolumeSceneNode::~CShadowVolumeSceneNode()
if (ShadowMesh) if (ShadowMesh)
ShadowMesh->drop(); ShadowMesh->drop();
delete [] Edges;
for (u32 i=0; i<ShadowVolumes.size(); ++i) for (u32 i=0; i<ShadowVolumes.size(); ++i)
delete [] ShadowVolumes[i].vertices; delete [] ShadowVolumes[i].vertices;
delete [] Vertices;
delete [] Indices;
delete [] Adjacency;
delete [] FaceData;
} }
...@@ -55,7 +46,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light) ...@@ -55,7 +46,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
// builds the shadow volume and adds it to the shadow volume list. // builds the shadow volume and adds it to the shadow volume list.
if (ShadowVolumes.size() > (u32)ShadowVolumesUsed) if (ShadowVolumes.size() > ShadowVolumesUsed)
{ {
// get the next unused buffer // get the next unused buffer
svp = &ShadowVolumes[ShadowVolumesUsed]; svp = &ShadowVolumes[ShadowVolumesUsed];
...@@ -84,16 +75,12 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light) ...@@ -84,16 +75,12 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
++ShadowVolumesUsed; ++ShadowVolumesUsed;
} }
const s32 faceCount = (s32)(IndexCount / 3); const u32 faceCount = IndexCount / 3;
if (!Edges || faceCount * 6 > EdgeCount) if (faceCount * 6 > Edges.size())
{ Edges.set_used(faceCount*6);
delete [] Edges;
EdgeCount = faceCount * 6;
Edges = new u16[EdgeCount];
}
s32 numEdges = 0; u32 numEdges = 0;
const core::vector3df ls = light * Infinity; // light scaled const core::vector3df ls = light * Infinity; // light scaled
//if (UseZFailMethod) //if (UseZFailMethod)
...@@ -106,7 +93,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light) ...@@ -106,7 +93,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
// is used // is used
createZPassVolume(faceCount, numEdges, light, svp, UseZFailMethod); createZPassVolume(faceCount, numEdges, light, svp, UseZFailMethod);
for (s32 i=0; i<numEdges; ++i) for (u32 i=0; i<numEdges; ++i)
{ {
core::vector3df &v1 = Vertices[Edges[2*i+0]]; core::vector3df &v1 = Vertices[Edges[2*i+0]];
core::vector3df &v2 = Vertices[Edges[2*i+1]]; core::vector3df &v2 = Vertices[Edges[2*i+1]];
...@@ -128,7 +115,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light) ...@@ -128,7 +115,7 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
} }
void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges, void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, u32& numEdges,
const core::vector3df& light, const core::vector3df& light,
SShadowVolume* svp) SShadowVolume* svp)
{ {
...@@ -208,7 +195,7 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges, ...@@ -208,7 +195,7 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, s32& numEdges,
void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount, void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount,
s32& numEdges, u32& numEdges,
core::vector3df light, core::vector3df light,
SShadowVolume* svp, bool caps) SShadowVolume* svp, bool caps)
{ {
...@@ -265,8 +252,8 @@ void CShadowVolumeSceneNode::setShadowMesh(const IMesh* mesh) ...@@ -265,8 +252,8 @@ void CShadowVolumeSceneNode::setShadowMesh(const IMesh* mesh)
void CShadowVolumeSceneNode::updateShadowVolumes() void CShadowVolumeSceneNode::updateShadowVolumes()
{ {
const s32 oldIndexCount = IndexCount; const u32 oldIndexCount = IndexCount;
const s32 oldVertexCount = VertexCount; const u32 oldVertexCount = VertexCount;
VertexCount = 0; VertexCount = 0;
IndexCount = 0; IndexCount = 0;
...@@ -279,8 +266,8 @@ void CShadowVolumeSceneNode::updateShadowVolumes() ...@@ -279,8 +266,8 @@ void CShadowVolumeSceneNode::updateShadowVolumes()
// calculate total amount of vertices and indices // calculate total amount of vertices and indices
u32 i; u32 i;
s32 totalVertices = 0; u32 totalVertices = 0;
s32 totalIndices = 0; u32 totalIndices = 0;
const u32 bufcnt = mesh->getMeshBufferCount(); const u32 bufcnt = mesh->getMeshBufferCount();
for (i=0; i<bufcnt; ++i) for (i=0; i<bufcnt; ++i)
...@@ -292,24 +279,15 @@ void CShadowVolumeSceneNode::updateShadowVolumes() ...@@ -292,24 +279,15 @@ void CShadowVolumeSceneNode::updateShadowVolumes()
// allocate memory if necessary // allocate memory if necessary
if (totalVertices > VertexCountAllocated) if (totalVertices > Vertices.size())
{ Vertices.set_used(totalVertices);
delete [] Vertices;
Vertices = new core::vector3df[totalVertices];
VertexCountAllocated = totalVertices;
}
if (totalIndices > IndexCountAllocated) if (totalIndices > Indices.size())
{ {
delete [] Indices; Indices.set_used(totalIndices);
Indices = new u16[totalIndices];
IndexCountAllocated = totalIndices;
if (UseZFailMethod) if (UseZFailMethod)
{ FaceData.set_used(totalIndices / 3);
delete [] FaceData;
FaceData = new bool[totalIndices / 3];
}
} }
// copy mesh // copy mesh
...@@ -329,8 +307,7 @@ void CShadowVolumeSceneNode::updateShadowVolumes() ...@@ -329,8 +307,7 @@ void CShadowVolumeSceneNode::updateShadowVolumes()
} }
// recalculate adjacency if necessary // recalculate adjacency if necessary
if (oldVertexCount != VertexCount && if (oldVertexCount != VertexCount && oldIndexCount != IndexCount && UseZFailMethod)
oldIndexCount != IndexCount && UseZFailMethod)
calculateAdjacency(); calculateAdjacency();
// create as much shadow volumes as there are lights but // create as much shadow volumes as there are lights but
...@@ -338,9 +315,9 @@ void CShadowVolumeSceneNode::updateShadowVolumes() ...@@ -338,9 +315,9 @@ void CShadowVolumeSceneNode::updateShadowVolumes()
const u32 lights = SceneManager->getVideoDriver()->getDynamicLightCount(); const u32 lights = SceneManager->getVideoDriver()->getDynamicLightCount();
core::matrix4 mat = Parent->getAbsoluteTransformation(); core::matrix4 mat = Parent->getAbsoluteTransformation();
mat.makeInverse();
const core::vector3df parentpos = Parent->getAbsolutePosition(); const core::vector3df parentpos = Parent->getAbsolutePosition();
core::vector3df lpos; core::vector3df lpos;
mat.makeInverse();
// TODO: Only correct for point lights. // TODO: Only correct for point lights.
for (i=0; i<lights; ++i) for (i=0; i<lights; ++i)
...@@ -378,11 +355,10 @@ void CShadowVolumeSceneNode::render() ...@@ -378,11 +355,10 @@ void CShadowVolumeSceneNode::render()
driver->setTransform(video::ETS_WORLD, Parent->getAbsoluteTransformation()); driver->setTransform(video::ETS_WORLD, Parent->getAbsoluteTransformation());
for (s32 i=0; i<ShadowVolumesUsed; ++i) for (u32 i=0; i<ShadowVolumesUsed; ++i)
driver->drawStencilShadowVolume(ShadowVolumes[i].vertices, driver->drawStencilShadowVolume(ShadowVolumes[i].vertices,
ShadowVolumes[i].count, UseZFailMethod); ShadowVolumes[i].count, UseZFailMethod);
/*
if ( DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY ) if ( DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY )
{ {
video::SMaterial mat; video::SMaterial mat;
...@@ -390,12 +366,12 @@ void CShadowVolumeSceneNode::render() ...@@ -390,12 +366,12 @@ void CShadowVolumeSceneNode::render()
mat.Wireframe = true; mat.Wireframe = true;
mat.ZBuffer = true; mat.ZBuffer = true;
driver->setMaterial(mat); driver->setMaterial(mat);
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
for (s32 i=0; i<ShadowVolumesUsed; ++i) for (u32 i=0; i<ShadowVolumesUsed; ++i)
driver->drawVertexPrimitiveList(ShadowVolumes[i].vertices, driver->drawVertexPrimitiveList(ShadowVolumes[i].vertices,
ShadowVolumes[i].count,0,0,video::EVT_STANDARD,scene::EPT_LINES); ShadowVolumes[i].count,0,0,video::EVT_STANDARD,scene::EPT_LINES);
} }
*/
} }
...@@ -409,17 +385,14 @@ const core::aabbox3d<f32>& CShadowVolumeSceneNode::getBoundingBox() const ...@@ -409,17 +385,14 @@ const core::aabbox3d<f32>& CShadowVolumeSceneNode::getBoundingBox() const
//! Generates adjacency information based on mesh indices. //! Generates adjacency information based on mesh indices.
void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon) void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
{ {
delete [] Adjacency; Adjacency.set_used(IndexCount);
Adjacency = new u16[IndexCount];
epsilon *= epsilon; epsilon *= epsilon;
f32 t = 0;
// go through all faces and fetch their three neighbours // go through all faces and fetch their three neighbours
for (s32 f=0; f<IndexCount; f+=3) for (u32 f=0; f<IndexCount; f+=3)
{ {
for (s32 edge = 0; edge<3; ++edge) for (u32 edge = 0; edge<3; ++edge)
{ {
core::vector3df v1 = Vertices[Indices[f+edge]]; core::vector3df v1 = Vertices[Indices[f+edge]];
core::vector3df v2 = Vertices[Indices[f+((edge+1)%3)]]; core::vector3df v2 = Vertices[Indices[f+((edge+1)%3)]];
...@@ -427,9 +400,10 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon) ...@@ -427,9 +400,10 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
// now we search an_O_ther _F_ace with these two // now we search an_O_ther _F_ace with these two
// vertices, which is not the current face. // vertices, which is not the current face.
s32 of; u32 of;
for (of=0; of<IndexCount; of+=3) for (of=0; of<IndexCount; of+=3)
{
if (of != f) if (of != f)
{ {
s32 cnt1 = 0; s32 cnt1 = 0;
...@@ -437,18 +411,19 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon) ...@@ -437,18 +411,19 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
for (s32 e=0; e<3; ++e) for (s32 e=0; e<3; ++e)
{ {
t = v1.getDistanceFromSQ(Vertices[Indices[of+e]]); const f32 t1 = v1.getDistanceFromSQ(Vertices[Indices[of+e]]);
if (core::iszero(t)) if (core::iszero(t1))
++cnt1; ++cnt1;
t = v2.getDistanceFromSQ(Vertices[Indices[of+e]]); const f32 t2 = v2.getDistanceFromSQ(Vertices[Indices[of+e]]);
if (core::iszero(t)) if (core::iszero(t2))
++cnt2; ++cnt2;
} }
if (cnt1 == 1 && cnt2 == 1) if (cnt1 == 1 && cnt2 == 1)
break; break;
} }
}
if (of == IndexCount) if (of == IndexCount)
Adjacency[f + edge] = f; Adjacency[f + edge] = f;
...@@ -462,4 +437,3 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon) ...@@ -462,4 +437,3 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
...@@ -49,14 +49,13 @@ namespace scene ...@@ -49,14 +49,13 @@ namespace scene
struct SShadowVolume struct SShadowVolume
{ {
core::vector3df* vertices; core::vector3df* vertices;
s32 count; u32 count;
s32 size; u32 size;
}; };
void createShadowVolume(const core::vector3df& pos); void createShadowVolume(const core::vector3df& pos);
void createZPassVolume(s32 faceCount, s32& numEdges, core::vector3df light, SShadowVolume* svp, bool caps); void createZPassVolume(s32 faceCount, u32& numEdges, core::vector3df light, SShadowVolume* svp, bool caps);
void createZFailVolume(s32 faceCount, s32& numEdges, const core::vector3df& light, SShadowVolume* svp); void createZFailVolume(s32 faceCount, u32& numEdges, const core::vector3df& light, SShadowVolume* svp);
void addEdge(s32& numEdges, u16 v0, u16 v1);
//! Generates adjacency information based on mesh indices. //! Generates adjacency information based on mesh indices.
void calculateAdjacency(f32 epsilon=0.0001f); void calculateAdjacency(f32 epsilon=0.0001f);
...@@ -66,23 +65,19 @@ namespace scene ...@@ -66,23 +65,19 @@ namespace scene
// a shadow volume for every light // a shadow volume for every light
core::array<SShadowVolume> ShadowVolumes; core::array<SShadowVolume> ShadowVolumes;
core::vector3df* Vertices; core::array<core::vector3df> Vertices;
u16* Indices; core::array<u16> Indices;
u16* Adjacency; core::array<u16> Adjacency;
u16* Edges; core::array<u16> Edges;
// used for zfail method, if face is front facing // used for zfail method, if face is front facing
bool* FaceData; core::array<bool> FaceData;
const scene::IMesh* ShadowMesh; const scene::IMesh* ShadowMesh;
s32 IndexCountAllocated; u32 IndexCount;
s32 VertexCountAllocated; u32 VertexCount;
s32 IndexCount;
s32 VertexCount;
s32 EdgeCount; u32 ShadowVolumesUsed;
s32 ShadowVolumesUsed;
f32 Infinity; f32 Infinity;
......
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