]> git.lizzy.rs Git - minetest.git/blobdiff - src/mesh.cpp
Drop texture file list cache (#6660)
[minetest.git] / src / mesh.cpp
index 824d6891bdc1113d4917aa33c4c747e2cbb2ee49..7fc7531f2e8b00dcd2c33710a3340721571efd69 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iostream>
 #include <IAnimatedMesh.h>
 #include <SAnimatedMesh.h>
+#include <IAnimatedMeshSceneNode.h>
 
 // In Irrlicht 1.8 the signature of ITexture::lock was changed from
 // (bool, u32) to (E_TEXTURE_LOCK_MODE, u32).
@@ -175,6 +176,21 @@ void translateMesh(scene::IMesh *mesh, v3f vec)
        mesh->setBoundingBox(bbox);
 }
 
+void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color)
+{
+       const u32 stride = getVertexPitchFromType(buf->getVertexType());
+       u32 vertex_count = buf->getVertexCount();
+       u8 *vertices = (u8 *) buf->getVertices();
+       for (u32 i = 0; i < vertex_count; i++)
+               ((video::S3DVertex *) (vertices + i * stride))->Color = color;
+}
+
+void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color)
+{
+       for (u32 i = 0; i < node->getMaterialCount(); ++i) {
+               node->getMaterial(i).EmissiveColor = color;
+       }
+}
 
 void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
 {
@@ -182,14 +198,8 @@ void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
                return;
 
        u32 mc = mesh->getMeshBufferCount();
-       for (u32 j = 0; j < mc; j++) {
-               scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
-               const u32 stride = getVertexPitchFromType(buf->getVertexType());
-               u32 vertex_count = buf->getVertexCount();
-               u8 *vertices = (u8 *)buf->getVertices();
-               for (u32 i = 0; i < vertex_count; i++)
-                       ((video::S3DVertex *)(vertices + i * stride))->Color = color;
-       }
+       for (u32 j = 0; j < mc; j++)
+               setMeshBufferColor(mesh->getMeshBuffer(j), color);
 }
 
 void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor)
@@ -451,11 +461,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
 
        video::SColor c(255,255,255,255);
 
-       for (std::vector<aabb3f>::const_iterator
-                       i = boxes.begin();
-                       i != boxes.end(); ++i)
-       {
-               aabb3f box = *i;
+       for (aabb3f box : boxes) {
                box.repair();
 
                box.MinEdge.X -= expand;
@@ -612,9 +618,8 @@ class f_lru
 public:
        f_lru(vcache *v, tcache *t): vc(v), tc(t)
        {
-               for (u16 i = 0; i < cachesize; i++)
-               {
-                       cache[i] = -1;
+               for (int &i : cache) {
+                       i = -1;
                }
        }
 
@@ -669,15 +674,14 @@ class f_lru
                        }
 
                        // Update triangle scores
-                       for (u16 i = 0; i < cachesize; i++)
-                       {
-                               if (cache[i] == -1)
+                       for (int i : cache) {
+                               if (i == -1)
                                        break;
 
-                               const u16 trisize = vc[cache[i]].tris.size();
+                               const u16 trisize = vc[i].tris.size();
                                for (u16 t = 0; t < trisize; t++)
                                {
-                                       tcache *tri = &tc[vc[cache[i]].tris[t]];
+                                       tcache *tri = &tc[vc[i].tris[t]];
 
                                        tri->score =
                                                vc[tri->ind[0]].score +
@@ -687,7 +691,7 @@ class f_lru
                                        if (tri->score > hiscore)
                                        {
                                                hiscore = tri->score;
-                                               highest = vc[cache[i]].tris[t];
+                                               highest = vc[i].tris[t];
                                        }
                                }
                        }
@@ -874,9 +878,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
 
                                        tc[highest].drawn = true;
 
-                                       for (u16 j = 0; j < 3; j++)
-                                       {
-                                               vcache *vert = &vc[tc[highest].ind[j]];
+                                       for (u16 j : tc[highest].ind) {
+                                               vcache *vert = &vc[j];
                                                for (u16 t = 0; t < vert->tris.size(); t++)
                                                {
                                                        if (highest == vert->tris[t])
@@ -986,9 +989,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
 
                                        tc[highest].drawn = true;
 
-                                       for (u16 j = 0; j < 3; j++)
-                                       {
-                                               vcache *vert = &vc[tc[highest].ind[j]];
+                                       for (u16 j : tc[highest].ind) {
+                                               vcache *vert = &vc[j];
                                                for (u16 t = 0; t < vert->tris.size(); t++)
                                                {
                                                        if (highest == vert->tris[t])
@@ -1099,9 +1101,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
 
                                        tc[highest].drawn = true;
 
-                                       for (u16 j = 0; j < 3; j++)
-                                       {
-                                               vcache *vert = &vc[tc[highest].ind[j]];
+                                       for (u16 j : tc[highest].ind) {
+                                               vcache *vert = &vc[j];
                                                for (u16 t = 0; t < vert->tris.size(); t++)
                                                {
                                                        if (highest == vert->tris[t])