]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Graphic/Sprite.cpp
Replaced patchobjects arrays by vectors, cleaned code a bit
[lugaru.git] / Source / Graphic / Sprite.cpp
index 4276ce5e8cbb18a8fa037162728c8abddf3f7262..862d4bbbf71026ba8301f14b4f5677fe1f407661 100644 (file)
@@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License
 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "Game.h"
-#include "Graphic/Sprite.h"
-#include "Objects/Person.h"
+#include "Graphic/Sprite.hpp"
+
+#include "Game.hpp"
+#include "Objects/Person.hpp"
 
 extern XYZ viewer;
 extern float viewdistance;
@@ -31,7 +32,6 @@ extern Light light;
 extern float multiplier;
 extern float gravity;
 extern Terrain terrain;
-extern Objects objects;
 extern int detail;
 extern XYZ viewerfacing;
 extern int bloodtoggle;
@@ -245,14 +245,14 @@ void Sprite::Draw()
                 if (distancemult >= 1)
                     glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
                 else
-                    glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
+                    glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], distancemult);
             }
         }
         if (sprites[i]->type == splintersprite && (sprites[i]->special == 0 || sprites[i]->special == 3)) {
             if (distancemult >= 1)
                 glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
             else
-                glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
+                glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], distancemult);
         }
 
         glBegin(GL_TRIANGLES);
@@ -349,27 +349,28 @@ void Sprite::Draw()
 
                 whichpatchx = sprites[i]->position.x / (terrain.size / subdivision * terrain.scale);
                 whichpatchz = sprites[i]->position.z / (terrain.size / subdivision * terrain.scale);
-                if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision)
-                    if (terrain.patchobjectnum[whichpatchx][whichpatchz]) {
-                        if (!spritehit)
-                            for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) {
-                                k = terrain.patchobjects[whichpatchx][whichpatchz][j];
-                                start = sprites[i]->oldposition;
-                                end = sprites[i]->position;
-                                if (!spritehit)
-                                    if (objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]) != -1) {
-                                        if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0))
-                                            objects.model[k].MakeDecal(blooddecalfast, DoRotation(colpoint - objects.position[k], 0, -objects.yaw[k], 0), sprites[i]->size * 1.6, .5, Random() % 360);
-                                        DeleteSprite(i);
-                                        spritehit = 1;
-                                    }
-                            }
+                if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision) {
+                    if (!spritehit) {
+                        for (unsigned int j = 0; j < terrain.patchobjects[whichpatchx][whichpatchz].size(); j++) {
+                            k = terrain.patchobjects[whichpatchx][whichpatchz][j];
+                            start = sprites[i]->oldposition;
+                            end = sprites[i]->position;
+                            if (!spritehit)
+                                if (Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw) != -1) {
+                                    if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0))
+                                        Object::objects[k]->model.MakeDecal(blooddecalfast, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), sprites[i]->size * 1.6, .5, Random() % 360);
+                                    DeleteSprite(i);
+                                    spritehit = 1;
+                                }
+                        }
                     }
-                if (!spritehit)
+                }
+                if (!spritehit) {
                     if (sprites[i]->position.y < terrain.getHeight(sprites[i]->position.x, sprites[i]->position.z)) {
                         terrain.MakeDecal(blooddecalfast, sprites[i]->position, sprites[i]->size * 1.6, .6, Random() % 360);
                         DeleteSprite(i);
                     }
+                }
             }
         }
         if (sprites[i]->type == splintersprite) {
@@ -462,19 +463,3 @@ Sprite::Sprite()
     speed = 0;
     rotatespeed = 0;
 }
-
-void Sprite::clearTextures()
-{
-    toothtexture.destroy();
-    cloudtexture.destroy();
-    cloudimpacttexture.destroy();
-    bloodtexture.destroy();
-    flametexture.destroy();
-    bloodflametexture.destroy();
-    smoketexture.destroy();
-    snowflaketexture.destroy();
-    shinetexture.destroy();
-    splintertexture.destroy();
-    leaftexture.destroy();
-}
-