]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Models.cpp
Using at() instead of operator[] in currentFrame to get more precise crashes
[lugaru.git] / Source / Models.cpp
index d0a991b8217a5b6eed602b44b613913ce6664dd9..2c301689ea38f8cd3695e7ebd5693fc2d838ec0c 100644 (file)
@@ -20,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;
@@ -399,7 +400,7 @@ void Model::UpdateVertexArrayNoTexNoNorm()
     }
 }
 
-bool Model::loadnotex(const char *filename )
+bool Model::loadnotex(const std::string& filename )
 {
     FILE *tfile;
     long i;
@@ -407,7 +408,8 @@ bool Model::loadnotex(const char *filename )
     type = notextype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
+    tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
+
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
@@ -458,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;
@@ -477,9 +479,9 @@ bool Model::load(const char *filename, bool texture )
     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);
@@ -533,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);
@@ -631,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;
@@ -646,9 +645,9 @@ bool Model::loadraw(char *filename )
     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 +685,7 @@ bool Model::loadraw(char *filename )
         owner[i] = -1;
     }
 
-    return 1;
+    return true;
 }