Firelike drawtype: Improve code

Remove unusable fine rotation by param2
Remove unused and redundant code
Fix code style issues
master
paramat 2015-09-12 22:19:29 +01:00
parent 620dcddf43
commit 8e9c9e305a
1 changed files with 60 additions and 92 deletions

View File

@ -1157,7 +1157,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
u16 l = getInteriorLight(n, 1, nodedef); u16 l = getInteriorLight(n, 1, nodedef);
video::SColor c = MapBlock_LightColor(255, l, f.light_source); video::SColor c = MapBlock_LightColor(255, l, f.light_source);
float s = BS/2*f.visual_scale; float s = BS / 2 * f.visual_scale;
content_t current = n.getContent(); content_t current = n.getContent();
content_t n2c; content_t n2c;
@ -1165,148 +1165,116 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
v3s16 n2p; v3s16 n2p;
static const v3s16 dirs[6] = { static const v3s16 dirs[6] = {
v3s16( 0, 1, 0), v3s16( 0, 1, 0),
v3s16( 0,-1, 0), v3s16( 0, -1, 0),
v3s16( 1, 0, 0), v3s16( 1, 0, 0),
v3s16(-1, 0, 0), v3s16(-1, 0, 0),
v3s16( 0, 0, 1), v3s16( 0, 0, 1),
v3s16( 0, 0,-1) v3s16( 0, 0, -1)
}; };
int doDraw[6] = {0,0,0,0,0,0}; int doDraw[6] = {0, 0, 0, 0, 0, 0};
bool drawAllFaces = true; bool drawAllFaces = true;
bool drawBottomFacesOnly = false; // Currently unused
// Check for adjacent nodes // Check for adjacent nodes
for(int i = 0; i < 6; i++) for (int i = 0; i < 6; i++) {
{
n2p = blockpos_nodes + p + dirs[i]; n2p = blockpos_nodes + p + dirs[i];
n2 = data->m_vmanip.getNodeNoEx(n2p); n2 = data->m_vmanip.getNodeNoEx(n2p);
n2c = n2.getContent(); n2c = n2.getContent();
if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) { if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
doDraw[i] = 1; doDraw[i] = 1;
if(drawAllFaces) if (drawAllFaces)
drawAllFaces = false; drawAllFaces = false;
} }
} }
for(int j = 0; j < 6; j++) for (int j = 0; j < 6; j++) {
{
int vOffset = 0; // Vertical offset of faces after rotation
int hOffset = 4; // Horizontal offset of faces to reach the edge
video::S3DVertex vertices[4] = video::S3DVertex vertices[4] = {
{ video::S3DVertex(-s, -BS / 2, 0, 0, 0, 0, c, 0, 1),
video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1), video::S3DVertex( s, -BS / 2, 0, 0, 0, 0, c, 1, 1),
video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1), video::S3DVertex( s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 1, 0),
video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0), video::S3DVertex(-s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 0, 0),
video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
}; };
// Calculate which faces should be drawn, (top or sides) // Calculate which faces should be drawn, (top or sides)
if(j == 0 && (drawAllFaces || (doDraw[3] == 1 || doDraw[1] == 1))) if (j == 0 && (drawAllFaces ||
{ (doDraw[3] == 1 || doDraw[1] == 1))) {
for(int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
vertices[i].Pos.rotateXZBy(90 + n.param2 * 2); vertices[i].Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(-10); vertices[i].Pos.rotateXYBy(-10);
vertices[i].Pos.Y -= vOffset; vertices[i].Pos.X -= 4.0;
vertices[i].Pos.X -= hOffset;
} }
} } else if (j == 1 && (drawAllFaces ||
else if(j == 1 && (drawAllFaces || (doDraw[5] == 1 || doDraw[1] == 1))) (doDraw[5] == 1 || doDraw[1] == 1))) {
{ for (int i = 0; i < 4; i++) {
for(int i = 0; i < 4; i++) { vertices[i].Pos.rotateXZBy(180);
vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
vertices[i].Pos.rotateYZBy(10); vertices[i].Pos.rotateYZBy(10);
vertices[i].Pos.Y -= vOffset; vertices[i].Pos.Z -= 4.0;
vertices[i].Pos.Z -= hOffset;
} }
} } else if (j == 2 && (drawAllFaces ||
else if(j == 2 && (drawAllFaces || (doDraw[2] == 1 || doDraw[1] == 1))) (doDraw[2] == 1 || doDraw[1] == 1))) {
{ for (int i = 0; i < 4; i++) {
for(int i = 0; i < 4; i++) { vertices[i].Pos.rotateXZBy(270);
vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
vertices[i].Pos.rotateXYBy(10); vertices[i].Pos.rotateXYBy(10);
vertices[i].Pos.Y -= vOffset; vertices[i].Pos.X += 4.0;
vertices[i].Pos.X += hOffset;
} }
} } else if (j == 3 && (drawAllFaces ||
else if(j == 3 && (drawAllFaces || (doDraw[4] == 1 || doDraw[1] == 1))) (doDraw[4] == 1 || doDraw[1] == 1))) {
{ for (int i = 0; i < 4; i++) {
for(int i = 0; i < 4; i++) {
vertices[i].Pos.rotateYZBy(-10); vertices[i].Pos.rotateYZBy(-10);
vertices[i].Pos.Y -= vOffset; vertices[i].Pos.Z += 4.0;
vertices[i].Pos.Z += hOffset;
} }
}
// Center cross-flames // Center cross-flames
else if(j == 4 && (drawAllFaces || doDraw[1] == 1)) } else if (j == 4 && (drawAllFaces || doDraw[1] == 1)) {
{ for (int i = 0; i < 4; i++) {
for(int i=0; i<4; i++) { vertices[i].Pos.rotateXZBy(45);
vertices[i].Pos.rotateXZBy(45 + n.param2 * 2);
vertices[i].Pos.Y -= vOffset;
} }
} } else if (j == 5 && (drawAllFaces || doDraw[1] == 1)) {
else if(j == 5 && (drawAllFaces || doDraw[1] == 1)) for (int i = 0; i < 4; i++) {
{ vertices[i].Pos.rotateXZBy(-45);
for(int i=0; i<4; i++) {
vertices[i].Pos.rotateXZBy(-45 + n.param2 * 2);
vertices[i].Pos.Y -= vOffset;
} }
} // Render flames on bottom of node above
} else if (j == 0 && doDraw[0] == 1 && doDraw[1] == 0) {
// Render flames on bottom for (int i = 0; i < 4; i++) {
else if(j == 0 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
{
for(int i = 0; i < 4; i++) {
vertices[i].Pos.rotateYZBy(70); vertices[i].Pos.rotateYZBy(70);
vertices[i].Pos.rotateXZBy(90 + n.param2 * 2); vertices[i].Pos.rotateXZBy(90);
vertices[i].Pos.Y += 4.84; vertices[i].Pos.Y += 4.84;
vertices[i].Pos.X -= hOffset+0.7; vertices[i].Pos.X -= 4.7;
} }
} } else if (j == 1 && doDraw[0] == 1 && doDraw[1] == 0) {
else if(j == 1 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0))) for (int i = 0; i < 4; i++) {
{
for(int i = 0; i < 4; i++) {
vertices[i].Pos.rotateYZBy(70); vertices[i].Pos.rotateYZBy(70);
vertices[i].Pos.rotateXZBy(180 + n.param2 * 2); vertices[i].Pos.rotateXZBy(180);
vertices[i].Pos.Y += 4.84; vertices[i].Pos.Y += 4.84;
vertices[i].Pos.Z -= hOffset+0.7; vertices[i].Pos.Z -= 4.7;
} }
} } else if (j == 2 && doDraw[0] == 1 && doDraw[1] == 0) {
else if(j == 2 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0))) for (int i = 0; i < 4; i++) {
{
for(int i = 0; i < 4; i++) {
vertices[i].Pos.rotateYZBy(70); vertices[i].Pos.rotateYZBy(70);
vertices[i].Pos.rotateXZBy(270 + n.param2 * 2); vertices[i].Pos.rotateXZBy(270);
vertices[i].Pos.Y += 4.84; vertices[i].Pos.Y += 4.84;
vertices[i].Pos.X += hOffset+0.7; vertices[i].Pos.X += 4.7;
} }
} } else if (j == 3 && doDraw[0] == 1 && doDraw[1] == 0) {
else if(j == 3 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0))) for (int i = 0; i < 4; i++) {
{
for(int i = 0; i < 4; i++) {
vertices[i].Pos.rotateYZBy(70); vertices[i].Pos.rotateYZBy(70);
vertices[i].Pos.Y += 4.84; vertices[i].Pos.Y += 4.84;
vertices[i].Pos.Z += hOffset+0.7; vertices[i].Pos.Z += 4.7;
} }
} } else {
else {
// Skip faces that aren't adjacent to a node // Skip faces that aren't adjacent to a node
continue; continue;
} }
for(int i=0; i<4; i++) for (int i = 0; i < 4; i++) {
{
vertices[i].Pos *= f.visual_scale; vertices[i].Pos *= f.visual_scale;
vertices[i].Pos += intToFloat(p, BS); vertices[i].Pos += intToFloat(p, BS);
} }
u16 indices[] = {0,1,2,2,3,0}; u16 indices[] = {0, 1, 2, 2, 3, 0};
// Add to mesh collector // Add to mesh collector
collector.append(tile, vertices, 4, indices, 6); collector.append(tile, vertices, 4, indices, 6);
} }