Templated parse entity
This commit is contained in:
parent
6ef6745d29
commit
0993b17333
@ -6,6 +6,7 @@
|
||||
using namespace std;
|
||||
|
||||
bool is_ebrush(const std::vector<std::string> &input) {
|
||||
using namespace std;
|
||||
#define KEYWORD_ENTBRUSH1 "type Teleporter"
|
||||
#define KEYWORD_ENTBRUSH2 "type JumpPad"
|
||||
#define KEYWORD_ENTBRUSH3 "type RaceStart"
|
||||
@ -21,6 +22,25 @@ bool is_ebrush(const std::vector<std::string> &input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vector<string> extract_brush(const vector<string> &entity) {
|
||||
bool brushent = false;
|
||||
unsigned int i;
|
||||
for (i = 0; i < entity.size(); ++i) {
|
||||
if (entity[i].find(KEYWORD_BRUSH) != string::npos) {
|
||||
brushent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
vector<string> output(entity.size() - i);
|
||||
if (brushent) {
|
||||
// entity.begin() + i = vector that begins with KEYWORD_BRUSH
|
||||
// parsing functions will expect only the contents underneath the keyword.
|
||||
move((entity.begin() + i), entity.end(), output.begin());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// place holding functions to test proper control flow.
|
||||
bool write(const struct TBrush &geometry,
|
||||
ofstream &fout,
|
||||
@ -62,20 +82,7 @@ void write(const vector<string> &entity,
|
||||
2. Searches through and splits the vector.
|
||||
3. Recombines the brush vector.
|
||||
(4. Sends the vector to parse the brush through again.)*/
|
||||
bool brushent = false;
|
||||
unsigned int i;
|
||||
for (i = 0; i < entity.size(); ++i) {
|
||||
if (entity[i].find(KEYWORD_BRUSH) != string::npos) {
|
||||
brushent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
vector<string> brush(entity.size() - i);
|
||||
if (brushent) {
|
||||
// entity.begin() + i = vector that begins with KEYWORD_BRUSH
|
||||
// parsing functions will expect only the contents underneath the keyword.
|
||||
move((entity.begin() + i), entity.end(), brush.begin());
|
||||
}
|
||||
vector<string> brush = extract_brush(entity);
|
||||
vector<string> converted = e.convert(entity);
|
||||
if (converted.empty()) {
|
||||
return;
|
||||
@ -84,7 +91,7 @@ void write(const vector<string> &entity,
|
||||
for (const string &s : converted) {
|
||||
fo << s;
|
||||
}
|
||||
if (brushent) {
|
||||
if (brush.size() > 0) {
|
||||
stringstream ss;
|
||||
string line;
|
||||
copy(brush.begin(), brush.end(), ostream_iterator<string>(ss, "\n"));
|
||||
@ -94,28 +101,6 @@ void write(const vector<string> &entity,
|
||||
fo << "}" << endl;
|
||||
}
|
||||
|
||||
// entities will vary widely depending on their type and available flags.
|
||||
// for now, acquire entity data, and handle their conversion in the write methods.
|
||||
vector<string> get_entity(ifstream &f) {
|
||||
vector<string> output;
|
||||
string line;
|
||||
unsigned int pos = f.tellg();
|
||||
while (getline(f, line)) {
|
||||
// stop when
|
||||
// entity or a prefab keyword
|
||||
// brush keyword and the entity is not of the type teleporter or jumppad.
|
||||
if ((line.find(KEYWORD_ENTITY) != string::npos ||
|
||||
line.find(KEYWORD_PREFAB) != string::npos) || (
|
||||
line.find(KEYWORD_BRUSH) != string::npos && !is_ebrush(output))) {
|
||||
f.seekg(pos);
|
||||
return output;
|
||||
} else {
|
||||
output.push_back(line);
|
||||
}
|
||||
pos = f.tellg();
|
||||
}
|
||||
}
|
||||
|
||||
void parse_prefab(ifstream &f,
|
||||
ofstream &out,
|
||||
void (*b) (stringstream &, const vector<TPlanePoints> &),
|
||||
@ -125,7 +110,7 @@ void parse_prefab(ifstream &f,
|
||||
if (l.find(KEYWORD_BRUSH) != string::npos) {
|
||||
write(parse_brush<ifstream>(f), out, b);
|
||||
} else if (l.find(KEYWORD_ENTITY) != string::npos) {
|
||||
entities.push_back(get_entity(f));
|
||||
entities.push_back(get_entity<ifstream>(f));
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,7 +138,7 @@ bool convertmap(const char * const infile,
|
||||
line.find(KEYWORD_GLOBAL) != string::npos) {
|
||||
parse_prefab(fin, fout, brushdef, entities);
|
||||
} else if (line.find(KEYWORD_ENTITY) != string::npos) {
|
||||
entities.push_back(get_entity(fin));
|
||||
entities.push_back(get_entity<ifstream>(fin));
|
||||
} else if (line.find(KEYWORD_BRUSH) != string::npos) {
|
||||
write(parse_brush<ifstream>(fin), fout, brushdef);
|
||||
}
|
||||
|
@ -10,7 +10,9 @@
|
||||
#include <queue>
|
||||
#include "EntityConverter.hpp"
|
||||
|
||||
bool is_ebrush(const std::vector<std::string>&);
|
||||
bool is_ebrush(const std::vector<std::string> &);
|
||||
|
||||
std::vector<std::string> extract_brush(const std::vector<std::string> &);
|
||||
|
||||
struct TBrush override_textures(struct TBrush, const char*);
|
||||
|
||||
@ -23,8 +25,6 @@ void write(const std::vector<std::string> &,
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
|
||||
EntityConverter &);
|
||||
|
||||
std::vector<std::string> get_entity(std::ifstream &);
|
||||
|
||||
void parse_prefab(std::ifstream &,
|
||||
std::ofstream &,
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
|
||||
@ -35,6 +35,7 @@ bool convertmap(const char * const,
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
|
||||
std::vector<std::vector<std::string> > &);
|
||||
|
||||
|
||||
#define KEYWORD_ENTITY "entity"
|
||||
#define KEYWORD_BRUSH "brush"
|
||||
#define KEYWORD_VERTICES "vertices"
|
||||
@ -42,6 +43,28 @@ bool convertmap(const char * const,
|
||||
#define KEYWORD_GLOBAL "global"
|
||||
#define KEYWORD_PREFAB "prefab"
|
||||
|
||||
template <class STREAMOBJ>
|
||||
std::vector<std::string> get_entity(STREAMOBJ &f) {
|
||||
using namespace std;
|
||||
vector<string> output;
|
||||
string line;
|
||||
unsigned int pos = f.tellg();
|
||||
while (getline(f, line)) {
|
||||
// stop when
|
||||
// entity or a prefab keyword
|
||||
// brush keyword and the entity is not of the type teleporter or jumppad.
|
||||
if ((line.find(KEYWORD_ENTITY) != string::npos ||
|
||||
line.find(KEYWORD_PREFAB) != string::npos) || (
|
||||
line.find(KEYWORD_BRUSH) != string::npos && !is_ebrush(output))) {
|
||||
f.seekg(pos);
|
||||
return output;
|
||||
} else {
|
||||
output.push_back(line);
|
||||
}
|
||||
pos = f.tellg();
|
||||
}
|
||||
}
|
||||
|
||||
template <class STREAMOBJ>
|
||||
std::vector<Eigen::Vector3f> parse_vertices(STREAMOBJ &f) {
|
||||
using namespace std;
|
||||
|
Loading…
Reference in New Issue
Block a user