Add firelike drawtype
authorTriBlade9 <triblade9@mail.com>
Fri, 19 Sep 2014 23:37:40 +0000 (07:37 +0800)
committerShadowNinja <shadowninja@minetest.net>
Sun, 21 Sep 2014 19:50:27 +0000 (15:50 -0400)
doc/lua_api.txt
src/content_mapblock.cpp
src/nodedef.cpp
src/nodedef.h
src/script/cpp_api/s_node.cpp
src/shader.cpp

index 805b63f6a404b9dae729b5fe3926a18c1a57ddba..0cdca506f23ad37005c033c2bd0e8025fc223344 100644 (file)
@@ -422,6 +422,7 @@ Look for examples in games/minimal or games/minetest_game.
 - torchlike
 - signlike
 - plantlike
+- firelike
 - fencelike
 - raillike
 - nodebox -- See below. EXPERIMENTAL
index c94ff590e47b66ae20172dfbd09b7905adb901a1..6d7a69bb8d0231a68d7955019d6da4f7462b439e 100644 (file)
@@ -1187,6 +1187,168 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                                collector.append(tile, vertices, 4, indices, 6);
                        }
                break;}
+               case NDT_FIRELIKE:
+               {
+                       TileSpec tile = getNodeTileN(n, p, 0, data);
+                       tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
+
+                       u16 l = getInteriorLight(n, 1, nodedef);
+                       video::SColor c = MapBlock_LightColor(255, l, f.light_source);
+
+                       float s = BS/2*f.visual_scale;
+
+                       content_t current = n.getContent();
+                       content_t n2c;
+                       MapNode n2;
+                       v3s16 n2p;
+
+                       static const v3s16 dirs[6] = {
+                               v3s16( 0, 1, 0),
+                               v3s16( 0,-1, 0),
+                               v3s16( 1, 0, 0),
+                               v3s16(-1, 0, 0),
+                               v3s16( 0, 0, 1),
+                               v3s16( 0, 0,-1)
+                       };
+
+                       int doDraw[6] = {0,0,0,0,0,0};
+
+                       bool drawAllFaces = true;
+
+                       bool drawBottomFacesOnly = false; // Currently unused
+
+                       // Check for adjacent nodes
+                       for(int i = 0; i < 6; i++)
+                       {
+                               n2p = blockpos_nodes + p + dirs[i];
+                               n2 = data->m_vmanip.getNodeNoEx(n2p);
+                               n2c = n2.getContent();
+                               if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
+                                       doDraw[i] = 1;
+                                       if(drawAllFaces)
+                                               drawAllFaces = false;
+
+                               }
+                       }
+
+                       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(-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 + s*2,0, 0,0,0, c, 1,0),
+                                       video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
+                               };
+
+                               // Calculate which faces should be drawn, (top or sides)
+                               if(j == 0 && (drawAllFaces || (doDraw[3] == 1 || doDraw[1] == 1)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateXZBy(90 + n.param2 * 2);
+                                               vertices[i].Pos.rotateXYBy(-10);
+                                               vertices[i].Pos.Y -= vOffset;
+                                               vertices[i].Pos.X -= hOffset;
+                                       }
+                               }
+                               else if(j == 1 && (drawAllFaces || (doDraw[5] == 1 || doDraw[1] == 1)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
+                                               vertices[i].Pos.rotateYZBy(10);
+                                               vertices[i].Pos.Y -= vOffset;
+                                               vertices[i].Pos.Z -= hOffset;
+                                       }
+                               }
+                               else if(j == 2 && (drawAllFaces || (doDraw[2] == 1 || doDraw[1] == 1)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
+                                               vertices[i].Pos.rotateXYBy(10);
+                                               vertices[i].Pos.Y -= vOffset;
+                                               vertices[i].Pos.X += hOffset;
+                                       }
+                               }
+                               else if(j == 3 && (drawAllFaces || (doDraw[4] == 1 || doDraw[1] == 1)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateYZBy(-10);
+                                               vertices[i].Pos.Y -= vOffset;
+                                               vertices[i].Pos.Z += hOffset;
+                                       }
+                               }
+
+                               // Center cross-flames
+                               else if(j == 4 && (drawAllFaces || doDraw[1] == 1))
+                               {
+                                       for(int i=0; i<4; i++) {
+                                               vertices[i].Pos.rotateXZBy(45 + n.param2 * 2);
+                                               vertices[i].Pos.Y -= vOffset;
+                                       }
+                               }
+                               else if(j == 5 && (drawAllFaces || doDraw[1] == 1))
+                               {
+                                       for(int i=0; i<4; i++) {
+                                               vertices[i].Pos.rotateXZBy(-45 + n.param2 * 2);
+                                               vertices[i].Pos.Y -= vOffset;
+                                       }
+                               }
+
+                               // Render flames on bottom
+                               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.rotateXZBy(90 + n.param2 * 2);
+                                               vertices[i].Pos.Y += 4.84;
+                                               vertices[i].Pos.X -= hOffset+0.7;
+                                       }
+                               }
+                               else if(j == 1 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateYZBy(70);
+                                               vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
+                                               vertices[i].Pos.Y += 4.84;
+                                               vertices[i].Pos.Z -= hOffset+0.7;
+                                       }
+                               }
+                               else if(j == 2 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateYZBy(70);
+                                               vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
+                                               vertices[i].Pos.Y += 4.84;
+                                               vertices[i].Pos.X += hOffset+0.7;
+                                       }
+                               }
+                               else if(j == 3 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
+                               {
+                                       for(int i = 0; i < 4; i++) {
+                                               vertices[i].Pos.rotateYZBy(70);
+                                               vertices[i].Pos.Y += 4.84;
+                                               vertices[i].Pos.Z += hOffset+0.7;
+                                       }
+                               }
+                               else {
+                                       // Skip faces that aren't adjacent to a node
+                                       continue;
+                               }
+
+                               for(int i=0; i<4; i++)
+                               {
+                                       vertices[i].Pos *= f.visual_scale;
+                                       vertices[i].Pos += intToFloat(p, BS);
+                               }
+
+                               u16 indices[] = {0,1,2,2,3,0};
+                               // Add to mesh collector
+                               collector.append(tile, vertices, 4, indices, 6);
+                       }
+               break;}
                case NDT_FENCELIKE:
                {
                        TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
index f14311fc35ea16d56fde0889c8355af52eef52e3..31156ce68ce55a2a0fc03df85145dc44bcf50de5 100644 (file)
@@ -691,6 +691,8 @@ public:
                                if (f->waving == 1)
                                        material_type = TILE_MATERIAL_WAVING_PLANTS;
                                break;
+                       case NDT_FIRELIKE:
+                               f->backface_culling = false;
                        case NDT_TORCHLIKE:
                        case NDT_SIGNLIKE:
                        case NDT_FENCELIKE:
index 1f596e46baff75fc977e3bc3e5754b1e87c847da..262f4bc4e945d6a6aeee1828842bf13667b9b1ab 100644 (file)
@@ -149,6 +149,7 @@ enum NodeDrawType
        NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
                              // visible faces
                                                  // uses 2 textures, one for frames, second for faces
+       NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes
 };
 
 #define CF_SPECIAL_COUNT 6
index 5d51ebdd489f2a980b8d5584346c196935a3bd87..2b8d02d7494f7c3acc8a28e515b77d0b1079cb93 100644 (file)
@@ -40,6 +40,7 @@ struct EnumString ScriptApiNode::es_DrawType[] =
                {NDT_TORCHLIKE, "torchlike"},
                {NDT_SIGNLIKE, "signlike"},
                {NDT_PLANTLIKE, "plantlike"},
+               {NDT_FIRELIKE, "firelike"},
                {NDT_FENCELIKE, "fencelike"},
                {NDT_RAILLIKE, "raillike"},
                {NDT_NODEBOX, "nodebox"},
index 0ac54ec0810aab3900c052046910bc474e8ff2d0..cf3bbd76174239332573a337431375087de5f146 100644 (file)
@@ -644,7 +644,8 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
                "NDT_FENCELIKE",
                "NDT_RAILLIKE",
                "NDT_NODEBOX",
-               "NDT_GLASSLIKE_FRAMED"
+               "NDT_GLASSLIKE_FRAMED",
+               "NDT_FIRELIKE"
        };
        
        for (int i = 0; i < 14; i++){