Integrated entity converter; missing brush component.
This commit is contained in:
parent
29d8fd4c02
commit
0e214e5955
@ -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);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include "EntityConverter.hpp"
|
||||
|
||||
bool is_ebrush(std::vector<std::string>);
|
||||
|
||||
@ -14,17 +15,22 @@ bool write(const struct TBrush &,
|
||||
std::ofstream &,
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &));
|
||||
|
||||
void write(const std::vector<std::string> &, std::ofstream &);
|
||||
void write(const std::vector<std::string> &,
|
||||
std::ofstream &,
|
||||
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> &));
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
|
||||
EntityConverter &);
|
||||
|
||||
bool convertmap(const char * const,
|
||||
const char * const,
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &));
|
||||
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &),
|
||||
const char * const);
|
||||
|
||||
#define KEYWORD_ENTITY "entity"
|
||||
#define KEYWORD_BRUSH "brush"
|
||||
@ -33,8 +39,8 @@ bool convertmap(const char * const,
|
||||
#define KEYWORD_GLOBAL "global"
|
||||
#define KEYWORD_PREFAB "prefab"
|
||||
|
||||
template <class T>
|
||||
std::vector<Eigen::Vector3f> parse_vertices(T &f) {
|
||||
template <class STREAMOBJ>
|
||||
std::vector<Eigen::Vector3f> parse_vertices(STREAMOBJ &f) {
|
||||
using namespace std;
|
||||
#define FIRSTCH(x) x[0]
|
||||
vector<Eigen::Vector3f> output;
|
||||
@ -69,8 +75,8 @@ using namespace std;
|
||||
return output;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::vector<struct TFace> parse_face(T &f) {
|
||||
template <class STREAMOBJ>
|
||||
std::vector<struct TFace> parse_face(STREAMOBJ &f) {
|
||||
using namespace std;
|
||||
#define FIRSTCH(x) x[0]
|
||||
#define SECONDCH(x) x[1]
|
||||
@ -132,18 +138,18 @@ using namespace std;
|
||||
return output;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct TBrush parse_brush(T &f) {
|
||||
template <class STREAMOBJ>
|
||||
struct TBrush parse_brush(STREAMOBJ &f) {
|
||||
using namespace std;
|
||||
struct TBrush output;
|
||||
string l;
|
||||
getline(f, l);
|
||||
if (l.find(KEYWORD_VERTICES) != string::npos) {
|
||||
output.m_Vertices = parse_vertices<T>(f);
|
||||
output.m_Vertices = parse_vertices<STREAMOBJ>(f);
|
||||
}
|
||||
getline(f, l);
|
||||
if (l.find(KEYWORD_FACES) != string::npos) {
|
||||
output.m_Faces = parse_face<T>(f);
|
||||
output.m_Faces = parse_face<STREAMOBJ>(f);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -24,17 +24,22 @@ int main(const int _kiArgC, const char** _kppcArgv)
|
||||
{
|
||||
return(3);
|
||||
}
|
||||
/* // placeholder argument parsing until something more robust is decided upon
|
||||
// optional arg #1: brush definition - gtkradiant or netradiant style
|
||||
// placeholder argument parsing until something more robust is decided upon
|
||||
/* // optional arg #1: brush definition - gtkradiant or netradiant style
|
||||
void (*brushdef) (std::stringstream &, const std::vector<TPlanePoints> &);
|
||||
brushdef = ((string(_kppcArgv[ARG_POS_BRUSHDEF - 1])).compare("-gtk") == 0) ?
|
||||
&brushdef_gtk: &brushdef_net;
|
||||
|
||||
*/
|
||||
// optional arg #2: entity mapping file - enables entity conversion
|
||||
const char * const entitymap = (_kiArgC < ARG_POS_ENTITYCONV) ?
|
||||
_kppcArgv[ARG_POS_ENTITYCONV - 1]: NULL; */
|
||||
const char * const entitymap = (_kiArgC >= ARG_POS_ENTITYCONV) ?
|
||||
_kppcArgv[ARG_POS_ENTITYCONV - 1]: NULL;
|
||||
|
||||
bool status = convertmap(_kppcArgv[1], _kppcArgv[2], &brushdef_net);
|
||||
bool status;
|
||||
try {
|
||||
status = convertmap(_kppcArgv[1], _kppcArgv[2], &brushdef_net, entitymap);
|
||||
} catch (exception &e) {
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
if (status) {
|
||||
cout << "Successfully converted map "
|
||||
<< _kppcArgv[1]
|
||||
|
Loading…
Reference in New Issue
Block a user