reflex2q3/ReflexToQ3/main.cpp

107 lines
3.1 KiB
C++
Raw Normal View History

2015-02-02 08:11:03 +05:30
//
// Author: Michael Cameron
// Email: chronokun@hotmail.com
//
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
2017-05-06 08:03:26 +05:30
#include <cxxopts.hpp>
2017-05-06 08:03:26 +05:30
#include "oopless-parser.hpp"
2017-04-11 20:57:10 +05:30
#include "brushdef.hpp"
2015-02-02 08:11:03 +05:30
#define ARG_INPUT_SHORTALIAS "i"
#define ARG_OUTPUT_SHORTALIAS "o"
using namespace std;
cxxopts::Options arguments(int ac, char ** av) {
vector<string> parg = {"input", "output"};
cxxopts::Options o("reflex2q3",
"A tool to convert Reflex maps to idTech 3 maps.");
o.add_options()
("h,help", "displays help")
("i,input",
"required, input map file, from Reflex",
cxxopts::value<string>(), "FILE")
("o,output",
"required, output map file, for idTech 3 or similar map editors",
cxxopts::value<string>(), "FILE")
("gtk",
"optional, output in GTK Radiant's brush definition format")
("e,ent",
"optional, convert game entities given a table of equivalents",
cxxopts::value<string>(), "FILE")
;
o.parse_positional(parg);
o.parse(ac, av);
if (o.count("help")) {
cout << o.help() << endl;
}
if (o.count(ARG_INPUT_SHORTALIAS) < 1 ||
o.count(ARG_OUTPUT_SHORTALIAS) < 1) {
cerr << "error: no input or output file given" << endl;
exit(EXIT_FAILURE);
}
return o;
}
bool convert_worldspawn(const cxxopts::Options &o,
queue<vector<string> > &q) {
//ease of reading
typedef void (*brushdef) (std::stringstream &,
const std::vector<TPlanePoints> &);
bool is_ok = false;
brushdef fn = &brushdef_net;
if (o.count("gtk")) {
fn = &brushdef_gtk;
}
try {
is_ok = convertmap(
o[ARG_INPUT_SHORTALIAS].as<string>().c_str(), // in file
o[ARG_OUTPUT_SHORTALIAS].as<string>().c_str(), // out file
fn, // brush definition
q); // queue of entities
} catch (exception &e) {
cout << e.what() << endl;
cout << "exception encountered while converting map geometry"
" - unrecoverable failure" << endl;
}
if (is_ok) {
cout << "Successfully converted map "
<< o[ARG_INPUT_SHORTALIAS].as<string>()
<< " to "
<< o[ARG_OUTPUT_SHORTALIAS].as<string>()
<< endl;
} else {
cout << "Failed to convert map." << endl;
}
return is_ok;
}
// wip: current a print out of all entities
bool convert_entities(const cxxopts::Options &o, queue<vector<string> > &q) {
vector<string> entity;
do {
entity = q.front();
for (const string &s : entity) {
cout << s << endl;
}
q.pop();
} while (!q.empty());
return true;
}
int main(int argc, char** argv)
{
string entityfile;
cxxopts::Options p = arguments(argc, argv);
queue<vector<string> > entities;
bool is_ok = convert_worldspawn(p, entities);
convert_entities(p, entities);
2015-02-02 08:11:03 +05:30
return(0);
}