diff dmmodel.cpp @ 47:9909014498f0

Add helper functions dmError() and dmMsg() and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2019 23:52:45 +0200
parents d640f2a34031
children 0ae1ff609626
line wrap: on
line diff
--- a/dmmodel.cpp	Thu Dec 05 22:45:21 2019 +0200
+++ b/dmmodel.cpp	Thu Dec 05 23:52:45 2019 +0200
@@ -10,9 +10,9 @@
 #include <SDL_endian.h>
 
 
-static bool dmError(DMTextFileInfo &info, const std::string &msg)
+static bool dmTextError(DMTextFileInfo &info, const std::string &msg)
 {
-    printf("ERROR: %s on line #%d: %s\n",
+    dmError("%s on line #%d: %s\n",
         msg.c_str(), info.nline, info.line.c_str());
     return false;
 }
@@ -20,7 +20,7 @@
 
 static bool dmSyntaxError(DMTextFileInfo &info, const std::string &msg)
 {
-    printf("ERROR: Syntax error on line #%d: %s\n",
+    dmError("Syntax error on line #%d: %s\n",
         info.nline, msg.c_str());
     return false;
 }
@@ -97,7 +97,7 @@
             break;
 
         default:
-            return dmError(info,
+            return dmTextError(info,
                 "Internal error, unimplemented PLY property type");
     }
 
@@ -146,7 +146,7 @@
     // Read one line
     if (!dmReadLine(info))
     {
-        return dmError(info,
+        return dmTextError(info,
             "Unexpected end of file");
     }
 
@@ -225,7 +225,7 @@
             break;
 
         default:
-            return dmError(info,
+            return dmTextError(info,
                 "Internal error, unimplemented PLY property type");
     }
 
@@ -301,12 +301,12 @@
     info.nline = info.state = 0;
     info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary);
 
-    printf("INFO: Trying to read mesh from '%s'.\n",
+    dmMsg("Trying to read mesh from '%s'.\n",
         info.filename.c_str());
 
     if (!info.file.is_open())
     {
-        printf("ERROR: Unable to open file '%s'.\n",
+        dmError("Unable to open file '%s'.\n",
             info.filename.c_str());
         return false;
     }
@@ -358,7 +358,7 @@
             if (info.format == PLY_FMT_UNKNOWN ||
                 tokens[2] != "1.0")
             {
-                printf("ERROR: Unknown or unsupported PLY file format '%s'.\n",
+                dmError("Unknown or unsupported PLY file format '%s'.\n",
                     (tokens[1] +" "+ tokens[2]).c_str());
                 return false;
             }
@@ -480,7 +480,7 @@
         (prop = elem->checkProp("z")) == 0 || prop->type != PLY_TYPE_FLOAT
         )
     {
-        printf("ERROR: PLY file did not contain expected information.\n");
+        dmError("PLY file did not contain expected information.\n");
         return false;
     }
 
@@ -490,12 +490,12 @@
 
     if (nvertices < 3 || nfaces < 1)
     {
-        printf("ERROR: Invalid nvertices (%d) and/or nfaces (%d).\n",
+        dmError("Invalid nvertices (%d) and/or nfaces (%d).\n",
             nvertices, nfaces);
         return false;
     }
 
-    printf("INFO: Should have %d vertices, %d faces\n",
+    dmMsg("Should have %d vertices, %d faces\n",
         nvertices, nfaces);
 
     // Pre-allocate space
@@ -560,7 +560,7 @@
         }
     }
 
-    printf("INFO: Found %ld vertices, %ld normals, %ld faces\n",
+    dmMsg("Found %ld vertices, %ld normals, %ld faces\n",
         vertices.size(),
         normals.size(),
         faces.size() / 3);
@@ -629,12 +629,12 @@
     info.nline = info.state = 0;
     info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary);
 
-    printf("INFO: Trying to read scene data from '%s'.\n",
+    dmMsg("Trying to read scene data from '%s'.\n",
         info.filename.c_str());
 
     if (!info.file.is_open())
     {
-        printf("ERROR: Unable to open file '%s'.\n",
+        dmError("Unable to open file '%s'.\n",
             info.filename.c_str());
         return false;
     }
@@ -755,7 +755,7 @@
 
             if (lights.size() >= 4)
             {
-                return dmError(info,
+                return dmTextError(info,
                 "Too many lights defined (max 4)");
             }