Commit 0d0d8790 authored by hybrid's avatar hybrid

Constification and code layout.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2888 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 45b3d37e
...@@ -62,18 +62,30 @@ struct STriangleList ...@@ -62,18 +62,30 @@ struct STriangleList
if (core::line2df(a,b).getPointOrientation(c) < 0) if (core::line2df(a,b).getPointOrientation(c) < 0)
{ core::vector2df tmp=a; a=b; b=tmp; } { core::vector2df tmp=a; a=b; b=tmp; }
u32 ia=-1, ib=-1, ic=-1; u32 ia=0xffffffff, ib=0xffffffff, ic=0xffffffff;
// Find each vertex // Find each vertex
for (u32 i=0; i < positions.size() && (ia==(u32)-1||ib==(u32)-1||ic==(u32)-1) ; ++i) for (u32 i=0; i < positions.size() && (ia==(u32)-1||ib==(u32)-1||ic==(u32)-1) ; ++i)
{ {
if (positions[i] == a) ia = i; if (positions[i] == a)
if (positions[i] == b) ib = i; ia = i;
if (positions[i] == c) ic = i; if (positions[i] == b)
ib = i;
if (positions[i] == c)
ic = i;
} }
if (ia==-1) {return false;} if (ia==0xffffffff)
if (ib==-1) {return false;} {
if (ic==-1) {return false;} return false;
}
if (ib==0xffffffff)
{
return false;
}
if (ic==0xffffffff)
{
return false;
}
for (u32 i=0; i<indexes.size(); i+=3) for (u32 i=0; i<indexes.size(); i+=3)
if ( (indexes[i] == ia && indexes[i+1] == ib && indexes[i+2] == ic) || if ( (indexes[i] == ia && indexes[i+1] == ib && indexes[i+2] == ic) ||
...@@ -93,26 +105,35 @@ struct STriangleList ...@@ -93,26 +105,35 @@ struct STriangleList
core::vector2df tmp=a; a=b; b=tmp; core::vector2df tmp=a; a=b; b=tmp;
} }
u32 ia=-1, ib=-1, ic=-1; u32 ia=0xffffffff, ib=0xffffffff, ic=0xffffffff;
// no duplicate vertex positions allowed... // no duplicate vertex positions allowed...
for (u32 i=0; i < positions.size() && (ia==-1||ib==-1||ic==-1) ; ++i) for (u32 i=0; i < positions.size() && (ia==-1||ib==-1||ic==-1) ; ++i)
{ {
if (positions[i] == a) ia = i; if (positions[i] == a)
if (positions[i] == b) ib = i; ia = i;
if (positions[i] == c) ic = i; if (positions[i] == b)
ib = i;
if (positions[i] == c)
ic = i;
} }
bool found=true; bool found=true;
if (ia==-1) if (ia==0xffffffff)
{ {
ia = positions.size(); positions.push_back(a); found=false; ia = positions.size();
positions.push_back(a);
found=false;
} }
if (ib==-1) if (ib==0xffffffff)
{ {
ib = positions.size(); positions.push_back(b); found=false; ib = positions.size();
positions.push_back(b);
found=false;
} }
if (ic==-1) if (ic==0xffffffff)
{ {
ic = positions.size(); positions.push_back(c); found=false; ic = positions.size();
positions.push_back(c);
found=false;
} }
// no duplicate triangles allowed // no duplicate triangles allowed
...@@ -259,26 +280,26 @@ public: ...@@ -259,26 +280,26 @@ public:
core::vector2df out; core::vector2df out;
//if (la.intersectWith(l2,out)) //if (la.intersectWith(l2,out))
// if ( out != la.start && out != la.end && // if (out != la.start && out != la.end &&
// out != l2.start && out != l2.end ) // out != l2.start && out != l2.end)
// return true; // return true;
if (lb.intersectWith(l2,out)) if (lb.intersectWith(l2,out))
if (!out.equals(lb.start) && !out.equals(lb.end) && if (!out.equals(lb.start) && !out.equals(lb.end) &&
!out.equals(l2.start) && !out.equals(l2.end) ) !out.equals(l2.start) && !out.equals(l2.end))
return true; return true;
if (lc.intersectWith(l2,out)) if (lc.intersectWith(l2,out))
if (!out.equals(lc.start) && !out.equals(lc.end) && if (!out.equals(lc.start) && !out.equals(lc.end) &&
!out.equals(l2.start) && !out.equals(l2.end) ) !out.equals(l2.start) && !out.equals(l2.end))
return true; return true;
// my shit intersection code only works with lines in certain directions :( // my shit intersection code only works with lines in certain directions :(
if (l2.intersectWith(lb,out)) if (l2.intersectWith(lb,out))
if (!out.equals(lb.start) && !out.equals(lb.end) && if (!out.equals(lb.start) && !out.equals(lb.end) &&
!out.equals(l2.start) && !out.equals(l2.end) ) !out.equals(l2.start) && !out.equals(l2.end))
return true; return true;
if (l2.intersectWith(lc,out)) if (l2.intersectWith(lc,out))
if (!out.equals(lc.start) && !out.equals(lc.end) && if (!out.equals(lc.start) && !out.equals(lc.end) &&
!out.equals(l2.start) && !out.equals(l2.end) ) !out.equals(l2.start) && !out.equals(l2.end))
return true; return true;
...@@ -320,7 +341,7 @@ public: ...@@ -320,7 +341,7 @@ public:
void drawTriangle( core::line2df line, core::vector2df point) void drawTriangle( core::line2df line, core::vector2df point)
{ {
//u32 endt = Device->getTimer()->getTime() + t; //const u32 endt = Device->getTimer()->getTime() + t;
f32 scale = 5; f32 scale = 5;
...@@ -338,9 +359,9 @@ public: ...@@ -338,9 +359,9 @@ public:
Device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,255,255)); Device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,255,255));
} }
// draw this triangle // draw this triangle
core::position2di st = core::position2di((s32)(line.start.X*scale)+50, (s32)(line.start.Y*scale)+50); const core::position2di st((s32)(line.start.X*scale)+50, (s32)(line.start.Y*scale)+50);
core::position2di en = core::position2di((s32)(line.end.X*scale)+50, (s32)(line.end.Y*scale)+50); const core::position2di en((s32)(line.end.X*scale)+50, (s32)(line.end.Y*scale)+50);
core::position2di p = core::position2di((s32)(point.X*scale)+50, (s32)(point.Y*scale)+50); const core::position2di p((s32)(point.X*scale)+50, (s32)(point.Y*scale)+50);
Device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,0,0)); Device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,0,0));
Device->getVideoDriver()->draw2DLine(en,p, SColor(255,0,255,0)); Device->getVideoDriver()->draw2DLine(en,p, SColor(255,0,255,0));
Device->getVideoDriver()->draw2DLine(p,st, SColor(255,0,0,255)); Device->getVideoDriver()->draw2DLine(p,st, SColor(255,0,0,255));
...@@ -668,12 +689,12 @@ public: ...@@ -668,12 +689,12 @@ public:
void drawEdges(IrrlichtDevice *device, u32 t, s32 scale) void drawEdges(IrrlichtDevice *device, u32 t, s32 scale)
{ {
u32 stt = device->getTimer()->getTime(); const u32 stt = device->getTimer()->getTime();
u32 endt = stt + t; const u32 endt = stt + t;
while(device->getTimer()->getTime() < endt ) while(device->getTimer()->getTime() < endt )
{ {
f32 phase = f32((device->getTimer()->getTime()-stt) % 500) / 500.0f; const f32 phase = f32((device->getTimer()->getTime()-stt) % 500) / 500.0f;
device->run(); device->run();
device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0)); device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0));
...@@ -694,12 +715,12 @@ public: ...@@ -694,12 +715,12 @@ public:
void drawTriangles(IrrlichtDevice *device, u32 t, s32 scale) void drawTriangles(IrrlichtDevice *device, u32 t, s32 scale)
{ {
u32 stt = device->getTimer()->getTime(); const u32 stt = device->getTimer()->getTime();
u32 endt = stt + t; const u32 endt = stt + t;
while(device->getTimer()->getTime() < endt ) while(device->getTimer()->getTime() < endt )
{ {
f32 phase = f32((device->getTimer()->getTime()-stt) % 500) / 500.0f; const f32 phase = f32((device->getTimer()->getTime()-stt) % 500) / 500.0f;
device->run(); device->run();
device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0)); device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0));
...@@ -707,9 +728,8 @@ public: ...@@ -707,9 +728,8 @@ public:
for (u32 v=0;v<groups[g].triangles.indexes.size()*phase; v+=3) for (u32 v=0;v<groups[g].triangles.indexes.size()*phase; v+=3)
{ {
STriangleList &t = groups[g].triangles; STriangleList &t = groups[g].triangles;
core::position2di st, en; core::position2di st((s32)(t.positions[t.indexes[v+0]].X*scale)+50,(s32)(t.positions[t.indexes[v+0]].Y*scale)+50);
st = core::position2di((s32)(t.positions[t.indexes[v+0]].X*scale)+50,(s32)(t.positions[t.indexes[v+0]].Y*scale)+50); core::position2di en((s32)(t.positions[t.indexes[v+1]].X*scale)+50,(s32)(t.positions[t.indexes[v+1]].Y*scale)+50);
en = core::position2di((s32)(t.positions[t.indexes[v+1]].X*scale)+50,(s32)(t.positions[t.indexes[v+1]].Y*scale)+50);
device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,0,0)); device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,0,0));
st = core::position2di((s32)(t.positions[t.indexes[v+1]].X*scale)+50,(s32)(t.positions[t.indexes[v+1]].Y*scale)+50); st = core::position2di((s32)(t.positions[t.indexes[v+1]].X*scale)+50,(s32)(t.positions[t.indexes[v+1]].Y*scale)+50);
en = core::position2di((s32)(t.positions[t.indexes[v+2]].X*scale)+50,(s32)(t.positions[t.indexes[v+2]].Y*scale)+50); en = core::position2di((s32)(t.positions[t.indexes[v+2]].X*scale)+50,(s32)(t.positions[t.indexes[v+2]].Y*scale)+50);
...@@ -724,7 +744,7 @@ public: ...@@ -724,7 +744,7 @@ public:
void drawTriLines(IrrlichtDevice *device, u32 t, s32 scale) void drawTriLines(IrrlichtDevice *device, u32 t, s32 scale)
{ {
u32 endt = device->getTimer()->getTime() + t; const u32 endt = device->getTimer()->getTime() + t;
while(device->getTimer()->getTime() < endt ) while(device->getTimer()->getTime() < endt )
{ {
...@@ -735,8 +755,8 @@ public: ...@@ -735,8 +755,8 @@ public:
for (u32 h=0;h<groups[g].ll[v].lines.size(); ++h) for (u32 h=0;h<groups[g].ll[v].lines.size(); ++h)
{ {
core::line2df &currentline = groups[g].ll[v].lines[h]; core::line2df &currentline = groups[g].ll[v].lines[h];
core::position2di st = core::position2di((s32)(currentline.start.X*scale)+50, (s32)(currentline.start.Y*scale)+50); const core::position2di st((s32)(currentline.start.X*scale)+50, (s32)(currentline.start.Y*scale)+50);
core::position2di en = core::position2di((s32)(currentline.end.X*scale)+50, (s32)(currentline.end.Y*scale)+50); const core::position2di en((s32)(currentline.end.X*scale)+50, (s32)(currentline.end.Y*scale)+50);
device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,0,0)); device->getVideoDriver()->draw2DLine(st,en, SColor(255,255,0,0));
} }
...@@ -752,8 +772,9 @@ public: ...@@ -752,8 +772,9 @@ public:
verts.clear(); verts.clear();
for(u32 v=0; v< t.positions.size(); ++v) for(u32 v=0; v< t.positions.size(); ++v)
{ {
verts.push_back(S3DVertex( -t.positions[v].X, -t.positions[v].Y, -100, verts.push_back(S3DVertex(
0,0,1,SColor(255,255,255,255),0,0) ); -t.positions[v].X, -t.positions[v].Y, -100,
0,0,1,SColor(255,255,255,255),0,0));
} }
device->getVideoDriver()->drawIndexedTriangleList(verts.pointer(),verts.size(),t.indexes.pointer(), t.indexes.size()/3 ); device->getVideoDriver()->drawIndexedTriangleList(verts.pointer(),verts.size(),t.indexes.pointer(), t.indexes.size()/3 );
...@@ -800,8 +821,7 @@ public: ...@@ -800,8 +821,7 @@ public:
void processPixel(s32 x, s32 y) void processPixel(s32 x, s32 y)
{ {
// solid? // solid?
bool pix = getPixel(x,y); if (getPixel(x,y))
if (pix)
{ {
s32 g=0, grp=0; s32 g=0, grp=0;
...@@ -931,7 +951,8 @@ public: ...@@ -931,7 +951,8 @@ public:
} }
// number of verts is one more than number of pixels because it's a grid of squares // number of verts is one more than number of pixels because it's a grid of squares
letterWidth++; letterHeight++; letterWidth++;
letterHeight++;
// create image memory // create image memory
imagedata.set_used(letterWidth*letterHeight); imagedata.set_used(letterWidth*letterHeight);
...@@ -939,6 +960,7 @@ public: ...@@ -939,6 +960,7 @@ public:
// create vertex list, set position etc // create vertex list, set position etc
verts.set_used(letterWidth*letterHeight); verts.set_used(letterWidth*letterHeight);
for (s32 y=0; y<letterHeight; ++y) for (s32 y=0; y<letterHeight; ++y)
{
for (s32 x=0; x<letterWidth; ++x) for (s32 x=0; x<letterWidth; ++x)
{ {
S3DVertex &v = getVert(x,y); S3DVertex &v = getVert(x,y);
...@@ -948,6 +970,7 @@ public: ...@@ -948,6 +970,7 @@ public:
v.Normal = core::vector3df(0,0,-1); v.Normal = core::vector3df(0,0,-1);
v.Color = SColor(255,255,255,255); v.Color = SColor(255,255,255,255);
} }
}
// clear index list // clear index list
inds.clear(); inds.clear();
...@@ -968,11 +991,11 @@ public: ...@@ -968,11 +991,11 @@ public:
void addChar(wchar_t thischar) void addChar(wchar_t thischar)
{ {
s32 area = FontTool->CharMap[thischar]; const s32 area = FontTool->CharMap[thischar];
CFontTool::SFontArea &fa = FontTool->Areas[area]; const CFontTool::SFontArea &fa = FontTool->Areas[area];
s32 img = fa.sourceimage; const s32 img = fa.sourceimage;
core::rect<s32> r = fa.rectangle; const core::rect<s32>& r = fa.rectangle;
// init image memory // init image memory
IImage *image = FontTool->currentImages[img]; IImage *image = FontTool->currentImages[img];
......
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