From 64c5032c93553719be01075c72f794cd3e05a84c Mon Sep 17 00:00:00 2001 From: <> Date: Fri, 5 May 2017 18:08:44 -0700 Subject: [PATCH] Fixed bug that added an extra index for a 3 vertex face. --- ReflexToQ3/wip/oopless-parser.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ReflexToQ3/wip/oopless-parser.cpp b/ReflexToQ3/wip/oopless-parser.cpp index ccbb07f..f9025e8 100644 --- a/ReflexToQ3/wip/oopless-parser.cpp +++ b/ReflexToQ3/wip/oopless-parser.cpp @@ -92,6 +92,7 @@ vector parse_vertices(ifstream &f) { vector parse_face(ifstream &f) { #define FIRSTCH(x) x[0] +#define SECONDCH(x) x[1] // it is possible for the next line to be unrelated to faces // so it is needed to reset the stream prior to reading // the new label, e.g '\tbrush'. @@ -102,7 +103,8 @@ vector parse_face(ifstream &f) { if (line.find(KEYWORD_VERTICES) != string::npos || line.find(KEYWORD_BRUSH) != string::npos || line.find(KEYWORD_ENTITY) != string::npos || - line.find(KEYWORD_PREFAB) != string::npos) { + line.find(KEYWORD_PREFAB) != string::npos || + line.find(KEYWORD_GLOBAL) != string::npos) { f.seekg(pos); return output; } else { @@ -110,6 +112,7 @@ vector parse_face(ifstream &f) { float *f = &x.m_fXOffset;; stringstream ss(line); string fdata; + bool hex = false; unsigned int i = 0; while (ss >> fdata) { if (i < 5) { @@ -120,14 +123,24 @@ vector parse_face(ifstream &f) { } // note: if there is a non-digit in the first 5 fields // then it qualifies as an illegal line. - } else if (i == 9) { - ; - } else { - if (isdigit(FIRSTCH(fdata)) || FIRSTCH(fdata) == '-') { + } else if (4 < i && i < 8) { x.m_Indices.push_back(stoi(fdata)); + } else if (i == 8) { + // field #8 may either be the unidentified hex digit + // i.e there are 3 indices only, + // or it could be another index. + if (fdata.length() > 1 && SECONDCH(fdata) == 'x') { + // this is the unidentified hex digit. + // just it signify the texture at the end. + hex = true; } else { - x.m_Material = fdata; + x.m_Indices.push_back(stoi(fdata)); } + } else if ((i == 9 && hex) || i == 10) { + // it is a texture if it is field #9 + // and the hex digit is already encountered + // or it is field #10. + x.m_Material = fdata; } i++; } // end, per field iteration @@ -186,7 +199,6 @@ bool convertmap(const char * const infile, << "\"classname\" \"worldspawn\"" << endl; string line; while (getline(fin, line)) { - cout << line << endl; if (line.find(KEYWORD_PREFAB) != string::npos || line.find(KEYWORD_GLOBAL) != string::npos) { parse_prefab(fin, fout, brushdef);