From bc432345a4d7f309db1dc787c5b2e1a187e87368 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 29 Jul 2018 17:15:29 +0100 Subject: [PATCH] namespace for both types --- source/game/render/bmf_loader.cpp | 12 ++++++++---- source/game/render/obj_loader.cpp | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/source/game/render/bmf_loader.cpp b/source/game/render/bmf_loader.cpp index 91ddf6d..b64b171 100644 --- a/source/game/render/bmf_loader.cpp +++ b/source/game/render/bmf_loader.cpp @@ -43,10 +43,7 @@ const char* bmfHead = "BMF "; namespace render { -struct UV { - float u, v; -}; - +namespace bmf { struct VertexIndex { unsigned a, b, c; @@ -57,7 +54,14 @@ struct VertexIndex { return memcmp(this, &other, sizeof(unsigned) * 3) < 0; } }; +} +using namespace bmf; + + +struct UV { + float u, v; +}; void loadBinaryMesh(const char* filename, Mesh& mesh) { static_assert(sizeof(vec3f) == 12, "vec3f must be the size of 3 floats"); diff --git a/source/game/render/obj_loader.cpp b/source/game/render/obj_loader.cpp index ba0c96c..6c2129f 100644 --- a/source/game/render/obj_loader.cpp +++ b/source/game/render/obj_loader.cpp @@ -9,15 +9,19 @@ namespace render { +namespace obj { struct VertexIndex { - unsigned int a, b, c; + int a, b, c; - VertexIndex(unsigned int A, unsigned int B, unsigned int C) : a(A), b(B), c(C) {} + VertexIndex(int A, int B, int C) : a(A), b(B), c(C) {} bool operator<(const VertexIndex& other) const { return memcmp(this, &other, sizeof(int) * 3) < 0; } }; +} + +using namespace obj; void loadMeshOBJ(const char* filename, Mesh& mesh) { // Read all the appropriate separate data arrays @@ -74,11 +78,11 @@ void loadMeshOBJ(const char* filename, Mesh& mesh) { case 'f': // Face int vertsThisLine = 3; - unsigned int vertexIndex[4]; - unsigned int uvIndex[4]; - unsigned int normalIndex[4]; + int vertexIndex[4]; + int uvIndex[4]; + int normalIndex[4]; - unsigned int elemIndex[4]; + int elemIndex[4]; int items = sscanf(line.c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d", &vertexIndex[0], &uvIndex[0], &normalIndex[0], @@ -87,9 +91,9 @@ void loadMeshOBJ(const char* filename, Mesh& mesh) { &vertexIndex[3], &uvIndex[3], &normalIndex[3]); vertsThisLine = items / 3; - size_t vertCount = vertices.size(); - size_t normCount = normals.size(); - size_t uvCount = ucoord.size(); + int vertCount = (int)vertices.size(); + int normCount = (int)normals.size(); + int uvCount = (int)ucoord.size(); for(int i = 0; i < vertsThisLine; ++i) { if(vertexIndex[i] > 0)