]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Models.cpp
Updating newdetail more often to avoid storing bad value, and added a newline at...
[lugaru.git] / Source / Models.cpp
index 20c30f7eba719626e22a2d7548f1a93ba155d37a..2c301689ea38f8cd3695e7ebd5693fc2d838ec0c 100644 (file)
@@ -1,5 +1,6 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
@@ -19,6 +20,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "Game.h"
 #include "Models.h"
+#include "Utils/Folders.h"
 
 extern float multiplier;
 extern float viewdistance;
@@ -153,7 +155,6 @@ int Model::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate)
     static int firstintersecting;
     static XYZ point;
     static XYZ oldp1;
-    static XYZ start, end;
 
     firstintersecting = -1;
 
@@ -207,7 +208,6 @@ int Model::SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate)
     static int firstintersecting;
     static XYZ point;
     static XYZ oldp1;
-    static XYZ start, end;
 
     firstintersecting = -1;
 
@@ -400,19 +400,16 @@ void Model::UpdateVertexArrayNoTexNoNorm()
     }
 }
 
-bool Model::loadnotex(const char *filename )
+bool Model::loadnotex(const std::string& filename )
 {
     FILE *tfile;
     long i;
 
-    //~ int oldvertexNum, oldTriangleNum;
-    //~ oldvertexNum = vertexNum;
-    //~ oldTriangleNum = TriangleNum;
-
     type = notextype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
+    tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
+
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
@@ -434,7 +431,6 @@ bool Model::loadnotex(const char *filename )
     }
 
     for (i = 0; i < TriangleNum; i++) {
-        //funpackf(tfile, "Bi Bi Bi", &Triangles[i].vertex[0], &Triangles[i].vertex[1], &Triangles[i].vertex[2]);
         short vertex[ 6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[ 0], &vertex[ 1], &vertex[ 2], &vertex[ 3], &vertex[ 4], &vertex[ 5]);
         Triangles[i].vertex[ 0] = vertex[ 0];
@@ -464,11 +460,11 @@ bool Model::loadnotex(const char *filename )
     }
     boundingsphereradius = fast_sqrt(boundingsphereradius);
 
-    return 1;
+    return true;
 }
 
 
-bool Model::load(const char *filename, bool texture )
+bool Model::load(const std::string& filename, bool texture )
 {
     FILE *tfile;
     long i;
@@ -480,16 +476,12 @@ bool Model::load(const char *filename, bool texture )
     if (visibleloading)
         Game::LoadingScreen();
 
-    //~ int oldvertexNum, oldTriangleNum;
-    //~ oldvertexNum = vertexNum;
-    //~ oldTriangleNum = TriangleNum;
-
     type = normaltype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
-    // read model settings
+    tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
 
+    // read model settings
 
     fseek(tfile, 0, SEEK_SET);
     funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
@@ -512,7 +504,6 @@ bool Model::load(const char *filename, bool texture )
     }
 
     for (i = 0; i < TriangleNum; i++) {
-        //funpackf(tfile, "Bi Bi Bi", &Triangles[i].vertex[0], &Triangles[i].vertex[1], &Triangles[i].vertex[2]);
         short vertex[ 6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[ 0], &vertex[ 1], &vertex[ 2], &vertex[ 3], &vertex[ 4], &vertex[ 5]);
         Triangles[i].vertex[ 0] = vertex[ 0];
@@ -544,28 +535,25 @@ bool Model::load(const char *filename, bool texture )
     }
     boundingsphereradius = fast_sqrt(boundingsphereradius);
 
-    return 1;
+    return true;
 }
 
-bool Model::loaddecal(const char *filename, bool texture )
+bool Model::loaddecal(const std::string& filename, bool texture )
 {
     FILE *tfile;
     long i, j;
 
     LOGFUNC;
 
-    // Changing the filename so that its more os specific
-    char * FixedFN = ConvertFileName(filename);
-
-    LOG(std::string("Loading decal...") + FixedFN);
+    LOG(std::string("Loading decal...") + Folders::getResourcePath(filename));
 
     type = decalstype;
     numdecals = 0;
     color = 0;
 
-    tfile = fopen( FixedFN, "rb" );
-    // read model settings
+    tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
 
+    // read model settings
 
     fseek(tfile, 0, SEEK_SET);
     funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
@@ -590,7 +578,6 @@ bool Model::loaddecal(const char *filename, bool texture )
     }
 
     for (i = 0; i < TriangleNum; i++) {
-        //funpackf(tfile, "Bi Bi Bi", &Triangles[i].vertex[0], &Triangles[i].vertex[1], &Triangles[i].vertex[2]);
         short vertex[ 6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[ 0], &vertex[ 1], &vertex[ 2], &vertex[ 3], &vertex[ 4], &vertex[ 5]);
         Triangles[i].vertex[ 0] = vertex[ 0];
@@ -643,10 +630,10 @@ bool Model::loaddecal(const char *filename, bool texture )
         decalposition = (XYZ*)malloc(sizeof(XYZ) * max_model_decals);
     }
 
-    return 1;
+    return true;
 }
 
-bool Model::loadraw(char *filename )
+bool Model::loadraw(const std::string& filename)
 {
     FILE *tfile;
     long i;
@@ -655,16 +642,12 @@ bool Model::loadraw(char *filename )
 
     LOG(std::string("Loading raw...") + filename);
 
-    //~ int oldvertexNum, oldTriangleNum;
-    //~ oldvertexNum = vertexNum;
-    //~ oldTriangleNum = TriangleNum;
-
     type = rawtype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
-    // read model settings
+    tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
 
+    // read model settings
 
     fseek(tfile, 0, SEEK_SET);
     funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
@@ -686,7 +669,6 @@ bool Model::loadraw(char *filename )
     }
 
     for (i = 0; i < TriangleNum; i++) {
-        //funpackf(tfile, "Bi Bi Bi", &Triangles[i].vertex[0], &Triangles[i].vertex[1], &Triangles[i].vertex[2]);
         short vertex[ 6];
         funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[ 0], &vertex[ 1], &vertex[ 2], &vertex[ 3], &vertex[ 4], &vertex[ 5]);
         Triangles[i].vertex[ 0] = vertex[ 0];
@@ -703,7 +685,7 @@ bool Model::loadraw(char *filename )
         owner[i] = -1;
     }
 
-    return 1;
+    return true;
 }