Placed hardcoded keywords into defines & cleaned up scraps

This commit is contained in:
2017-04-06 17:05:11 -07:00
parent 4f2aec99e2
commit 31df64b272

View File

@ -3,9 +3,7 @@
// Email: chronokun@hotmail.com // Email: chronokun@hotmail.com
// //
// Libraries Include
#include "libraries.h" #include "libraries.h"
// This Include
#include "v8mapparser.h" #include "v8mapparser.h"
using namespace std; using namespace std;
@ -24,6 +22,13 @@ inline char *strcpy_s(char *dest, const char *src) {
} }
#endif #endif
#define KEYWORD_GLOBAL "\tglobal"
#define KEYWORD_PREFAB "\tprefab"
#define KEYWORD_ENTITY "\tentity"
#define KEYWORD_BRUSH "\tbrush"
#define KEYWORD_VERTICES "\tvertices"
#define KEYWORD_FACES "\tfaces"
const bool CMapParser::LoadMap(const char* _kpcFileName) const bool CMapParser::LoadMap(const char* _kpcFileName)
{ {
std::ifstream InFile; std::ifstream InFile;
@ -47,11 +52,11 @@ const bool CMapParser::LoadMap(const char* _kpcFileName)
bAdvance = true; bAdvance = true;
if(eState == PARSERSTATE_UNKNOWN) if(eState == PARSERSTATE_UNKNOWN)
{ {
if(Line.find("entity") != string::npos) if(Line.find(KEYWORD_ENTITY) != string::npos)
{ {
eState = PARSERSTATE_ENTITY; eState = PARSERSTATE_ENTITY;
continue; continue;
} else if (Line.find("prefab") != string::npos || Line.find("global") != string::npos) { } else if (Line.find(KEYWORD_PREFAB) != string::npos || Line.find(KEYWORD_GLOBAL) != string::npos) {
// prefab and global share an indentation level // prefab and global share an indentation level
// both encapsulate similar objects // both encapsulate similar objects
eState = PARSERSTATE_PREFAB; eState = PARSERSTATE_PREFAB;
@ -107,7 +112,7 @@ EParserState CMapParser::ParsePrefab(const std::string _Line) {
// if prefabs are simply broken and de-indented. // if prefabs are simply broken and de-indented.
// typically entities are listed first, then brushes, but just in case. // typically entities are listed first, then brushes, but just in case.
if (_Line.find("entity") != string::npos) { if (_Line.find(KEYWORD_ENTITY) != string::npos) {
return PARSERSTATE_ENTITY; return PARSERSTATE_ENTITY;
} else { } else {
return PARSERSTATE_BRUSH; return PARSERSTATE_BRUSH;
@ -125,7 +130,7 @@ EParserState CMapParser::ParseEntity(const std::string _Line)
strcpy_s(pcLine, _Line.c_str()); strcpy_s(pcLine, _Line.c_str());
pcToken = strtok_s(pcLine, kpcDelim, &pcContext); pcToken = strtok_s(pcLine, kpcDelim, &pcContext);
if (_Line.find("\tbrush") != string::npos) { if (_Line.find(KEYWORD_BRUSH) != string::npos) {
m_WorldSpawn.m_Brushes.push_back(TBrush()); m_WorldSpawn.m_Brushes.push_back(TBrush());
return PARSERSTATE_BRUSH; return PARSERSTATE_BRUSH;
} }
@ -153,7 +158,7 @@ EParserState CMapParser::ParseEntity(const std::string _Line)
EParserState CMapParser::ParseWorldSpawn(const std::string _Line) EParserState CMapParser::ParseWorldSpawn(const std::string _Line)
{ {
if(_Line.find("brush") != string::npos) if(_Line.find(KEYWORD_BRUSH) != string::npos)
{ {
m_WorldSpawn.m_Brushes.push_back(TBrush()); m_WorldSpawn.m_Brushes.push_back(TBrush());
return(PARSERSTATE_BRUSH); return(PARSERSTATE_BRUSH);
@ -163,16 +168,16 @@ EParserState CMapParser::ParseWorldSpawn(const std::string _Line)
EParserState CMapParser::ParseBrush(const std::string _Line) EParserState CMapParser::ParseBrush(const std::string _Line)
{ {
if(_Line.find("brush") != string::npos) if(_Line.find(KEYWORD_BRUSH) != string::npos)
{ {
m_WorldSpawn.m_Brushes.push_back(TBrush()); m_WorldSpawn.m_Brushes.push_back(TBrush());
return(PARSERSTATE_BRUSH); return(PARSERSTATE_BRUSH);
} }
if(_Line.find("\tvertices") != string::npos) if(_Line.find(KEYWORD_VERTICES) != string::npos)
{ {
return(PARSERSTATE_VERTEX); return(PARSERSTATE_VERTEX);
} }
else if(_Line.find("\tfaces") != string::npos) else if(_Line.find(KEYWORD_FACES) != string::npos)
{ {
return(PARSERSTATE_FACE); return(PARSERSTATE_FACE);
} }
@ -217,7 +222,6 @@ EParserState CMapParser::ParseVertex(const std::string _Line)
pcToken = strtok_s(NULL, kpcDelim, &pcContext); pcToken = strtok_s(NULL, kpcDelim, &pcContext);
} }
//this->m_WorldSpawn.m_Brushes[this->m_WorldSpawn.m_Brushes.size()-1].m_Vertices.push_back(Vert);
m_WorldSpawn.m_Brushes[m_WorldSpawn.m_Brushes.size()-1].m_Vertices.push_back(Vert); m_WorldSpawn.m_Brushes[m_WorldSpawn.m_Brushes.size()-1].m_Vertices.push_back(Vert);
return(PARSERSTATE_VERTEX); return(PARSERSTATE_VERTEX);
} }
@ -274,7 +278,6 @@ EParserState CMapParser::ParseFace(const std::string _Line)
TFace Face; TFace Face;
Face.m_Indices = Indices; Face.m_Indices = Indices;
Face.m_Material = material; Face.m_Material = material;
//this->m_WorldSpawn.m_Brushes[this->m_WorldSpawn.m_Brushes.size()-1].m_Faces.push_back(Face);
m_WorldSpawn.m_Brushes[m_WorldSpawn.m_Brushes.size()-1].m_Faces.push_back(Face); m_WorldSpawn.m_Brushes[m_WorldSpawn.m_Brushes.size()-1].m_Faces.push_back(Face);
return(PARSERSTATE_FACE); return(PARSERSTATE_FACE);
} }