Attempted to fix partial conversion bug

This commit is contained in:
_ 2017-12-15 23:42:19 -08:00
parent 579b23fccb
commit e6511e3306
3 changed files with 41 additions and 33 deletions

View File

@ -25,12 +25,7 @@ void write(const std::vector<std::string> &,
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
EntityConverter &);
void parse_prefab(std::ifstream &,
std::ofstream &,
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
std::vector<std::vector<std::string> > &);
bool convertmap(const char * const,
bool convertmap(std::stringstream &,
const char * const,
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
std::vector<std::vector<std::string> > &);
@ -180,4 +175,19 @@ using namespace std;
return output;
}
#endif
template <class ISTR>
void parse_prefab(ISTR &f,
std::ofstream &out,
void (*b) (std::stringstream &, const std::vector<TPlanePoints> &),
std::vector<std::vector<std::string> > &entities) {
using namespace std;
string l;
getline(f, l);
if (l.find(KEYWORD_BRUSH) != string::npos) {
write(parse_brush<ISTR>(f), out, b);
} else if (l.find(KEYWORD_ENTITY) != string::npos) {
entities.push_back(get_entity<ISTR>(f));
}
}
#endif

View File

@ -57,6 +57,22 @@ cxxopts::Options arguments(int ac, char ** av) {
return o;
}
stringstream loadmap(const char *filename) {
ifstream fin;
fin.open(filename);
if (!fin.good()) {
cout << "error: can not open input file." << endl;
}
vector<string> v;
string line;
stringstream output;
while (getline(fin, line)) {
v.push_back(line);
}
move(v.begin(), v.end(), ostream_iterator<string>(output, "\n"));
return output;
}
bool convert_worldspawn(const cxxopts::Options &o,
vector<vector<string> > &q) {
bool is_ok = false;
@ -64,9 +80,11 @@ bool convert_worldspawn(const cxxopts::Options &o,
if (o.count(ARG_BRUSHFORMAT)) {
fn = &brushdef_gtk;
}
string inputfile = o[ARG_INPUT_SHORTALIAS].as<string>();
stringstream mapdata = loadmap(inputfile.c_str());
try {
is_ok = convertmap(
o[ARG_INPUT_SHORTALIAS].as<string>().c_str(), // in file
mapdata, // in file
o[ARG_OUTPUT_SHORTALIAS].as<string>().c_str(), // out file
fn, // brush definition
q); // queue of entities

View File

@ -101,29 +101,10 @@ void write(const vector<string> &entity,
fo << "}" << endl;
}
void parse_prefab(ifstream &f,
ofstream &out,
void (*b) (stringstream &, const vector<TPlanePoints> &),
vector<vector<string> > &entities) {
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) {
entities.push_back(get_entity<ifstream>(f));
}
}
bool convertmap(const char * const infile,
bool convertmap(stringstream &mapdata,
const char * const outfile,
void (*brushdef) (stringstream &, const vector<TPlanePoints> &),
vector<vector<string> > &entities) {
ifstream fin;
fin.open(infile);
if (!fin.good()){
cerr << "error: failed to open input file" << endl;
return false;
}
ofstream fout;
fout.open(outfile);
if (!fout.good()) {
@ -133,18 +114,17 @@ bool convertmap(const char * const infile,
fout << "{\n"
<< "\"classname\" \"worldspawn\"" << endl;
string line;
while (getline(fin, line)) {
while (getline(mapdata, line)) {
if (line.find(KEYWORD_PREFAB) != string::npos ||
line.find(KEYWORD_GLOBAL) != string::npos) {
parse_prefab(fin, fout, brushdef, entities);
parse_prefab<stringstream>(mapdata, fout, brushdef, entities);
} else if (line.find(KEYWORD_ENTITY) != string::npos) {
entities.push_back(get_entity<ifstream>(fin));
entities.push_back(get_entity<stringstream>(mapdata));
} else if (line.find(KEYWORD_BRUSH) != string::npos) {
write(parse_brush<ifstream>(fin), fout, brushdef);
write(parse_brush<stringstream>(mapdata), fout, brushdef);
}
}
fout << "}" << endl;
fin.close();
fout.close();
return true;
}