Offset height for teleport desinations, pickups, and player spawns

This commit is contained in:
suhrke 2017-07-05 05:10:31 -07:00
parent dcf6e76f39
commit f6b1b9ca41
3 changed files with 93 additions and 13 deletions

View File

@ -19,6 +19,7 @@
#include <exception>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
@ -272,7 +273,7 @@ EntityConverter::convertPickup(std::vector<std::string> &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<std::string> &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<std::string> &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<std::string> &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()

View File

@ -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<std::string> convertRaceStart(std::vector<std::string> &entity);
std::vector<std::string> convertRaceFinish(std::vector<std::string> &entity);
void printMapping(); //DEBUG
void printTargetSources(); //DEBUG

View File

@ -18,12 +18,15 @@
#ifndef CATCH_CONFIG_MAIN
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <cmath>
#include <queue>
#include <vector>
#include <sstream>
#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<std::string> 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<std::string> 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<std::string> 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 );
}