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"
|
#include "libraries.h"
|
||||||
// This Include
|
// This Include
|
||||||
#include "v8mapparser.h"
|
#include "v8mapparser.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
/*
|
/*
|
||||||
@ -46,15 +47,17 @@ const bool CMapParser::LoadMap(const char* _kpcFileName)
|
|||||||
bAdvance = true;
|
bAdvance = true;
|
||||||
if(eState == PARSERSTATE_UNKNOWN)
|
if(eState == PARSERSTATE_UNKNOWN)
|
||||||
{
|
{
|
||||||
if(strcmp(Line.c_str(), "entity") == 0)
|
if(Line.find("entity") != string::npos)
|
||||||
{
|
{
|
||||||
eState = PARSERSTATE_ENTITY;
|
eState = PARSERSTATE_ENTITY;
|
||||||
continue;
|
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
|
// prefab and global share an indentation level
|
||||||
// both encapsulate similar objects
|
// both encapsulate similar objects
|
||||||
eState = PARSERSTATE_PREFAB;
|
eState = PARSERSTATE_PREFAB;
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
cout << "Warning: PARSERSTATE_UNKNOWN and no cases met." << endl;
|
||||||
}
|
}
|
||||||
} else if (eState == PARSERSTATE_PREFAB) {
|
} else if (eState == PARSERSTATE_PREFAB) {
|
||||||
eState = this->ParsePrefab(Line);
|
eState = this->ParsePrefab(Line);
|
||||||
@ -104,7 +107,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.compare("entity") == 0) {
|
if (_Line.find("entity") != string::npos) {
|
||||||
return PARSERSTATE_ENTITY;
|
return PARSERSTATE_ENTITY;
|
||||||
} else {
|
} else {
|
||||||
return PARSERSTATE_BRUSH;
|
return PARSERSTATE_BRUSH;
|
||||||
@ -122,6 +125,9 @@ 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) {
|
||||||
|
return PARSERSTATE_BRUSH;
|
||||||
|
}
|
||||||
while(pcToken != nullptr)
|
while(pcToken != nullptr)
|
||||||
{
|
{
|
||||||
if(strcmp(pcToken, "\ttype") == 0)
|
if(strcmp(pcToken, "\ttype") == 0)
|
||||||
@ -146,9 +152,9 @@ EParserState CMapParser::ParseEntity(const std::string _Line)
|
|||||||
|
|
||||||
EParserState CMapParser::ParseWorldSpawn(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_BRUSH);
|
||||||
}
|
}
|
||||||
return(PARSERSTATE_WORLDSPAWN);
|
return(PARSERSTATE_WORLDSPAWN);
|
||||||
@ -156,16 +162,16 @@ EParserState CMapParser::ParseWorldSpawn(const std::string _Line)
|
|||||||
|
|
||||||
EParserState CMapParser::ParseBrush(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);
|
return(PARSERSTATE_BRUSH);
|
||||||
}
|
}
|
||||||
if(strcmp(_Line.c_str(), "\tvertices") == 0)
|
if(_Line.find("\tvertices") != string::npos)
|
||||||
{
|
{
|
||||||
return(PARSERSTATE_VERTEX);
|
return(PARSERSTATE_VERTEX);
|
||||||
}
|
}
|
||||||
else if(strcmp(_Line.c_str(), "\tfaces") == 0)
|
else if(_Line.find("\tfaces") != string::npos)
|
||||||
{
|
{
|
||||||
return(PARSERSTATE_FACE);
|
return(PARSERSTATE_FACE);
|
||||||
}
|
}
|
||||||
@ -182,7 +188,6 @@ EParserState CMapParser::ParseVertex(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);
|
||||||
|
|
||||||
Eigen::Vector3f Vert;
|
Eigen::Vector3f Vert;
|
||||||
int iTokenNum = 0;
|
int iTokenNum = 0;
|
||||||
while(pcToken != nullptr)
|
while(pcToken != nullptr)
|
||||||
@ -212,7 +217,8 @@ EParserState CMapParser::ParseVertex(const std::string _Line)
|
|||||||
pcToken = strtok_s(nullptr, kpcDelim, &pcContext);
|
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);
|
return(PARSERSTATE_VERTEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +274,7 @@ 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);
|
//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);
|
return(PARSERSTATE_FACE);
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,17 @@
|
|||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
#include "worldspawn.h"
|
#include "worldspawn.h"
|
||||||
|
#include "libraries.h"
|
||||||
// enums
|
// enums
|
||||||
enum EParserState
|
enum EParserState
|
||||||
{
|
{
|
||||||
PARSERSTATE_UNKNOWN,
|
PARSERSTATE_UNKNOWN, // 0
|
||||||
PARSERSTATE_ENTITY,
|
PARSERSTATE_ENTITY, // 1
|
||||||
PARSERSTATE_WORLDSPAWN,
|
PARSERSTATE_WORLDSPAWN, // 2
|
||||||
PARSERSTATE_BRUSH,
|
PARSERSTATE_BRUSH, // 3
|
||||||
PARSERSTATE_VERTEX,
|
PARSERSTATE_VERTEX, // 4
|
||||||
PARSERSTATE_FACE,
|
PARSERSTATE_FACE, // 5
|
||||||
PARSERSTATE_PREFAB
|
PARSERSTATE_PREFAB // 6
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMapParser
|
class CMapParser
|
||||||
@ -40,7 +40,6 @@ protected:
|
|||||||
EParserState ParseBrush(const std::string _Line);
|
EParserState ParseBrush(const std::string _Line);
|
||||||
EParserState ParseVertex(const std::string _Line);
|
EParserState ParseVertex(const std::string _Line);
|
||||||
EParserState ParseFace(const std::string _Line);
|
EParserState ParseFace(const std::string _Line);
|
||||||
EParserState ParsePrefab(const std::string _Line);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "libraries.h"
|
||||||
#ifndef __WORLDSPAWN_H__
|
#ifndef __WORLDSPAWN_H__
|
||||||
#define __WORLDSPAWN_H__
|
#define __WORLDSPAWN_H__
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user