Improved EC and tests readability
This commit is contained in:
parent
a241dc857d
commit
957e262560
@ -62,7 +62,7 @@ class EntityConverter
|
|||||||
* THROWS: std::ios::failure on IO failure
|
* THROWS: std::ios::failure on IO failure
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
EntityConverter(const std::string &entityMapFile);
|
EntityConverter (const std::string &entityMapFile);
|
||||||
/* *--------------------------------------------------------------------------------------
|
/* *--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
* Method: Constructor
|
* Method: Constructor
|
||||||
@ -73,7 +73,7 @@ class EntityConverter
|
|||||||
* THROWS: std::ios::failure on IO failure
|
* THROWS: std::ios::failure on IO failure
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
EntityConverter(const std::string &entityMapFile, const std::string &reflexMapFile);
|
EntityConverter (const std::string &entityMapFile, const std::string &reflexMapFile);
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -86,7 +86,7 @@ class EntityConverter
|
|||||||
* THROWS: runtime_error when called before map info has been extracted
|
* THROWS: runtime_error when called before map info has been extracted
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> convert(const std::vector<std::string> &lines);
|
std::vector<std::string> convert (const std::vector<std::string> &lines);
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -97,7 +97,7 @@ class EntityConverter
|
|||||||
* THROWS: runtime_error when encountering malformed entity
|
* THROWS: runtime_error when encountering malformed entity
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void extractMapInfo(std::queue<std::vector<std::string>> entities);
|
void extractMapInfo (std::queue<std::vector<std::string>> entities);
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -108,7 +108,7 @@ class EntityConverter
|
|||||||
* THROWS: runtime_error when encountering malformed entity
|
* THROWS: runtime_error when encountering malformed entity
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void extractMapInfo(const std::vector<std::vector<std::string>> &entities);
|
void extractMapInfo (const std::vector<std::vector<std::string>> &entities);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -124,14 +124,14 @@ class EntityConverter
|
|||||||
* Return: vector of strings, the converted entity
|
* Return: vector of strings, the converted entity
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> convertPickup(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertPickup (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertPlayerSpawn(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertPlayerSpawn (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertJumpPad(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertJumpPad (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertTeleporter(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertTeleporter (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertTarget(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertTarget (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertRaceStart(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertRaceStart (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertRaceFinish(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertRaceFinish (const std::vector<std::string> &lines) const;
|
||||||
std::vector<std::string> convertPointLight(const std::vector<std::string> &lines) const;
|
std::vector<std::string> convertPointLight (const std::vector<std::string> &lines) const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
@ -141,7 +141,7 @@ class EntityConverter
|
|||||||
* Parameter: string "line", entity keyword followed by the type
|
* Parameter: string "line", entity keyword followed by the type
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::string getAttributeType(const std::string &line) const;
|
std::string getAttributeType (const std::string &line) const;
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -151,7 +151,7 @@ class EntityConverter
|
|||||||
* Return: true if no error, false if error
|
* Return: true if no error, false if error
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void mapEntities(const std::string &mapFile);
|
void mapEntities (const std::string &mapFile);
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -170,7 +170,7 @@ class EntityConverter
|
|||||||
* single entity
|
* single entity
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void extractFromEntity(const std::string &line, std::istream &is);
|
void extractFromEntity (const std::string &line, std::istream &is);
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -182,7 +182,7 @@ class EntityConverter
|
|||||||
* Return: string, float value passed as string
|
* Return: string, float value passed as string
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::string offset(const std::string &value, const float offset) const;
|
std::string offset (const std::string &value, const float offset) const;
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -192,7 +192,7 @@ class EntityConverter
|
|||||||
* Return: string, the adjusted angle in degrees
|
* Return: string, the adjusted angle in degrees
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::string adjustAngleForHandedness(const std::string &angle) const;
|
std::string adjustAngleForHandedness (const std::string &angle) const;
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -204,7 +204,7 @@ class EntityConverter
|
|||||||
* Parameter: float b, RETURN BY REFERENCE: converted blue value
|
* Parameter: float b, RETURN BY REFERENCE: converted blue value
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void hexToRGB(const std::string &hex, float &r, float &g, float &b) const;
|
void hexToRGB (const std::string &hex, float &r, float &g, float &b) const;
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -213,7 +213,7 @@ class EntityConverter
|
|||||||
* Parameter: string value, original brightness value
|
* Parameter: string value, original brightness value
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
int adjustBrightness(const std::string &value) const;
|
int adjustBrightness (const std::string &value) const;
|
||||||
/*
|
/*
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
* Class: EntityConverter
|
* Class: EntityConverter
|
||||||
@ -221,7 +221,7 @@ class EntityConverter
|
|||||||
* Description: Combine a message and the entity responsible into an error message
|
* Description: Combine a message and the entity responsible into an error message
|
||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::string makeErrorMessage(const std::string message,
|
std::string makeErrorMessage (const std::string message,
|
||||||
const std::vector<std::string> entity) const;
|
const std::vector<std::string> entity) const;
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
EntityConverter::EntityConverter(const std::string &entityMapFile) :
|
EntityConverter::EntityConverter (const std::string &entityMapFile) :
|
||||||
OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0),
|
OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0),
|
||||||
OUTPUT_PRECISION(10)
|
OUTPUT_PRECISION(10)
|
||||||
{
|
{
|
||||||
@ -46,12 +46,12 @@ EntityConverter::EntityConverter(const std::string &entityMapFile) :
|
|||||||
ws_.tdm = true;
|
ws_.tdm = true;
|
||||||
ws_.duel = true;
|
ws_.duel = true;
|
||||||
|
|
||||||
mapEntities(entityMapFile);
|
mapEntities (entityMapFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EntityConverter::EntityConverter(const std::string &entityMapFile,
|
EntityConverter::EntityConverter (const std::string &entityMapFile,
|
||||||
const std::string &reflexMapFile) : OFFSET_PLAYER(32.0),
|
const std::string &reflexMapFile) : OFFSET_PLAYER(32.0),
|
||||||
OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0), OUTPUT_PRECISION(10)
|
OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0), OUTPUT_PRECISION(10)
|
||||||
{
|
{
|
||||||
@ -63,21 +63,21 @@ EntityConverter::EntityConverter(const std::string &entityMapFile,
|
|||||||
ws_.tdm = true;
|
ws_.tdm = true;
|
||||||
ws_.duel = true;
|
ws_.duel = true;
|
||||||
|
|
||||||
mapEntities(entityMapFile);
|
mapEntities (entityMapFile);
|
||||||
|
|
||||||
// Pre-scan for info needed by converter
|
// Pre-scan for info needed by converter
|
||||||
std::ifstream fin;
|
std::ifstream fin;
|
||||||
fin.open(reflexMapFile);
|
fin.open (reflexMapFile);
|
||||||
|
|
||||||
if ( fin.is_open() ) {
|
if (fin.is_open()) {
|
||||||
//Extract the source type of targets (teleporters or jump pads)
|
//Extract the source type of targets (teleporters or jump pads)
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(fin, line)) {
|
while (std::getline(fin, line)) {
|
||||||
extractFromEntity(line, fin);
|
extractFromEntity (line, fin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::ios::failure( "Error: EntityConverter failed to open .map file " + reflexMapFile );
|
throw std::ios::failure ("Error: EntityConverter failed to open .map file " + reflexMapFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fin.close();
|
fin.close();
|
||||||
@ -89,22 +89,22 @@ EntityConverter::EntityConverter(const std::string &entityMapFile,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
|
EntityConverter::extractMapInfo (std::queue<std::vector<std::string>> entities)
|
||||||
{
|
{
|
||||||
if( haveMapInfo_ ) {
|
if (haveMapInfo_) {
|
||||||
std::cerr << "Map info already extracted, doing nothing" << std::endl;
|
std::cerr << "Map info already extracted, doing nothing" << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
while ( ! entities.empty() ) {
|
while ( ! entities.empty()) {
|
||||||
std::vector<std::string> entity( entities.front() );
|
std::vector<std::string> entity (entities.front());
|
||||||
entities.pop();
|
entities.pop();
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::copy(entity.begin(), entity.end(),
|
std::copy (entity.begin(), entity.end(),
|
||||||
std::ostream_iterator<std::string>(ss, "\n"));
|
std::ostream_iterator<std::string> (ss, "\n"));
|
||||||
|
|
||||||
std::string nextLine;
|
std::string nextLine;
|
||||||
if ( getline(ss, nextLine )) {
|
if (getline(ss, nextLine)) {
|
||||||
extractFromEntity(nextLine, ss);
|
extractFromEntity(nextLine, ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,23 +117,23 @@ EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EntityConverter::extractMapInfo(const std::vector<std::vector<std::string>> &entities)
|
EntityConverter::extractMapInfo (const std::vector<std::vector<std::string>> &entities)
|
||||||
{
|
{
|
||||||
if( haveMapInfo_ ) {
|
if (haveMapInfo_) {
|
||||||
std::cerr << "Map info already extracted, doing nothing" << std::endl;
|
std::cerr << "Map info already extracted, doing nothing" << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::vector<std::vector<std::string>>::const_iterator it;
|
std::vector<std::vector<std::string>>::const_iterator it;
|
||||||
for ( it=entities.begin(); it!=entities.end(); ++it ) {
|
for (it=entities.begin(); it!=entities.end(); ++it) {
|
||||||
std::vector<std::string> entity( *it );
|
std::vector<std::string> entity (*it);
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::copy(entity.begin(), entity.end(),
|
std::copy (entity.begin(), entity.end(),
|
||||||
std::ostream_iterator<std::string>(ss, "\n"));
|
std::ostream_iterator<std::string> (ss, "\n"));
|
||||||
|
|
||||||
std::string nextLine;
|
std::string nextLine;
|
||||||
if ( getline(ss, nextLine )) {
|
if (getline (ss, nextLine)) {
|
||||||
extractFromEntity(nextLine, ss);
|
extractFromEntity (nextLine, ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,29 +144,29 @@ EntityConverter::extractMapInfo(const std::vector<std::vector<std::string>> &ent
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convert(const std::vector<std::string> &lines)
|
EntityConverter::convert (const std::vector<std::string> &lines)
|
||||||
{
|
{
|
||||||
if ( haveMapInfo_ )
|
if (haveMapInfo_)
|
||||||
{
|
{
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string trash; //unused tokens
|
std::string trash; //unused tokens
|
||||||
|
|
||||||
std::string type;
|
std::string type;
|
||||||
if ( lines.size() < 1 ) {
|
if (lines.size() < 1) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: empty entity cannot be converted", lines ));
|
makeErrorMessage( "error: empty entity cannot be converted", lines));
|
||||||
}
|
}
|
||||||
// second token is the type
|
// second token is the type
|
||||||
std::istringstream iss(lines[0]);
|
std::istringstream iss(lines[0]);
|
||||||
if ( ! (iss >> trash >> type)) {
|
if ( ! (iss >> trash >> type)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
makeErrorMessage( "error: type is required", lines ));
|
makeErrorMessage ("error: type is required", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If worldspawn, first reenable all gamemodes
|
// If worldspawn, first reenable all gamemodes
|
||||||
// then check worldspawn for disabled modes
|
// then check worldspawn for disabled modes
|
||||||
// then RETURN EMPTY VECTOR
|
// then RETURN EMPTY VECTOR
|
||||||
if ( type == "WorldSpawn" ) {
|
if (type == "WorldSpawn") {
|
||||||
ws_.cts = true;
|
ws_.cts = true;
|
||||||
ws_.ctf = true;
|
ws_.ctf = true;
|
||||||
ws_.ffa = true;
|
ws_.ffa = true;
|
||||||
@ -174,53 +174,53 @@ EntityConverter::convert(const std::vector<std::string> &lines)
|
|||||||
ws_.duel = true;
|
ws_.duel = true;
|
||||||
|
|
||||||
// Each worldspawn can specify modes enabled/disabled
|
// Each worldspawn can specify modes enabled/disabled
|
||||||
for ( int i = 1; i < lines.size(); ++i ) {
|
for (int i = 1; i < lines.size(); ++i) {
|
||||||
if ( lines[i].find("modeRace 0") != std::string::npos) {
|
if (lines[i].find("modeRace 0") != std::string::npos) {
|
||||||
ws_.cts = false;
|
ws_.cts = false;
|
||||||
}
|
}
|
||||||
else if ( lines[i].find("modeCTF 0") != std::string::npos) {
|
else if (lines[i].find("modeCTF 0") != std::string::npos) {
|
||||||
ws_.ctf = false;
|
ws_.ctf = false;
|
||||||
}
|
}
|
||||||
else if ( lines[i].find("modeFFA 0") != std::string::npos) {
|
else if (lines[i].find("modeFFA 0") != std::string::npos) {
|
||||||
ws_.ffa = false;
|
ws_.ffa = false;
|
||||||
}
|
}
|
||||||
else if ( lines[i].find("modeTDM 0") != std::string::npos) {
|
else if (lines[i].find("modeTDM 0") != std::string::npos) {
|
||||||
ws_.tdm = false;
|
ws_.tdm = false;
|
||||||
}
|
}
|
||||||
else if ( lines[i].find("mode1v1 0") != std::string::npos) {
|
else if (lines[i].find("mode1v1 0") != std::string::npos) {
|
||||||
ws_.duel = false;
|
ws_.duel = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( type == "Pickup" ) {
|
else if (type == "Pickup") {
|
||||||
return convertPickup(lines);
|
return convertPickup (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "PlayerSpawn" ) {
|
else if (type == "PlayerSpawn") {
|
||||||
return convertPlayerSpawn(lines);
|
return convertPlayerSpawn (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "JumpPad" ) {
|
else if (type == "JumpPad") {
|
||||||
return convertJumpPad(lines);
|
return convertJumpPad (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "Teleporter" ) {
|
else if (type == "Teleporter") {
|
||||||
return convertTeleporter(lines);
|
return convertTeleporter (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "Target" ) {
|
else if (type == "Target") {
|
||||||
return convertTarget(lines);
|
return convertTarget (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "RaceStart" ) {
|
else if (type == "RaceStart") {
|
||||||
return convertRaceStart(lines);
|
return convertRaceStart (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "RaceFinish" ) {
|
else if (type == "RaceFinish") {
|
||||||
return convertRaceFinish(lines);
|
return convertRaceFinish (lines);
|
||||||
}
|
}
|
||||||
else if ( type == "PointLight" ) {
|
else if (type == "PointLight") {
|
||||||
return convertPointLight(lines);
|
return convertPointLight (lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Map info must be extracted prior to conversion", lines ));
|
makeErrorMessage ("error: Map info must be extracted prior to conversion", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If unsupported entity, return empty vector
|
// If unsupported entity, return empty vector
|
||||||
@ -238,7 +238,7 @@ EntityConverter::convert(const std::vector<std::string> &lines)
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertPickup(const std::vector<std::string> &lines) const
|
EntityConverter::convertPickup (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
//can ignore angle of pickups in xonotic format
|
//can ignore angle of pickups in xonotic format
|
||||||
@ -247,52 +247,52 @@ EntityConverter::convertPickup(const std::vector<std::string> &lines) const
|
|||||||
std::string trash;
|
std::string trash;
|
||||||
bool havePickupID = false;
|
bool havePickupID = false;
|
||||||
|
|
||||||
if ( lines.size() < 2 ) {
|
if (lines.size() < 2) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Pickup entity requires minimum of two lines (type and ID)", lines ));
|
makeErrorMessage ("error: Pickup entity requires minimum of two lines (type and ID)", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < lines.size(); i++) {
|
for (int i = 1; i < lines.size(); i++) {
|
||||||
std::string type = getAttributeType(lines[i]);
|
std::string type = getAttributeType (lines[i]);
|
||||||
if ( type == "position" ) {
|
if ( type == "position") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// Vector3 position coord0 coord1 coord2
|
// Vector3 position coord0 coord1 coord2
|
||||||
if ( ! (iss >> trash >> trash >>
|
if ( ! (iss >> trash >> trash >>
|
||||||
coords[0] >> coords[1] >> coords[2])) {
|
coords[0] >> coords[1] >> coords[2])) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid Pickup position", lines ));
|
makeErrorMessage ("error: Invalid Pickup position", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( type == "pickupType" ) {
|
else if (type == "pickupType") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// UInt8 pickupType ID
|
// UInt8 pickupType ID
|
||||||
if ( ! (iss >> trash >> trash >> pickupID) ) {
|
if ( ! (iss >> trash >> trash >> pickupID)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Format of Pickup ID line is invalid", lines ));
|
makeErrorMessage ("error: Format of Pickup ID line is invalid", lines));
|
||||||
}
|
}
|
||||||
havePickupID = true;
|
havePickupID = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( havePickupID ) {
|
if (havePickupID) {
|
||||||
auto pickupIter = entityMap_.find(pickupID);
|
auto pickupIter = entityMap_.find (pickupID);
|
||||||
if ( pickupIter == entityMap_.end() ) {
|
if ( pickupIter == entityMap_.end()) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
makeErrorMessage( "error: Pickup ID is invalid", lines ));
|
makeErrorMessage ("error: Pickup ID is invalid", lines));
|
||||||
}
|
}
|
||||||
std::stringstream pickupStream;
|
std::stringstream pickupStream;
|
||||||
pickupStream << "\"classname\" \"" << pickupIter->second << "\"" << std::endl;
|
pickupStream << "\"classname\" \"" << pickupIter->second << "\"" << std::endl;
|
||||||
convertedLines.push_back ( pickupStream.str() );
|
convertedLines.push_back (pickupStream.str());
|
||||||
// coordinates reordered to x, z, y
|
// coordinates reordered to x, z, y
|
||||||
std::stringstream positionStream;
|
std::stringstream positionStream;
|
||||||
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
||||||
offset(coords[1], OFFSET_PICKUP) << "\"" << std::endl;
|
offset (coords[1], OFFSET_PICKUP) << "\"" << std::endl;
|
||||||
convertedLines.push_back ( positionStream.str() );
|
convertedLines.push_back (positionStream.str());
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Pickup ID was not in the entity", lines ));
|
makeErrorMessage ("error: Pickup ID was not in the entity", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ EntityConverter::convertPickup(const std::vector<std::string> &lines) const
|
|||||||
*--------------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
|
EntityConverter::convertPlayerSpawn (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
// Requires position coordinate
|
// Requires position coordinate
|
||||||
@ -329,82 +329,82 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
|
|||||||
|
|
||||||
for (int i = 1; i < lines.size(); i++) {
|
for (int i = 1; i < lines.size(); i++) {
|
||||||
std::string type = getAttributeType(lines[i]);
|
std::string type = getAttributeType(lines[i]);
|
||||||
if ( type == "position" ) {
|
if (type == "position") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// Vector3 position coord0 coord1 coord2
|
// Vector3 position coord0 coord1 coord2
|
||||||
if ( ! (iss >> trash >> trash >>
|
if ( ! (iss >> trash >> trash >>
|
||||||
coords[0] >> coords[1] >> coords[2])) {
|
coords[0] >> coords[1] >> coords[2])) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid PlayerSpawn position", lines ));
|
makeErrorMessage ("error: Invalid PlayerSpawn position", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( type == "angles" ) {
|
else if (type == "angles") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// UInt8 pickupType ID
|
// UInt8 pickupType ID
|
||||||
if ( ! (iss >> trash >> trash >> angle )) {
|
if ( ! (iss >> trash >> trash >> angle)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid PlayerSpawn angle", lines ));
|
makeErrorMessage ("error: Invalid PlayerSpawn angle", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Bool8 modeX 0 indicates this spawn is not for game mode X
|
// Bool8 modeX 0 indicates this spawn is not for game mode X
|
||||||
else if ( type == "modeRace" ) {
|
else if (type == "modeRace") {
|
||||||
isModeRace = false;
|
isModeRace = false;
|
||||||
}
|
}
|
||||||
else if ( type == "modeCTF" ) {
|
else if (type == "modeCTF") {
|
||||||
isModeCtf = false;
|
isModeCtf = false;
|
||||||
}
|
}
|
||||||
else if ( type == "modeTDM" ) {
|
else if (type == "modeTDM") {
|
||||||
isModeTdm = false;
|
isModeTdm = false;
|
||||||
}
|
}
|
||||||
else if ( type == "modeFFA" ) {
|
else if (type == "modeFFA") {
|
||||||
isModeFfa = false;
|
isModeFfa = false;
|
||||||
}
|
}
|
||||||
else if ( type == "mode1v1" ) {
|
else if (type == "mode1v1") {
|
||||||
isModeDuel = false;
|
isModeDuel = false;
|
||||||
}
|
}
|
||||||
else if ( type == "teamA" ) {
|
else if (type == "teamA") {
|
||||||
team = 2; // Bool8 teamA 0 indicates teamB only
|
team = 2; // Bool8 teamA 0 indicates teamB only
|
||||||
}
|
}
|
||||||
else if ( type == "teamB" ) {
|
else if (type == "teamB") {
|
||||||
team = 1; // Bool8 teamB 0 indicates teamA only
|
team = 1; // Bool8 teamB 0 indicates teamA only
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) {
|
if (isModeCtf || isModeTdm || isModeFfa || isModeDuel) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::map<std::string, std::string>::const_iterator it;
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
switch (team) {
|
switch (team) {
|
||||||
case 0:
|
case 0:
|
||||||
convertedLines.push_back ("\"classname\" \"info_player_deathmatch\"\n" );
|
convertedLines.push_back ("\"classname\" \"info_player_deathmatch\"\n");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
it = entityMap_.find("team1");
|
it = entityMap_.find ("team1");
|
||||||
ss << "\"classname\" \"" << it->second << "\"" << std::endl;
|
ss << "\"classname\" \"" << it->second << "\"" << std::endl;
|
||||||
convertedLines.push_back (ss.str());
|
convertedLines.push_back (ss.str());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
it = entityMap_.find("team2");
|
it = entityMap_.find ("team2");
|
||||||
ss << "\"classname\" \"" << it->second << "\"" << std::endl;
|
ss << "\"classname\" \"" << it->second << "\"" << std::endl;
|
||||||
convertedLines.push_back (ss.str());
|
convertedLines.push_back (ss.str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
convertedLines.push_back ( "\"classname\" \"info_player_race\"\n" );
|
convertedLines.push_back ("\"classname\" \"info_player_race\"\n");
|
||||||
// Reflex maps have only start and finish, point to start on spawn
|
// Reflex maps have only start and finish, point to start on spawn
|
||||||
convertedLines.push_back ( "\"target\" \"cp1\"\n" );
|
convertedLines.push_back ("\"target\" \"cp1\"\n");
|
||||||
// Reflex maps are only cts, set spawn to cts-only type
|
// Reflex maps are only cts, set spawn to cts-only type
|
||||||
convertedLines.push_back ( "\"race_place\" \"-1\"\n" );
|
convertedLines.push_back ("\"race_place\" \"-1\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream positionStream;
|
std::stringstream positionStream;
|
||||||
// coordinates reordered to x, z, y
|
// coordinates reordered to x, z, y
|
||||||
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
||||||
offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl;
|
offset (coords[1], OFFSET_PLAYER) << "\"" << std::endl;
|
||||||
convertedLines.push_back ( positionStream.str() );
|
convertedLines.push_back (positionStream.str());
|
||||||
std::stringstream angleStream;
|
std::stringstream angleStream;
|
||||||
angleStream << "\"angle\" \"" << adjustAngleForHandedness(angle) << "\"" << std::endl;
|
angleStream << "\"angle\" \"" << adjustAngleForHandedness(angle) << "\"" << std::endl;
|
||||||
convertedLines.push_back (angleStream.str() );
|
convertedLines.push_back (angleStream.str());
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -412,61 +412,61 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertJumpPad(const std::vector<std::string> &lines) const
|
EntityConverter::convertJumpPad (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
std::string targetName;
|
std::string targetName;
|
||||||
std::string trash;
|
std::string trash;
|
||||||
|
|
||||||
if ( lines.size() < 2 ) {
|
if (lines.size() < 2) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
makeErrorMessage( "error: JumpPad entity requires minimum of two lines (type and target)", lines ));
|
makeErrorMessage ("error: JumpPad entity requires minimum of two lines (type and target)", lines));
|
||||||
}
|
}
|
||||||
std::istringstream iss(lines[1]);
|
std::istringstream iss (lines[1]);
|
||||||
// String32 target targetName
|
// String32 target targetName
|
||||||
if ( ! (iss >> trash >> trash >> targetName) ) {
|
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
makeErrorMessage( "error: Invalid JumpPad target", lines ));
|
makeErrorMessage ("error: Invalid JumpPad target", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
convertedLines.push_back ( "\"classname\" \"trigger_push\"\n" );
|
convertedLines.push_back ("\"classname\" \"trigger_push\"\n");
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
oss << "\"target\" \"" << targetName << "\"" << std::endl;
|
oss << "\"target\" \"" << targetName << "\"" << std::endl;
|
||||||
convertedLines.push_back ( oss.str() );
|
convertedLines.push_back (oss.str());
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertTeleporter(const std::vector<std::string> &lines) const
|
EntityConverter::convertTeleporter (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
std::string targetName;
|
std::string targetName;
|
||||||
std::string trash;
|
std::string trash;
|
||||||
|
|
||||||
if ( lines.size() < 2 ) {
|
if (lines.size() < 2) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Teleport entity requires minimum of two lines (type and target)", lines ));
|
makeErrorMessage ("error: Teleport entity requires minimum of two lines (type and target)", lines));
|
||||||
}
|
}
|
||||||
std::istringstream iss(lines[1]);
|
std::istringstream iss (lines[1]);
|
||||||
// String32 target targetName
|
// String32 target targetName
|
||||||
if ( ! (iss >> trash >> trash >> targetName) ) {
|
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid Teleport target", lines ));
|
makeErrorMessage ("error: Invalid Teleport target", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
convertedLines.push_back ( "\"classname\" \"trigger_teleport\"\n" );
|
convertedLines.push_back ("\"classname\" \"trigger_teleport\"\n");
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
oss << "\"target\" \"" << targetName << "\"" << std::endl;
|
oss << "\"target\" \"" << targetName << "\"" << std::endl;
|
||||||
convertedLines.push_back ( oss.str() );
|
convertedLines.push_back (oss.str());
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertTarget(const std::vector<std::string> &lines) const
|
EntityConverter::convertTarget (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
//position and name required, angles optional
|
//position and name required, angles optional
|
||||||
@ -477,80 +477,80 @@ EntityConverter::convertTarget(const std::vector<std::string> &lines) const
|
|||||||
bool haveName = false;
|
bool haveName = false;
|
||||||
|
|
||||||
|
|
||||||
if ( lines.size() < 3 ) {
|
if (lines.size() < 3) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Target entity requires minimum of two lines (type and name)", lines ));
|
makeErrorMessage ("error: Target entity requires minimum of two lines (type and name)", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < lines.size(); i++) {
|
for (int i = 1; i < lines.size(); i++) {
|
||||||
std::string type = getAttributeType(lines[i]);
|
std::string type = getAttributeType (lines[i]);
|
||||||
if ( type == "position" ) {
|
if (type == "position") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// Vector3 position coord0 coord1 coord2
|
// Vector3 position coord0 coord1 coord2
|
||||||
if ( ! (iss >> trash >> trash >>
|
if ( ! (iss >> trash >> trash >>
|
||||||
coords[0] >> coords[1] >> coords[2])) {
|
coords[0] >> coords[1] >> coords[2])) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid Target position", lines ));
|
makeErrorMessage ("error: Invalid Target position", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( type == "name" ) {
|
else if (type == "name") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// UInt8 name uniqueName
|
// UInt8 name uniqueName
|
||||||
if ( ! (iss >> trash >> trash >> targetName) ) {
|
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid Target \"target\"", lines ));
|
makeErrorMessage ("error: Invalid Target \"target\"", lines));
|
||||||
}
|
}
|
||||||
haveName = true;
|
haveName = true;
|
||||||
}
|
}
|
||||||
else if ( type == "angles" ) {
|
else if (type == "angles") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// Vector3 angles angle notapplicable notapplicable
|
// Vector3 angles angle notapplicable notapplicable
|
||||||
if ( ! (iss >> trash >> trash >> angle) ) {
|
if ( ! (iss >> trash >> trash >> angle)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid Target angle", lines ));
|
makeErrorMessage ("error: Invalid Target angle", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( haveName) {
|
if (haveName) {
|
||||||
auto targetIter = targetMap_.find(targetName);
|
auto targetIter = targetMap_.find (targetName);
|
||||||
if ( targetIter == targetMap_.end() ) {
|
if (targetIter == targetMap_.end()) {
|
||||||
std::cerr << makeErrorMessage("End-game camera Target is not a supported feature in id Tech games. Skipping", lines);
|
std::cerr << makeErrorMessage ("End-game camera Target is not a supported feature in id Tech games. Skipping", lines);
|
||||||
|
|
||||||
std::vector<std::string> empty;
|
std::vector<std::string> empty;
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
if ( targetIter->second == "Teleporter") {
|
if (targetIter->second == "Teleporter") {
|
||||||
convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" );
|
convertedLines.push_back ("\"classname\" \"misc_teleporter_dest\"\n");
|
||||||
// coordinates reordered to x, z, y
|
// coordinates reordered to x, z, y
|
||||||
// teleporter height is OFFSET
|
// teleporter height is OFFSET
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
||||||
offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl;
|
offset (coords[1], OFFSET_PLAYER) << "\"" << std::endl;
|
||||||
convertedLines.push_back ( oss.str() );
|
convertedLines.push_back ( oss.str());
|
||||||
}
|
}
|
||||||
else if ( targetIter->second == "JumpPad") {
|
else if ( targetIter->second == "JumpPad") {
|
||||||
convertedLines.push_back ( "\"classname\" \"target_position\"\n" );
|
convertedLines.push_back ("\"classname\" \"target_position\"\n");
|
||||||
// coordinates reordered to x, z, y
|
// coordinates reordered to x, z, y
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
||||||
coords[1] << "\"" << std::endl;
|
coords[1] << "\"" << std::endl;
|
||||||
convertedLines.push_back ( oss.str() );
|
convertedLines.push_back (oss.str());
|
||||||
}
|
}
|
||||||
std::stringstream targetStream;
|
std::stringstream targetStream;
|
||||||
targetStream << "\"targetname\" \"" << targetName << "\"" << std::endl;
|
targetStream << "\"targetname\" \"" << targetName << "\"" << std::endl;
|
||||||
convertedLines.push_back ( targetStream.str() );
|
convertedLines.push_back (targetStream.str());
|
||||||
|
|
||||||
// write angle every time
|
// write angle every time
|
||||||
std::stringstream angleStream;
|
std::stringstream angleStream;
|
||||||
angleStream << "\"angle\" \"" << adjustAngleForHandedness(angle) << "\"" << std::endl;
|
angleStream << "\"angle\" \"" << adjustAngleForHandedness (angle) << "\"" << std::endl;
|
||||||
convertedLines.push_back( angleStream.str() );
|
convertedLines.push_back( angleStream.str());
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: \"target\" was not found in this Target entity", lines ));
|
makeErrorMessage ("error: \"target\" was not found in this Target entity", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ EntityConverter::convertTarget(const std::vector<std::string> &lines) const
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertRaceStart(const std::vector<std::string> &lines) const
|
EntityConverter::convertRaceStart (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
||||||
@ -570,7 +570,7 @@ EntityConverter::convertRaceStart(const std::vector<std::string> &lines) const
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertRaceFinish(const std::vector<std::string> &lines) const
|
EntityConverter::convertRaceFinish (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
||||||
@ -582,7 +582,7 @@ EntityConverter::convertRaceFinish(const std::vector<std::string> &lines) const
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
EntityConverter::convertPointLight(const std::vector<std::string> &lines) const
|
EntityConverter::convertPointLight (const std::vector<std::string> &lines) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> convertedLines;
|
std::vector<std::string> convertedLines;
|
||||||
//position and intensity required, color optional
|
//position and intensity required, color optional
|
||||||
@ -596,36 +596,36 @@ EntityConverter::convertPointLight(const std::vector<std::string> &lines) const
|
|||||||
bool haveColor = false;
|
bool haveColor = false;
|
||||||
|
|
||||||
|
|
||||||
if ( lines.size() < 2 ) {
|
if (lines.size() < 2) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: PointLight entity requires at least one line (type)", lines ));
|
makeErrorMessage ("error: PointLight entity requires at least one line (type)", lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < lines.size(); i++) {
|
for (int i = 1; i < lines.size(); i++) {
|
||||||
std::string type = getAttributeType(lines[i]);
|
std::string type = getAttributeType(lines[i]);
|
||||||
if ( type == "position" ) {
|
if (type == "position") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// Vector3 position coord0 coord1 coord2
|
// Vector3 position coord0 coord1 coord2
|
||||||
if ( ! (iss >> trash >> trash >>
|
if ( ! (iss >> trash >> trash >>
|
||||||
coords[0] >> coords[1] >> coords[2])) {
|
coords[0] >> coords[1] >> coords[2])) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid PointLight position", lines ));
|
makeErrorMessage ("error: Invalid PointLight position", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( type == "intensity" ) {
|
else if (type == "intensity") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// Float intensity validFloat
|
// Float intensity validFloat
|
||||||
if ( ! (iss >> trash >> trash >> intensity) ) {
|
if ( ! (iss >> trash >> trash >> intensity)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid PointLight intensity", lines ));
|
makeErrorMessage ("error: Invalid PointLight intensity", lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( type == "color" ) {
|
else if (type == "color") {
|
||||||
std::istringstream iss(lines[i]);
|
std::istringstream iss (lines[i]);
|
||||||
// ColourXRGB32 color eightDigitHexValue
|
// ColourXRGB32 color eightDigitHexValue
|
||||||
if ( ! (iss >> trash >> trash >> color) ) {
|
if ( ! (iss >> trash >> trash >> color)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error (
|
||||||
makeErrorMessage( "error: Invalid PointLight color", lines ));
|
makeErrorMessage ("error: Invalid PointLight color", lines));
|
||||||
}
|
}
|
||||||
haveColor = true;
|
haveColor = true;
|
||||||
}
|
}
|
||||||
@ -633,26 +633,26 @@ EntityConverter::convertPointLight(const std::vector<std::string> &lines) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
convertedLines.push_back ( "\"classname\" \"light\"\n" );
|
convertedLines.push_back ("\"classname\" \"light\"\n");
|
||||||
// coordinates reordered to x, z, y
|
// coordinates reordered to x, z, y
|
||||||
std::stringstream positionStream;
|
std::stringstream positionStream;
|
||||||
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
|
||||||
coords[1] << "\"" << std::endl;
|
coords[1] << "\"" << std::endl;
|
||||||
convertedLines.push_back ( positionStream.str() );
|
convertedLines.push_back (positionStream.str());
|
||||||
// convert intensity
|
// convert intensity
|
||||||
std::stringstream intensityStream;
|
std::stringstream intensityStream;
|
||||||
intensityStream << "\"light\" \"" << adjustBrightness(intensity) << "\"\n";
|
intensityStream << "\"light\" \"" << adjustBrightness (intensity) << "\"\n";
|
||||||
convertedLines.push_back ( intensityStream.str() );
|
convertedLines.push_back (intensityStream.str());
|
||||||
|
|
||||||
float red;
|
float red;
|
||||||
float green;
|
float green;
|
||||||
float blue;
|
float blue;
|
||||||
// Convert 32bit hex RGBA value (ALPHA ALWAYS FULL) into RGB values
|
// Convert 32bit hex RGBA value (ALPHA ALWAYS FULL) into RGB values
|
||||||
hexToRGB(color, red, green, blue);
|
hexToRGB (color, red, green, blue);
|
||||||
|
|
||||||
std::stringstream colorStream;
|
std::stringstream colorStream;
|
||||||
colorStream << "\"_color\" \"" << red << " " << green << " " << blue << "\"" << std::endl;
|
colorStream << "\"_color\" \"" << red << " " << green << " " << blue << "\"" << std::endl;
|
||||||
convertedLines.push_back (colorStream.str() );
|
convertedLines.push_back (colorStream.str());
|
||||||
|
|
||||||
return convertedLines;
|
return convertedLines;
|
||||||
}
|
}
|
||||||
@ -661,12 +661,12 @@ EntityConverter::convertPointLight(const std::vector<std::string> &lines) const
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
EntityConverter::getAttributeType(const std::string &line) const
|
EntityConverter::getAttributeType (const std::string &line) const
|
||||||
{
|
{
|
||||||
std::string type;
|
std::string type;
|
||||||
std::string dataType;
|
std::string dataType;
|
||||||
std::istringstream iss(line);
|
std::istringstream iss (line);
|
||||||
if ( ! (iss >> dataType >> type )) {
|
if ( ! (iss >> dataType >> type)) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,27 +676,27 @@ EntityConverter::getAttributeType(const std::string &line) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EntityConverter::mapEntities(const std::string &mapFile)
|
EntityConverter::mapEntities (const std::string &mapFile)
|
||||||
{
|
{
|
||||||
std::ifstream fin;
|
std::ifstream fin;
|
||||||
fin.open(mapFile);
|
fin.open (mapFile);
|
||||||
|
|
||||||
if ( fin.is_open() ) {
|
if (fin.is_open()) {
|
||||||
//Read .ent contents into pickup map
|
//Read .ent contents into pickup map
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(fin, line)) {
|
while (std::getline (fin, line)) {
|
||||||
std::istringstream iss(line);
|
std::istringstream iss (line);
|
||||||
// Reflex ID corresponds to xonotic pickup name
|
// Reflex ID corresponds to xonotic pickup name
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string pickup;
|
std::string pickup;
|
||||||
if ( ! (iss >> id >> pickup)) {
|
if ( ! (iss >> id >> pickup)) {
|
||||||
throw std::runtime_error( "format error in Pickup .pck file " + mapFile );
|
throw std::runtime_error ("format error in Pickup .pck file " + mapFile);
|
||||||
}
|
}
|
||||||
entityMap_.insert ( std::pair<std::string, std::string>(id, pickup) );
|
entityMap_.insert (std::pair<std::string, std::string> (id, pickup));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::ios::failure( "Error: EntityConverter failed to open .ent file" );
|
throw std::ios::failure ("Error: EntityConverter failed to open .ent file");
|
||||||
}
|
}
|
||||||
fin.close();
|
fin.close();
|
||||||
|
|
||||||
@ -710,8 +710,8 @@ EntityConverter::haveRequiredMappings()
|
|||||||
std::vector<std::string> required = { "team1",
|
std::vector<std::string> required = { "team1",
|
||||||
"team2" };
|
"team2" };
|
||||||
for (std::string id : required) {
|
for (std::string id : required) {
|
||||||
auto pickupIter = entityMap_.find(id);
|
auto pickupIter = entityMap_.find (id);
|
||||||
if ( pickupIter == entityMap_.end() ) {
|
if ( pickupIter == entityMap_.end()) {
|
||||||
throw std::runtime_error ("error: Missing required entity mappings");
|
throw std::runtime_error ("error: Missing required entity mappings");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -723,63 +723,63 @@ EntityConverter::haveRequiredMappings()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EntityConverter::extractFromEntity(const std::string &line, std::istream &is)
|
EntityConverter::extractFromEntity (const std::string &line, std::istream &is)
|
||||||
{
|
{
|
||||||
std::string trash;
|
std::string trash;
|
||||||
std::string targetName;
|
std::string targetName;
|
||||||
std::string nextLine;
|
std::string nextLine;
|
||||||
if ( line.find("type Teleporter") != std::string::npos) {
|
if (line.find("type Teleporter") != std::string::npos) {
|
||||||
std::getline(is, nextLine);
|
std::getline (is, nextLine);
|
||||||
std::istringstream iss(nextLine);
|
std::istringstream iss (nextLine);
|
||||||
if ( ! (iss >> trash >> trash >> targetName)) {
|
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||||
throw std::runtime_error( "Format error in .map file" );
|
throw std::runtime_error ("Format error in .map file");
|
||||||
}
|
}
|
||||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "Teleporter") );
|
targetMap_.insert (std::pair<std::string, std::string>(targetName, "Teleporter"));
|
||||||
}
|
}
|
||||||
else if ( line.find("type JumpPad") != std::string::npos) {
|
else if (line.find ("type JumpPad") != std::string::npos) {
|
||||||
std::getline(is, nextLine);
|
std::getline (is, nextLine);
|
||||||
std::istringstream iss(nextLine);
|
std::istringstream iss (nextLine);
|
||||||
if ( ! (iss >> trash >> trash >> targetName)) {
|
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||||
throw std::runtime_error( "Format error in .map file" );
|
throw std::runtime_error ( "Format error in .map file");
|
||||||
}
|
}
|
||||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "JumpPad") );
|
targetMap_.insert (std::pair<std::string, std::string> (targetName, "JumpPad"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
EntityConverter::offset(const std::string &value, const float amount) const
|
EntityConverter::offset (const std::string &value, const float amount) const
|
||||||
{
|
{
|
||||||
std::istringstream iss(value);
|
std::istringstream iss (value);
|
||||||
float c;
|
float c;
|
||||||
iss >> c;
|
iss >> c;
|
||||||
c += amount;
|
c += amount;
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::fixed << std::fixed << std::setprecision(OUTPUT_PRECISION) << c;
|
ss << std::fixed << std::fixed << std::setprecision (OUTPUT_PRECISION) << c;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
EntityConverter::adjustAngleForHandedness(const std::string &angle) const
|
EntityConverter::adjustAngleForHandedness (const std::string &angle) const
|
||||||
{
|
{
|
||||||
std::istringstream iss(angle);
|
std::istringstream iss (angle);
|
||||||
float a;
|
float a;
|
||||||
iss >> a;
|
iss >> a;
|
||||||
a = -a + 90.0;
|
a = -a + 90.0;
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::fixed << std::fixed << std::setprecision(OUTPUT_PRECISION) << a;
|
ss << std::fixed << std::fixed << std::setprecision (OUTPUT_PRECISION) << a;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EntityConverter::hexToRGB(const std::string &hex, float &r, float &g, float &b) const
|
EntityConverter::hexToRGB (const std::string &hex, float &r, float &g, float &b) const
|
||||||
{
|
{
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -797,10 +797,10 @@ EntityConverter::hexToRGB(const std::string &hex, float &r, float &g, float &b)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
EntityConverter::adjustBrightness(const std::string &value) const
|
EntityConverter::adjustBrightness (const std::string &value) const
|
||||||
{
|
{
|
||||||
float inputBright;
|
float inputBright;
|
||||||
std::stringstream ss(value);
|
std::stringstream ss (value);
|
||||||
ss >> inputBright;
|
ss >> inputBright;
|
||||||
|
|
||||||
return static_cast<int>(inputBright * BRIGHTNESS_ADJUST);
|
return static_cast<int>(inputBright * BRIGHTNESS_ADJUST);
|
||||||
@ -810,14 +810,14 @@ EntityConverter::adjustBrightness(const std::string &value) const
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
EntityConverter::makeErrorMessage(const std::string message,
|
EntityConverter::makeErrorMessage (const std::string message,
|
||||||
const std::vector<std::string> entity) const
|
const std::vector<std::string> entity) const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::endl << message << ":" << std::endl;
|
ss << std::endl << message << ":" << std::endl;
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator it;
|
std::vector<std::string>::const_iterator it;
|
||||||
for ( it=entity.begin(); it!=entity.end(); ++it ) {
|
for (it=entity.begin(); it!=entity.end(); ++it) {
|
||||||
ss << *it << std::endl;
|
ss << *it << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -841,7 +841,7 @@ EntityConverter::printMapping() const
|
|||||||
{
|
{
|
||||||
std::cout << std::endl << "Reflex pickup ID mapped to Xonotic pickup names: " << std::endl;
|
std::cout << std::endl << "Reflex pickup ID mapped to Xonotic pickup names: " << std::endl;
|
||||||
std::map<std::string, std::string>::const_iterator it;
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
for ( it=entityMap_.begin(); it!=entityMap_.end(); ++it )
|
for (it=entityMap_.begin(); it!=entityMap_.end(); ++it)
|
||||||
std::cout << it->first << " => " << it->second << std::endl;
|
std::cout << it->first << " => " << it->second << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -851,7 +851,7 @@ EntityConverter::printTargetSources() const
|
|||||||
{
|
{
|
||||||
std::cout << std::endl << "Target and Sources: " << std::endl;
|
std::cout << std::endl << "Target and Sources: " << std::endl;
|
||||||
std::map<std::string, std::string>::const_iterator it;
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
for ( it=targetMap_.begin(); it!=targetMap_.end(); ++it )
|
for (it=targetMap_.begin(); it!=targetMap_.end(); ++it)
|
||||||
std::cout << it->first << " => " << it->second << std::endl;
|
std::cout << it->first << " => " << it->second << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
*
|
*
|
||||||
* Description: Unit tests for EntityConverter class
|
* Description: Unit tests for EntityConverter class
|
||||||
*
|
*
|
||||||
* Version: 0.1
|
* Version: 1.0
|
||||||
* Created: 07/14/2017 20:36:31 PM
|
* Created: 07/14/2017 20:36:31 PM
|
||||||
* Revision: none
|
* Revision: none
|
||||||
* Compiler: gcc
|
* Compiler: gcc
|
||||||
*
|
*
|
||||||
* Author: suhrke@teknik.io
|
* Author: surkeh@protonmail.com
|
||||||
*
|
*
|
||||||
* =====================================================================================
|
* =====================================================================================
|
||||||
*/
|
*/
|
||||||
@ -26,70 +26,70 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: Unsupported entity types cause return of empty vector", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: Unsupported entity types cause return of empty vector", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type NotAType");
|
entity.push_back (" type NotAType");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert (entity);
|
||||||
|
|
||||||
REQUIRE( converted.size() == 0 );
|
REQUIRE (converted.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single Pickup entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single Pickup entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type Pickup");
|
entity.push_back (" type Pickup");
|
||||||
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
entity.push_back (" Vector3 angles 180.00000 0.00000 0.00000");
|
||||||
entity.push_back(" UInt8 pickupType 2");
|
entity.push_back (" UInt8 pickupType 2");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert (entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"weapon_grenadelauncher\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"weapon_grenadelauncher\"\n");
|
||||||
|
|
||||||
// The z (vertical) is offset by +2
|
// The z (vertical) is offset by +2
|
||||||
std::istringstream iss(converted[1]);
|
std::istringstream iss (converted[1]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string coords[2];
|
std::string coords[2];
|
||||||
float offsetCoord;
|
float offsetCoord;
|
||||||
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"origin\"" );
|
REQUIRE (attribute == "\"origin\"");
|
||||||
REQUIRE( coords[0] == "\"-216.00000" );
|
REQUIRE (coords[0] == "\"-216.00000");
|
||||||
REQUIRE( coords[1] == "-1488.000488" );
|
REQUIRE (coords[1] == "-1488.000488");
|
||||||
REQUIRE( fabs(-130.00000 - offsetCoord) <= DELTA );
|
REQUIRE (fabs(-130.00000 - offsetCoord) <= DELTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single PlayerSpawn (race) entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
@ -97,55 +97,55 @@ TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityC
|
|||||||
// Mock up WorldSpawn entity
|
// Mock up WorldSpawn entity
|
||||||
// (needed for mode info)
|
// (needed for mode info)
|
||||||
std::vector<std::string> worldspawn;
|
std::vector<std::string> worldspawn;
|
||||||
worldspawn.push_back(" type WorldSpawn");
|
worldspawn.push_back (" type WorldSpawn");
|
||||||
worldspawn.push_back(" Bool8 modeCTF 0");
|
worldspawn.push_back (" Bool8 modeCTF 0");
|
||||||
worldspawn.push_back(" Bool8 modeFFA 0");
|
worldspawn.push_back (" Bool8 modeFFA 0");
|
||||||
worldspawn.push_back(" Bool8 modeTDM 0");
|
worldspawn.push_back (" Bool8 modeTDM 0");
|
||||||
worldspawn.push_back(" Bool8 mode1v1 0");
|
worldspawn.push_back (" Bool8 mode1v1 0");
|
||||||
|
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type PlayerSpawn");
|
entity.push_back (" type PlayerSpawn");
|
||||||
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
entity.push_back (" Vector3 angles 180.00000 0.00000 0.00000");
|
||||||
entity.push_back(" Bool8 teamA 0");
|
entity.push_back (" Bool8 teamA 0");
|
||||||
entity.push_back(" Bool8 teamB 0");
|
entity.push_back (" Bool8 teamB 0");
|
||||||
entity.push_back(" Bool8 modeCTF 0");
|
entity.push_back (" Bool8 modeCTF 0");
|
||||||
entity.push_back(" Bool8 modeFFA 0");
|
entity.push_back (" Bool8 modeFFA 0");
|
||||||
entity.push_back(" Bool8 modeTDM 0");
|
entity.push_back (" Bool8 modeTDM 0");
|
||||||
entity.push_back(" Bool8 mode1v1 0");
|
entity.push_back (" Bool8 mode1v1 0");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( worldspawn );
|
q.push (worldspawn);
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity (worldspawn conversion returns empty vector
|
// Convert a single entity (worldspawn conversion returns empty vector
|
||||||
// BUT sets the supported game modes for entities in that worldspawn
|
// BUT sets the supported game modes for entities in that worldspawn
|
||||||
std::vector<std::string> unused = ec.convert(worldspawn);
|
std::vector<std::string> unused = ec.convert(worldspawn);
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"info_player_race\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"info_player_race\"\n");
|
||||||
REQUIRE( converted[1] == "\"target\" \"cp1\"\n" );
|
REQUIRE (converted[1] == "\"target\" \"cp1\"\n");
|
||||||
REQUIRE( converted[2] == "\"race_place\" \"-1\"\n" );
|
REQUIRE (converted[2] == "\"race_place\" \"-1\"\n");
|
||||||
|
|
||||||
// The z (vertical) is offset by +32
|
// The z (vertical) is offset by +32
|
||||||
std::istringstream iss(converted[3]);
|
std::istringstream iss (converted[3]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string coords[2];
|
std::string coords[2];
|
||||||
float offsetCoord;
|
float offsetCoord;
|
||||||
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"origin\"" );
|
REQUIRE (attribute == "\"origin\"");
|
||||||
REQUIRE( coords[0] == "\"-216.00000" );
|
REQUIRE (coords[0] == "\"-216.00000");
|
||||||
REQUIRE( coords[1] == "-1488.000488" );
|
REQUIRE (coords[1] == "-1488.000488");
|
||||||
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
REQUIRE (fabs(-100.00000 - offsetCoord) <= DELTA);
|
||||||
|
|
||||||
SECTION( "Converted angles are valid (Different coordinate system handedness)" ) {
|
SECTION( "Converted angles are valid (Different coordinate system handedness)") {
|
||||||
std::istringstream angleLineStream(converted[4]);
|
std::istringstream angleLineStream(converted[4]);
|
||||||
std::string angleAttribute;
|
std::string angleAttribute;
|
||||||
std::string a;
|
std::string a;
|
||||||
@ -156,210 +156,210 @@ TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityC
|
|||||||
std::stringstream angleStream(a);
|
std::stringstream angleStream(a);
|
||||||
angleStream >> angle;
|
angleStream >> angle;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"angle\"" );
|
REQUIRE (attribute == "\"angle\"");
|
||||||
REQUIRE( fabs( -90.0 - angle) <= DELTA );
|
REQUIRE (fabs (-90.0 - angle) <= DELTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SECTION( "Encountering a new worldspawn reenables all modes" ) {
|
SECTION( "Encountering a new worldspawn reenables all modes") {
|
||||||
std::vector<std::string> basicWorldspawn;
|
std::vector<std::string> basicWorldspawn;
|
||||||
basicWorldspawn.push_back(" type WorldSpawn");
|
basicWorldspawn.push_back (" type WorldSpawn");
|
||||||
|
|
||||||
std::vector<std::string> e;
|
std::vector<std::string> e;
|
||||||
e.push_back(" type PlayerSpawn");
|
e.push_back (" type PlayerSpawn");
|
||||||
e.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
e.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
e.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
e.push_back (" Vector3 angles 180.00000 0.00000 0.00000");
|
||||||
|
|
||||||
std::vector<std::string> u = ec.convert(basicWorldspawn);
|
std::vector<std::string> u = ec.convert(basicWorldspawn);
|
||||||
std::vector<std::string> c = ec.convert(e);
|
std::vector<std::string> c = ec.convert(e);
|
||||||
REQUIRE( c[0] == "\"classname\" \"info_player_deathmatch\"\n" );
|
REQUIRE (c[0] == "\"classname\" \"info_player_deathmatch\"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single PlayerSpawn (teamA) entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single PlayerSpawn (teamA) entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type PlayerSpawn");
|
entity.push_back (" type PlayerSpawn");
|
||||||
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
entity.push_back (" Vector3 angles 180.00000 0.00000 0.00000");
|
||||||
entity.push_back(" Bool8 teamB 0");
|
entity.push_back (" Bool8 teamB 0");
|
||||||
entity.push_back(" Bool8 modeRace 0");
|
entity.push_back (" Bool8 modeRace 0");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"info_player_team1\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"info_player_team1\"\n");
|
||||||
|
|
||||||
// The z (vertical) is offset by +32
|
// The z (vertical) is offset by +32
|
||||||
std::istringstream iss(converted[1]);
|
std::istringstream iss (converted[1]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string coords[2];
|
std::string coords[2];
|
||||||
float offsetCoord;
|
float offsetCoord;
|
||||||
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"origin\"" );
|
REQUIRE (attribute == "\"origin\"");
|
||||||
REQUIRE( coords[0] == "\"-216.00000" );
|
REQUIRE (coords[0] == "\"-216.00000");
|
||||||
REQUIRE( coords[1] == "-1488.000488" );
|
REQUIRE (coords[1] == "-1488.000488");
|
||||||
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
REQUIRE (fabs(-100.00000 - offsetCoord) <= DELTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single PlayerSpawn (non-team) entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single PlayerSpawn (non-team) entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type PlayerSpawn");
|
entity.push_back (" type PlayerSpawn");
|
||||||
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
entity.push_back (" Vector3 angles 180.00000 0.00000 0.00000");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"info_player_deathmatch\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"info_player_deathmatch\"\n");
|
||||||
|
|
||||||
// The z (vertical) is offset by +32
|
// The z (vertical) is offset by +32
|
||||||
std::istringstream iss(converted[1]);
|
std::istringstream iss (converted[1]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string coords[2];
|
std::string coords[2];
|
||||||
float offsetCoord;
|
float offsetCoord;
|
||||||
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"origin\"" );
|
REQUIRE (attribute == "\"origin\"");
|
||||||
REQUIRE( coords[0] == "\"-216.00000" );
|
REQUIRE (coords[0] == "\"-216.00000");
|
||||||
REQUIRE( coords[1] == "-1488.000488" );
|
REQUIRE (coords[1] == "-1488.000488");
|
||||||
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
REQUIRE (fabs(-100.00000 - offsetCoord) <= DELTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single RaceStart entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single RaceStart entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type RaceStart");
|
entity.push_back (" type RaceStart");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n");
|
||||||
REQUIRE( converted[1] == "\"targetname\" \"cp1\"\n" );
|
REQUIRE (converted[1] == "\"targetname\" \"cp1\"\n");
|
||||||
REQUIRE( converted[2] == "\"cnt\" \"1\"\n" );
|
REQUIRE (converted[2] == "\"cnt\" \"1\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single RaceFinish entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single RaceFinish entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type RaceFinish");
|
entity.push_back (" type RaceFinish");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n");
|
||||||
REQUIRE( converted[1] == "\"targetname\" \"finish\"\n" );
|
REQUIRE (converted[1] == "\"targetname\" \"finish\"\n");
|
||||||
REQUIRE( converted[2] == "\"cnt\" \"0\"\n" );
|
REQUIRE (converted[2] == "\"cnt\" \"0\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single Teleporter and related Target can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single Teleporter and related Target can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up Teleporter entity
|
// Mock up Teleporter entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type Teleporter");
|
entity.push_back (" type Teleporter");
|
||||||
entity.push_back(" String32 target tp1");
|
entity.push_back (" String32 target tp1");
|
||||||
|
|
||||||
// Mock up Target entity
|
// Mock up Target entity
|
||||||
std::vector<std::string> entity2;
|
std::vector<std::string> entity2;
|
||||||
entity2.push_back(" type Target");
|
entity2.push_back (" type Target");
|
||||||
entity2.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity2.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity2.push_back(" String32 name tp1");
|
entity2.push_back (" String32 name tp1");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
q.push( entity2 );
|
q.push (entity2);
|
||||||
|
|
||||||
// Match related entities (one pair)
|
// Match related entities (one pair)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert two entities
|
// Convert two entities
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
REQUIRE( converted[0] == "\"classname\" \"trigger_teleport\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"trigger_teleport\"\n");
|
||||||
REQUIRE( converted[1] == "\"target\" \"tp1\"\n" );
|
REQUIRE (converted[1] == "\"target\" \"tp1\"\n");
|
||||||
|
|
||||||
std::vector<std::string> converted2 = ec.convert(entity2);
|
std::vector<std::string> converted2 = ec.convert(entity2);
|
||||||
REQUIRE( converted2[0] == "\"classname\" \"misc_teleporter_dest\"\n" );
|
REQUIRE (converted2[0] == "\"classname\" \"misc_teleporter_dest\"\n");
|
||||||
REQUIRE( converted2[2] == "\"targetname\" \"tp1\"\n" );
|
REQUIRE (converted2[2] == "\"targetname\" \"tp1\"\n");
|
||||||
//
|
//
|
||||||
// The z (vertical) is offset by +32
|
// The z (vertical) is offset by +32
|
||||||
std::istringstream iss(converted2[1]);
|
std::istringstream iss (converted2[1]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string coords[2];
|
std::string coords[2];
|
||||||
float offsetCoord;
|
float offsetCoord;
|
||||||
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
||||||
|
|
||||||
// next REQUIRE fails without busy wait
|
// next REQUIRE fails without busy wait
|
||||||
for( int i = 0; i < 10000000; i++ )
|
for( int i = 0; i < 10000000; i++)
|
||||||
int x = i;
|
int x = i;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"origin\"" );
|
REQUIRE (attribute == "\"origin\"");
|
||||||
REQUIRE( coords[0] == "\"-216.00000" );
|
REQUIRE (coords[0] == "\"-216.00000");
|
||||||
REQUIRE( coords[1] == "-1488.000488" );
|
REQUIRE (coords[1] == "-1488.000488");
|
||||||
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
REQUIRE (fabs(-100.00000 - offsetCoord) <= DELTA);
|
||||||
|
|
||||||
SECTION( "When angle unspecified, defaults to 0.0 (converted to 90.0)" ) {
|
SECTION( "When angle unspecified, defaults to 0.0 (converted to 90.0)") {
|
||||||
std::istringstream angleStream(converted2[3]);
|
std::istringstream angleStream(converted2[3]);
|
||||||
std::string a;
|
std::string a;
|
||||||
float angle;
|
float angle;
|
||||||
@ -367,79 +367,79 @@ TEST_CASE( "r2x: a single Teleporter and related Target can be converted", "[Ent
|
|||||||
a.erase(a.begin()); //removing preceding quote is necessary
|
a.erase(a.begin()); //removing preceding quote is necessary
|
||||||
std::stringstream out(a);
|
std::stringstream out(a);
|
||||||
out >> angle;
|
out >> angle;
|
||||||
REQUIRE( fabs(90.0 - angle) <= DELTA );
|
REQUIRE (fabs(90.0 - angle) <= DELTA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single JumpPad and related Target can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single JumpPad and related Target can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up JumpPad entity
|
// Mock up JumpPad entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type JumpPad");
|
entity.push_back (" type JumpPad");
|
||||||
entity.push_back(" String32 target jp1");
|
entity.push_back (" String32 target jp1");
|
||||||
|
|
||||||
// Mock up Target entity
|
// Mock up Target entity
|
||||||
std::vector<std::string> entity2;
|
std::vector<std::string> entity2;
|
||||||
entity2.push_back(" type Target");
|
entity2.push_back (" type Target");
|
||||||
entity2.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity2.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity2.push_back(" String32 name jp1");
|
entity2.push_back (" String32 name jp1");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
q.push( entity2 );
|
q.push (entity2);
|
||||||
|
|
||||||
// Match related entities (one pair)
|
// Match related entities (one pair)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert two entities
|
// Convert two entities
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
REQUIRE( converted[0] == "\"classname\" \"trigger_push\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"trigger_push\"\n");
|
||||||
REQUIRE( converted[1] == "\"target\" \"jp1\"\n" );
|
REQUIRE (converted[1] == "\"target\" \"jp1\"\n");
|
||||||
|
|
||||||
std::vector<std::string> converted2 = ec.convert(entity2);
|
std::vector<std::string> converted2 = ec.convert(entity2);
|
||||||
REQUIRE( converted2[0] == "\"classname\" \"target_position\"\n" );
|
REQUIRE (converted2[0] == "\"classname\" \"target_position\"\n");
|
||||||
REQUIRE( converted2[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
REQUIRE (converted2[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n");
|
||||||
REQUIRE( converted2[2] == "\"targetname\" \"jp1\"\n" );
|
REQUIRE (converted2[2] == "\"targetname\" \"jp1\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: a single PointLight entity can be converted", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: a single PointLight entity can be converted", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type PointLight");
|
entity.push_back (" type PointLight");
|
||||||
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
entity.push_back(" ColourXRGB32 color ffffc400");
|
entity.push_back (" ColourXRGB32 color ffffc400");
|
||||||
entity.push_back(" Float intensity 1.500000");
|
entity.push_back (" Float intensity 1.500000");
|
||||||
entity.push_back(" Float nearAttenuation 32.000000");
|
entity.push_back (" Float nearAttenuation 32.000000");
|
||||||
entity.push_back(" Float farAttenuation 160.000000");
|
entity.push_back (" Float farAttenuation 160.000000");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"light\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"light\"\n");
|
||||||
REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
REQUIRE (converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n");
|
||||||
REQUIRE( converted[2] == "\"light\" \"75\"\n" );
|
REQUIRE (converted[2] == "\"light\" \"75\"\n");
|
||||||
|
|
||||||
INFO( converted[3] );
|
INFO (converted[3]);
|
||||||
std::istringstream iss(converted[3]);
|
std::istringstream iss (converted[3]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string r;
|
std::string r;
|
||||||
float red;
|
float red;
|
||||||
@ -450,55 +450,55 @@ TEST_CASE( "r2x: a single PointLight entity can be converted", "[EntityConverter
|
|||||||
std::stringstream redStream(r);
|
std::stringstream redStream(r);
|
||||||
redStream >> red;
|
redStream >> red;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"_color\"" );
|
REQUIRE (attribute == "\"_color\"");
|
||||||
|
|
||||||
REQUIRE( fabs( 1.0 - red) <= DELTA );
|
REQUIRE (fabs (1.0 - red) <= DELTA);
|
||||||
REQUIRE( fabs( 0.768627 - green) <= DELTA );
|
REQUIRE (fabs (0.768627 - green) <= DELTA);
|
||||||
REQUIRE( fabs( 0.0 - blue) <= DELTA );
|
REQUIRE (fabs (0.0 - blue) <= DELTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE( "r2x: PointLight defaults to white light of typical intensity", "[EntityConverter]" ) {
|
TEST_CASE ("r2x: PointLight defaults to white light of typical intensity", "[EntityConverter]") {
|
||||||
|
|
||||||
// Instantiate object
|
// Instantiate object
|
||||||
EntityConverter ec (ENTITY_FILENAME);
|
EntityConverter ec (ENTITY_FILENAME);
|
||||||
|
|
||||||
// Mock up entity
|
// Mock up entity
|
||||||
std::vector<std::string> entity;
|
std::vector<std::string> entity;
|
||||||
entity.push_back(" type PointLight");
|
entity.push_back (" type PointLight");
|
||||||
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
entity.push_back (" Vector3 position -216.00000 -132.00000 -1488.000488");
|
||||||
|
|
||||||
// Mock up entity queue
|
// Mock up entity queue
|
||||||
std::queue<std::vector<std::string>> q;
|
std::queue<std::vector<std::string>> q;
|
||||||
q.push( entity );
|
q.push (entity);
|
||||||
|
|
||||||
// Match related entities (none)
|
// Match related entities (none)
|
||||||
ec.extractMapInfo( q );
|
ec.extractMapInfo (q);
|
||||||
|
|
||||||
// Convert a single entity
|
// Convert a single entity
|
||||||
std::vector<std::string> converted = ec.convert(entity);
|
std::vector<std::string> converted = ec.convert(entity);
|
||||||
|
|
||||||
REQUIRE( converted[0] == "\"classname\" \"light\"\n" );
|
REQUIRE (converted[0] == "\"classname\" \"light\"\n");
|
||||||
REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
REQUIRE (converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n");
|
||||||
REQUIRE( converted[2] == "\"light\" \"50\"\n" );
|
REQUIRE (converted[2] == "\"light\" \"50\"\n");
|
||||||
|
|
||||||
INFO( converted[3] );
|
INFO (converted[3]);
|
||||||
std::istringstream iss(converted[3]);
|
std::istringstream iss (converted[3]);
|
||||||
std::string attribute;
|
std::string attribute;
|
||||||
std::string r;
|
std::string r;
|
||||||
float red;
|
float red;
|
||||||
float green;
|
float green;
|
||||||
float blue;
|
float blue;
|
||||||
iss >> attribute >> r >> green >> blue;
|
iss >> attribute >> r >> green >> blue;
|
||||||
r.erase(r.begin()); //removing preceding quote is necessary
|
r.erase (r.begin()); //removing preceding quote is necessary
|
||||||
std::stringstream redStream(r);
|
std::stringstream redStream (r);
|
||||||
redStream >> red;
|
redStream >> red;
|
||||||
|
|
||||||
REQUIRE( attribute == "\"_color\"" );
|
REQUIRE (attribute == "\"_color\"");
|
||||||
|
|
||||||
REQUIRE( fabs( 0.0 - red) <= DELTA );
|
REQUIRE (fabs (0.0 - red) <= DELTA);
|
||||||
REQUIRE( fabs( 0.0 - green) <= DELTA );
|
REQUIRE (fabs (0.0 - green) <= DELTA);
|
||||||
REQUIRE( fabs( 0.0 - blue) <= DELTA );
|
REQUIRE (fabs (0.0 - blue) <= DELTA);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Revision: none
|
* Revision: none
|
||||||
* Compiler: gcc
|
* Compiler: gcc
|
||||||
*
|
*
|
||||||
* Author: suhrke@teknik.io
|
* Author: surkeh@protonmail.com
|
||||||
*
|
*
|
||||||
* =====================================================================================
|
* =====================================================================================
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user