From f6b1b9ca41f9bfe06d6cdd5b8b0473c0e338f859 Mon Sep 17 00:00:00 2001 From: suhrke Date: Wed, 5 Jul 2017 05:10:31 -0700 Subject: [PATCH] Offset height for teleport desinations, pickups, and player spawns --- ReflexToQ3/includes/EntityConverter.cpp | 42 +++++++++++++++++++------ ReflexToQ3/includes/EntityConverter.hpp | 22 +++++++++++++ ReflexToQ3/test/catch.cpp | 42 +++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 13 deletions(-) diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index 0d24a41..4343d74 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -272,7 +273,7 @@ EntityConverter::convertPickup(std::vector &lines) // coordinates reordered to x, z, y std::stringstream oss2; oss2 << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << - coords[1] << "\"" << std::endl; + offsetHeight(coords[1]) << "\"" << std::endl; convertedLines.push_back ( oss2.str() ); return convertedLines; } @@ -367,7 +368,7 @@ EntityConverter::convertPlayerSpawn(std::vector &lines) std::stringstream oss; // coordinates reordered to x, z, y oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << - coords[1] << "\"" << std::endl; + offsetHeight(coords[1]) << "\"" << std::endl; convertedLines.push_back ( oss.str() ); std::stringstream oss2; oss2 << "\"angle\" \"" << angle << "\"" << std::endl; @@ -482,24 +483,30 @@ EntityConverter::convertTarget(std::vector &lines) if ( havePosition && haveName) { if ( targetMap_[targetName] == "Teleporter") { convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" ); + // coordinates reordered to x, z, y + // teleporter height is OFFSET + std::stringstream oss; + oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << + offsetHeight(coords[1]) << "\"" << std::endl; + convertedLines.push_back ( oss.str() ); } else if ( targetMap_[targetName] == "JumpPad") { convertedLines.push_back ( "\"classname\" \"target_position\"\n" ); + // coordinates reordered to x, z, y + std::stringstream oss; + oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << + coords[1] << "\"" << std::endl; + convertedLines.push_back ( oss.str() ); } - // coordinates reordered to x, z, y - std::stringstream oss2; - oss2 << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << - coords[1] << "\"" << std::endl; - convertedLines.push_back ( oss2.str() ); std::stringstream oss; oss << "\"targetname\" \"" << targetName << "\"" << std::endl; convertedLines.push_back ( oss.str() ); // Write angle only if position and name exist if ( haveAngle ) { - std::stringstream oss3; - oss3 << "\"angle\" \"" << angle << "\"" << std::endl; - convertedLines.push_back (oss3.str() ); + std::stringstream oss2; + oss2 << "\"angle\" \"" << angle << "\"" << std::endl; + convertedLines.push_back (oss2.str() ); } return convertedLines; } @@ -535,6 +542,21 @@ EntityConverter::convertRaceFinish(std::vector &lines) +std::string +EntityConverter::offsetHeight(std::string coordinate) +{ + std::istringstream iss(coordinate); + float c; + iss >> c; + c += getHeightOffset(); + + std::stringstream ss; + ss << std::fixed << std::setprecision(5) << c; + return ss.str(); +} + + + // DEBUG void EntityConverter::printMapping() diff --git a/ReflexToQ3/includes/EntityConverter.hpp b/ReflexToQ3/includes/EntityConverter.hpp index 57fa1c5..5749f42 100644 --- a/ReflexToQ3/includes/EntityConverter.hpp +++ b/ReflexToQ3/includes/EntityConverter.hpp @@ -89,6 +89,16 @@ class EntityConverter private: + + /* + *-------------------------------------------------------------------------------------- + * Class: EntityConverter + * Method: EntityConverter :: getOffsetHeight + * Description: Returns a constant + *-------------------------------------------------------------------------------------- + */ + float getHeightOffset() { return 32.0; } + /* *-------------------------------------------------------------------------------------- * Class: EntityConverter @@ -119,6 +129,17 @@ class EntityConverter *-------------------------------------------------------------------------------------- */ void addIfRelated(std::string &line, std::istream &is); + /* + *-------------------------------------------------------------------------------------- + * Class: EntityConverter + * Method: EntityConverter :: offsetHeight + * Description: Reflex coordinates place entities at the ground and Xonotic entities + * are at about center of player height. Offset accordingly. + * Paramater: string coordinate, float value passed as string + * Return: string, float value passed as string + *-------------------------------------------------------------------------------------- + */ + std::string offsetHeight(std::string coordinate); /* *-------------------------------------------------------------------------------------- @@ -137,6 +158,7 @@ class EntityConverter std::vector convertRaceStart(std::vector &entity); std::vector convertRaceFinish(std::vector &entity); + void printMapping(); //DEBUG void printTargetSources(); //DEBUG diff --git a/ReflexToQ3/test/catch.cpp b/ReflexToQ3/test/catch.cpp index 5bad903..ee1090b 100644 --- a/ReflexToQ3/test/catch.cpp +++ b/ReflexToQ3/test/catch.cpp @@ -18,12 +18,15 @@ #ifndef CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN #include "catch.hpp" +#include #include #include +#include #include "EntityConverter.hpp" #define PICKUP_FILENAME "r2x.pck" +#define DELTA 0.00001 @@ -74,7 +77,18 @@ TEST_CASE( "r2x: a single Pickup entity can be converted", "[EntityConverter]" ) std::vector converted = ec.convert(entity); REQUIRE( converted[0] == "\"classname\" \"weapon_grenadelauncher\"\n" ); - REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" ); + + // The z (vertical) is offset + std::istringstream iss(converted[1]); + std::string attribute; + std::string coords[2]; + float offsetCoord; + iss >> attribute >> coords[0] >> coords[1] >> offsetCoord; + + REQUIRE( attribute == "\"origin\"" ); + REQUIRE( coords[0] == "\"-216.00000" ); + REQUIRE( coords[1] == "-1488.000488" ); + REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA ); } @@ -103,8 +117,19 @@ TEST_CASE( "r2x: a single PlayerSpawn (teamA) entity can be converted", "[Entity std::vector converted = ec.convert(entity); REQUIRE( converted[0] == "\"classname\" \"info_player_team1\"\n" ); - REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" ); REQUIRE( converted[2] == "\"angle\" \"180.00000\"\n" ); + + // The z (vertical) is offset + std::istringstream iss(converted[1]); + std::string attribute; + std::string coords[2]; + float offsetCoord; + iss >> attribute >> coords[0] >> coords[1] >> offsetCoord; + + REQUIRE( attribute == "\"origin\"" ); + REQUIRE( coords[0] == "\"-216.00000" ); + REQUIRE( coords[1] == "-1488.000488" ); + REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA ); } @@ -192,8 +217,19 @@ TEST_CASE( "r2x: a single Teleporter and related Target can be converted", "[Ent std::vector converted2 = ec.convert(entity2); REQUIRE( converted2[0] == "\"classname\" \"misc_teleporter_dest\"\n" ); - REQUIRE( converted2[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" ); REQUIRE( converted2[2] == "\"targetname\" \"tp1\"\n" ); + // + // The z (vertical) is offset + std::istringstream iss(converted2[1]); + std::string attribute; + std::string coords[2]; + float offsetCoord; + iss >> attribute >> coords[0] >> coords[1] >> offsetCoord; + + REQUIRE( attribute == "\"origin\"" ); + REQUIRE( coords[0] == "\"-216.00000" ); + REQUIRE( coords[1] == "-1488.000488" ); + REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA ); }