Parser transitions from prefab, entity, brush, to vertex, but crashes on vertex.
This commit is contained in:
parent
e7a3bc2d63
commit
92914e0e5d
@ -7,6 +7,7 @@
|
||||
#include "libraries.h"
|
||||
// This Include
|
||||
#include "v8mapparser.h"
|
||||
using namespace std;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
/*
|
||||
@ -46,15 +47,17 @@ const bool CMapParser::LoadMap(const char* _kpcFileName)
|
||||
bAdvance = true;
|
||||
if(eState == PARSERSTATE_UNKNOWN)
|
||||
{
|
||||
if(strcmp(Line.c_str(), "entity") == 0)
|
||||
if(Line.find("entity") != string::npos)
|
||||
{
|
||||
eState = PARSERSTATE_ENTITY;
|
||||
continue;
|
||||
} else if (Line.compare("prefab") == 0 || Line.compare("global") == 0) {
|
||||
} else if (Line.find("prefab") != string::npos || Line.find("global") != string::npos) {
|
||||
// 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;
|
||||
}
|
||||
} else if (eState == PARSERSTATE_PREFAB) {
|
||||
eState = this->ParsePrefab(Line);
|
||||
@ -104,7 +107,7 @@ EParserState CMapParser::ParsePrefab(const std::string _Line) {
|
||||
// if prefabs are simply broken and de-indented.
|
||||
|
||||
// typically entities are listed first, then brushes, but just in case.
|
||||
if (_Line.compare("entity") == 0) {
|
||||
if (_Line.find("entity") != string::npos) {
|
||||
return PARSERSTATE_ENTITY;
|
||||
} else {
|
||||
return PARSERSTATE_BRUSH;
|
||||
@ -122,6 +125,9 @@ EParserState CMapParser::ParseEntity(const std::string _Line)
|
||||
strcpy_s(pcLine, _Line.c_str());
|
||||
pcToken = strtok_s(pcLine, kpcDelim, &pcContext);
|
||||
|
||||
if (_Line.find("\tbrush") != string::npos) {
|
||||
return PARSERSTATE_BRUSH;
|
||||
}
|
||||
while(pcToken != nullptr)
|
||||
{
|
||||
if(strcmp(pcToken, "\ttype") == 0)
|
||||
@ -146,9 +152,9 @@ EParserState CMapParser::ParseEntity(const std::string _Line)
|
||||
|
||||
EParserState CMapParser::ParseWorldSpawn(const std::string _Line)
|
||||
{
|
||||
if(strcmp(_Line.c_str(), "brush") == 0)
|
||||
if(_Line.find("brush") != string::npos)
|
||||
{
|
||||
this->m_WorldSpawn.m_Brushes.push_back(TBrush());
|
||||
m_WorldSpawn.m_Brushes.push_back(TBrush());
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
return(PARSERSTATE_WORLDSPAWN);
|
||||
@ -156,16 +162,16 @@ EParserState CMapParser::ParseWorldSpawn(const std::string _Line)
|
||||
|
||||
EParserState CMapParser::ParseBrush(const std::string _Line)
|
||||
{
|
||||
if(strcmp(_Line.c_str(), "brush") == 0)
|
||||
if(_Line.find("brush") != string::npos)
|
||||
{
|
||||
this->m_WorldSpawn.m_Brushes.push_back(TBrush());
|
||||
m_WorldSpawn.m_Brushes.push_back(TBrush());
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
if(strcmp(_Line.c_str(), "\tvertices") == 0)
|
||||
if(_Line.find("\tvertices") != string::npos)
|
||||
{
|
||||
return(PARSERSTATE_VERTEX);
|
||||
}
|
||||
else if(strcmp(_Line.c_str(), "\tfaces") == 0)
|
||||
else if(_Line.find("\tfaces") != string::npos)
|
||||
{
|
||||
return(PARSERSTATE_FACE);
|
||||
}
|
||||
@ -182,7 +188,6 @@ EParserState CMapParser::ParseVertex(const std::string _Line)
|
||||
|
||||
strcpy_s(pcLine, _Line.c_str());
|
||||
pcToken = strtok_s(pcLine, kpcDelim, &pcContext);
|
||||
|
||||
Eigen::Vector3f Vert;
|
||||
int iTokenNum = 0;
|
||||
while(pcToken != nullptr)
|
||||
@ -212,7 +217,8 @@ EParserState CMapParser::ParseVertex(const std::string _Line)
|
||||
pcToken = strtok_s(nullptr, kpcDelim, &pcContext);
|
||||
}
|
||||
|
||||
this->m_WorldSpawn.m_Brushes[this->m_WorldSpawn.m_Brushes.size()-1].m_Vertices.push_back(Vert);
|
||||
//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);
|
||||
return(PARSERSTATE_VERTEX);
|
||||
}
|
||||
|
||||
@ -268,6 +274,7 @@ EParserState CMapParser::ParseFace(const std::string _Line)
|
||||
TFace Face;
|
||||
Face.m_Indices = Indices;
|
||||
Face.m_Material = material;
|
||||
this->m_WorldSpawn.m_Brushes[this->m_WorldSpawn.m_Brushes.size()-1].m_Faces.push_back(Face);
|
||||
//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);
|
||||
return(PARSERSTATE_FACE);
|
||||
}
|
||||
|
@ -10,17 +10,17 @@
|
||||
|
||||
// Includes
|
||||
#include "worldspawn.h"
|
||||
|
||||
#include "libraries.h"
|
||||
// enums
|
||||
enum EParserState
|
||||
{
|
||||
PARSERSTATE_UNKNOWN,
|
||||
PARSERSTATE_ENTITY,
|
||||
PARSERSTATE_WORLDSPAWN,
|
||||
PARSERSTATE_BRUSH,
|
||||
PARSERSTATE_VERTEX,
|
||||
PARSERSTATE_FACE,
|
||||
PARSERSTATE_PREFAB
|
||||
PARSERSTATE_UNKNOWN, // 0
|
||||
PARSERSTATE_ENTITY, // 1
|
||||
PARSERSTATE_WORLDSPAWN, // 2
|
||||
PARSERSTATE_BRUSH, // 3
|
||||
PARSERSTATE_VERTEX, // 4
|
||||
PARSERSTATE_FACE, // 5
|
||||
PARSERSTATE_PREFAB // 6
|
||||
};
|
||||
|
||||
class CMapParser
|
||||
@ -40,7 +40,6 @@ protected:
|
||||
EParserState ParseBrush(const std::string _Line);
|
||||
EParserState ParseVertex(const std::string _Line);
|
||||
EParserState ParseFace(const std::string _Line);
|
||||
EParserState ParsePrefab(const std::string _Line);
|
||||
};
|
||||
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "libraries.h"
|
||||
#ifndef __WORLDSPAWN_H__
|
||||
#define __WORLDSPAWN_H__
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user