Integrated entity converter; missing brush component.
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
|
||||
#include "oopless-parser.hpp"
|
||||
#include "brushdef.hpp"
|
||||
#include "EntityConverter.hpp"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
using namespace std;
|
||||
|
||||
bool is_ebrush(std::vector<std::string> input) {
|
||||
// defines are only used in this function.
|
||||
#define KEYWORD_ENTBRUSH1 "type Teleporter"
|
||||
#define KEYWORD_ENTBRUSH2 "type JumpPad"
|
||||
for (const string &str : input) {
|
||||
@@ -38,8 +36,46 @@ bool write(const struct TBrush &geometry,
|
||||
return ok;
|
||||
}
|
||||
|
||||
void write(const vector<string> &entity, ofstream &fo) {
|
||||
;
|
||||
void write(const vector<string> &entity,
|
||||
ofstream &fo,
|
||||
void (*b) (stringstream &, const vector<TPlanePoints> &),
|
||||
EntityConverter &e) {
|
||||
/* Likely inefficient.
|
||||
Current process for the entities:
|
||||
1. It acquires the lines.
|
||||
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 + 1)), entity.end(), brush.begin());
|
||||
}
|
||||
vector<string> converted = e.convert(entity);
|
||||
if (converted.empty()) {
|
||||
return;
|
||||
}
|
||||
fo << "{" << endl;
|
||||
for (const string &s : converted) {
|
||||
fo << s;
|
||||
}
|
||||
if (brushent) {
|
||||
stringstream ss;
|
||||
string line;
|
||||
copy(brush.begin(), brush.end(), ostream_iterator<string>(ss, "\n"));
|
||||
getline(ss, line);
|
||||
write(parse_brush<stringstream>(ss), fo, b);
|
||||
}
|
||||
fo << "}" << endl;
|
||||
}
|
||||
|
||||
// entities will vary widely depending on their type and available flags.
|
||||
@@ -66,26 +102,33 @@ vector<string> get_entity(ifstream &f) {
|
||||
|
||||
void parse_prefab(ifstream &f,
|
||||
ofstream &out,
|
||||
void (*b) (stringstream &, const vector<TPlanePoints> &)) {
|
||||
void (*b) (stringstream &, const vector<TPlanePoints> &),
|
||||
EntityConverter &e) {
|
||||
string l;
|
||||
getline(f, l);
|
||||
if (l.find(KEYWORD_BRUSH) != string::npos) {
|
||||
write(parse_brush<ifstream>(f), out, b);
|
||||
} else if (l.find(KEYWORD_ENTITY) != string::npos) {
|
||||
write(get_entity(f), out);
|
||||
write(get_entity(f), out, b, e);
|
||||
}
|
||||
}
|
||||
|
||||
// note: can't use a single function pointer for variadic overloaded write function?
|
||||
bool convertmap(const char * const infile,
|
||||
const char * const outfile,
|
||||
void (*brushdef) (stringstream &, const vector<TPlanePoints> &)) {
|
||||
void (*brushdef) (stringstream &, const vector<TPlanePoints> &),
|
||||
const char * const entfile) {
|
||||
ifstream fin;
|
||||
fin.open(infile);
|
||||
if (!fin.good()){
|
||||
cerr << "error: failed to open input file" << endl;
|
||||
return false;
|
||||
}
|
||||
EntityConverter ec;
|
||||
if (entfile != NULL) {
|
||||
string ef(entfile);
|
||||
string in(infile);
|
||||
ec = EntityConverter(ef, in);
|
||||
}
|
||||
ofstream fout;
|
||||
fout.open(outfile);
|
||||
if (!fout.good()) {
|
||||
@@ -98,9 +141,9 @@ bool convertmap(const char * const infile,
|
||||
while (getline(fin, line)) {
|
||||
if (line.find(KEYWORD_PREFAB) != string::npos ||
|
||||
line.find(KEYWORD_GLOBAL) != string::npos) {
|
||||
parse_prefab(fin, fout, brushdef);
|
||||
parse_prefab(fin, fout, brushdef, ec);
|
||||
} else if (line.find(KEYWORD_ENTITY) != string::npos) {
|
||||
write(get_entity(fin), fout);
|
||||
write(get_entity(fin), fout, brushdef, ec);
|
||||
} else if (line.find(KEYWORD_BRUSH) != string::npos) {
|
||||
write(parse_brush<ifstream>(fin), fout, brushdef);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user