reflex2q3/ReflexToQ3/includes/v8mapparser.cpp

96 lines
2.4 KiB
C++
Raw Normal View History

#include "v8mapparser.hpp"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
const bool V8MapParser::LoadMap(const char* _kpcFileName) {
2017-04-05 18:08:54 +05:30
std::ifstream InFile;
EParserState eState = PARSERSTATE_UNKNOWN;
InFile.open(_kpcFileName, std::ios::in);
if(InFile.is_open())
{
std::string Line;
bool bAdvance = true;
bool bGoing = true;
while(bGoing)
{
if(bAdvance)
{
if(!std::getline(InFile, Line))
{
bGoing = false;
// without this break, loop control allows the final empty string to get passed into ParseFunctions()
break;
2017-04-05 18:08:54 +05:30
}
}
bAdvance = true;
if(eState == PARSERSTATE_UNKNOWN)
{
if(Line.find(KEYWORD_ENTITY) != string::npos)
2017-04-05 18:08:54 +05:30
{
eState = PARSERSTATE_ENTITY;
continue;
} else if (Line.find(KEYWORD_PREFAB) != string::npos || Line.find(KEYWORD_GLOBAL) != string::npos) {
2017-04-05 18:08:54 +05:30
// prefab and global share an indentation level
// both encapsulate similar objects
eState = PARSERSTATE_PREFAB;
continue;
} else {
cout << "Warning: PARSERSTATE_UNKNOWN and no cases met." << endl;
2017-04-05 18:08:54 +05:30
}
} else if (eState == PARSERSTATE_PREFAB) {
eState = this->ParsePrefab(Line);
}
else if(eState == PARSERSTATE_ENTITY)
{
eState = this->ParseEntity(Line);
}
else if(eState == PARSERSTATE_WORLDSPAWN)
{
eState = this->ParseWorldSpawn(Line);
}
else if(eState == PARSERSTATE_BRUSH)
{
eState = this->ParseBrush(Line);
//bAdvance = false;
}
else if(eState == PARSERSTATE_VERTEX)
{
eState = this->ParseVertex(Line);
if(eState != PARSERSTATE_VERTEX)
{
bAdvance = false;
}
}
else if(eState == PARSERSTATE_FACE)
{
eState = this->ParseFace(Line);
if(eState != PARSERSTATE_FACE)
{
bAdvance = false;
}
}
}
InFile.close();
}
else
{
return(false);
}
return(true);
}
EParserState V8MapParser::ParsePrefab(const std::string _Line) {
2017-04-05 18:08:54 +05:30
// this is going with the idea that its possible to correctly parse the map file
// if prefabs are simply broken and de-indented.
// typically entities are listed first, then brushes, but just in case.
if (_Line.find(KEYWORD_ENTITY) != string::npos) {
2017-04-05 18:08:54 +05:30
return PARSERSTATE_ENTITY;
} else {
return PARSERSTATE_BRUSH;
}
}