Changed output queue to vector

This commit is contained in:
2017-07-06 13:52:31 -07:00
parent 7595b42593
commit 984ff03c80
3 changed files with 12 additions and 15 deletions

View File

@ -103,20 +103,20 @@ vector<string> get_entity(ifstream &f) {
void parse_prefab(ifstream &f, void parse_prefab(ifstream &f,
ofstream &out, ofstream &out,
void (*b) (stringstream &, const vector<TPlanePoints> &), void (*b) (stringstream &, const vector<TPlanePoints> &),
queue<vector<string> > &entities) { vector<vector<string> > &entities) {
string l; string l;
getline(f, l); getline(f, l);
if (l.find(KEYWORD_BRUSH) != string::npos) { if (l.find(KEYWORD_BRUSH) != string::npos) {
write(parse_brush<ifstream>(f), out, b); write(parse_brush<ifstream>(f), out, b);
} else if (l.find(KEYWORD_ENTITY) != string::npos) { } else if (l.find(KEYWORD_ENTITY) != string::npos) {
entities.push(get_entity(f)); entities.push_back(get_entity(f));
} }
} }
bool convertmap(const char * const infile, bool convertmap(const char * const infile,
const char * const outfile, const char * const outfile,
void (*brushdef) (stringstream &, const vector<TPlanePoints> &), void (*brushdef) (stringstream &, const vector<TPlanePoints> &),
queue<vector<string> > &entities) { vector<vector<string> > &entities) {
ifstream fin; ifstream fin;
fin.open(infile); fin.open(infile);
if (!fin.good()){ if (!fin.good()){
@ -137,7 +137,7 @@ bool convertmap(const char * const infile,
line.find(KEYWORD_GLOBAL) != string::npos) { line.find(KEYWORD_GLOBAL) != string::npos) {
parse_prefab(fin, fout, brushdef, entities); parse_prefab(fin, fout, brushdef, entities);
} else if (line.find(KEYWORD_ENTITY) != string::npos) { } else if (line.find(KEYWORD_ENTITY) != string::npos) {
entities.push(get_entity(fin)); entities.push_back(get_entity(fin));
} else if (line.find(KEYWORD_BRUSH) != string::npos) { } else if (line.find(KEYWORD_BRUSH) != string::npos) {
write(parse_brush<ifstream>(fin), fout, brushdef); write(parse_brush<ifstream>(fin), fout, brushdef);
} }

View File

@ -26,12 +26,12 @@ std::vector<std::string> get_entity(std::ifstream &);
void parse_prefab(std::ifstream &, void parse_prefab(std::ifstream &,
std::ofstream &, std::ofstream &,
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &), void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
std::queue<std::vector<std::string> > &); std::vector<std::vector<std::string> > &);
bool convertmap(const char * const, bool convertmap(const char * const,
const char * const, const char * const,
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &), void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
std::queue<std::vector<std::string> > &); std::vector<std::vector<std::string> > &);
#define KEYWORD_ENTITY "entity" #define KEYWORD_ENTITY "entity"
#define KEYWORD_BRUSH "brush" #define KEYWORD_BRUSH "brush"

View File

@ -54,7 +54,7 @@ cxxopts::Options arguments(int ac, char ** av) {
} }
bool convert_worldspawn(const cxxopts::Options &o, bool convert_worldspawn(const cxxopts::Options &o,
queue<vector<string> > &q) { vector<vector<string> > &q) {
bool is_ok = false; bool is_ok = false;
brushdef fn = &brushdef_net; brushdef fn = &brushdef_net;
if (o.count(ARG_BRUSHFORMAT)) { if (o.count(ARG_BRUSHFORMAT)) {
@ -83,7 +83,7 @@ bool convert_worldspawn(const cxxopts::Options &o,
return is_ok; return is_ok;
} }
void print_entities(queue<vector<string> > &q) { void print_entities(vector<vector<string> > &q) {
vector<string> entity; vector<string> entity;
do { do {
entity = q.front(); entity = q.front();
@ -92,12 +92,11 @@ void print_entities(queue<vector<string> > &q) {
cout << s << endl; cout << s << endl;
} }
cout << "--------------------------" << endl; cout << "--------------------------" << endl;
q.pop();
} while (!q.empty()); } while (!q.empty());
} }
void convert_entities(const cxxopts::Options &o, queue<vector<string> > &q) { void convert_entities(const cxxopts::Options &o, vector<vector<string> > &q) {
string entfile = o["e"].as<string>(); string entfile = o["e"].as<string>();
if (entfile.empty()) { if (entfile.empty()) {
cout << "No entity data file given" cout << "No entity data file given"
@ -111,18 +110,16 @@ void convert_entities(const cxxopts::Options &o, queue<vector<string> > &q) {
if (o.count(ARG_BRUSHFORMAT)) { if (o.count(ARG_BRUSHFORMAT)) {
fn = &brushdef_gtk; fn = &brushdef_gtk;
} }
do { for (const vector<string> &entity : q) {
entity = q.front();
write(entity, fout, fn, e); write(entity, fout, fn, e);
q.pop(); }
} while(!q.empty());
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
cxxopts::Options p = arguments(argc, argv); cxxopts::Options p = arguments(argc, argv);
queue<vector<string> > entities; vector<vector<string> > entities;
bool is_ok = convert_worldspawn(p, entities); bool is_ok = convert_worldspawn(p, entities);
// print_entities(entities); // print_entities(entities);
convert_entities(p, entities); convert_entities(p, entities);