Added extractMapInfo(vector---) + finish const correct functions
This commit is contained in:
parent
3b73c4300a
commit
100c830c83
@ -84,15 +84,6 @@ EntityConverter::EntityConverter(const std::string &entityMapFile,
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*--------------------------------------------------------------------------------------
|
||||
* Class: EntityConverter
|
||||
* Method: EntityConverter :: extractMapInfo
|
||||
* Description: Read through entities, matching related as necessary
|
||||
* Note: For now, accomplishes the same goal as the pre-scan
|
||||
* constructor
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
|
||||
{
|
||||
@ -101,7 +92,7 @@ EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
|
||||
}
|
||||
else {
|
||||
while ( ! entities.empty() ) {
|
||||
std::vector<std::string> entity = entities.front();
|
||||
std::vector<std::string> entity( entities.front() );
|
||||
entities.pop();
|
||||
|
||||
std::stringstream ss;
|
||||
@ -120,6 +111,32 @@ EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
|
||||
|
||||
|
||||
|
||||
void
|
||||
EntityConverter::extractMapInfo(const std::vector<std::vector<std::string>> &entities)
|
||||
{
|
||||
if( haveMapInfo_ ) {
|
||||
std::cerr << "Map info already extracted, doing nothing" << std::endl;
|
||||
}
|
||||
else {
|
||||
for ( int i = 0; i < entities.size(); i++ ) {
|
||||
std::vector<std::string> entity( entities[i] );
|
||||
|
||||
std::stringstream ss;
|
||||
std::copy(entity.begin(), entity.end(),
|
||||
std::ostream_iterator<std::string>(ss, "\n"));
|
||||
|
||||
std::string nextLine;
|
||||
if ( getline(ss, nextLine )) {
|
||||
extractFromEntity(nextLine, ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
haveMapInfo_ = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convert(const std::vector<std::string> &lines)
|
||||
{
|
||||
@ -208,7 +225,7 @@ EntityConverter::convert(const std::vector<std::string> &lines)
|
||||
* PROTECTED
|
||||
*-----------------------------------------------------------------------------*/
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertPickup(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertPickup(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
//can ignore angle of pickups in xonotic format
|
||||
@ -245,7 +262,7 @@ EntityConverter::convertPickup(const std::vector<std::string> &lines)
|
||||
|
||||
if ( havePosition && havePickupID ) {
|
||||
std::stringstream pickupStream;
|
||||
pickupStream << "\"classname\" \"" << pickupMapping_[pickupID] << "\"" << std::endl;
|
||||
pickupStream << "\"classname\" \"" << pickupMapping_.find(pickupID)->second << "\"" << std::endl;
|
||||
convertedLines.push_back ( pickupStream.str() );
|
||||
// coordinates reordered to x, z, y
|
||||
std::stringstream positionStream;
|
||||
@ -272,7 +289,7 @@ EntityConverter::convertPickup(const std::vector<std::string> &lines)
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
// Requires position coordinate
|
||||
@ -377,7 +394,7 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertJumpPad(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertJumpPad(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
std::string targetName;
|
||||
@ -402,7 +419,7 @@ EntityConverter::convertJumpPad(const std::vector<std::string> &lines)
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertTeleporter(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertTeleporter(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
std::string targetName;
|
||||
@ -427,7 +444,7 @@ EntityConverter::convertTeleporter(const std::vector<std::string> &lines)
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertTarget(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertTarget(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
//position and name required, angles optional
|
||||
@ -475,7 +492,7 @@ EntityConverter::convertTarget(const std::vector<std::string> &lines)
|
||||
}
|
||||
|
||||
if ( havePosition && haveName) {
|
||||
if ( targetMap_[targetName] == "Teleporter") {
|
||||
if ( targetMap_.find(targetName)->second == "Teleporter") {
|
||||
convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" );
|
||||
// coordinates reordered to x, z, y
|
||||
// teleporter height is OFFSET
|
||||
@ -484,7 +501,7 @@ EntityConverter::convertTarget(const std::vector<std::string> &lines)
|
||||
offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl;
|
||||
convertedLines.push_back ( oss.str() );
|
||||
}
|
||||
else if ( targetMap_[targetName] == "JumpPad") {
|
||||
else if ( targetMap_.find(targetName)->second == "JumpPad") {
|
||||
convertedLines.push_back ( "\"classname\" \"target_position\"\n" );
|
||||
// coordinates reordered to x, z, y
|
||||
std::stringstream oss;
|
||||
@ -513,7 +530,7 @@ EntityConverter::convertTarget(const std::vector<std::string> &lines)
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertRaceStart(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertRaceStart(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
||||
@ -525,7 +542,7 @@ EntityConverter::convertRaceStart(const std::vector<std::string> &lines)
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertRaceFinish(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertRaceFinish(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
|
||||
@ -537,7 +554,7 @@ EntityConverter::convertRaceFinish(const std::vector<std::string> &lines)
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertPointLight(const std::vector<std::string> &lines)
|
||||
EntityConverter::convertPointLight(const std::vector<std::string> &lines) const
|
||||
{
|
||||
std::vector<std::string> convertedLines;
|
||||
//position and intensity required, color optional
|
||||
@ -705,7 +722,7 @@ EntityConverter::offset(const std::string &value, const float amount) const
|
||||
|
||||
|
||||
void
|
||||
EntityConverter::hexToRGB(const std::string &hex, float &r, float &g, float &b)
|
||||
EntityConverter::hexToRGB(const std::string &hex, float &r, float &g, float &b) const
|
||||
{
|
||||
unsigned int value;
|
||||
std::stringstream ss;
|
||||
@ -734,19 +751,21 @@ EntityConverter::adjustBrightness(const std::string &value) const
|
||||
|
||||
// DEBUG
|
||||
void
|
||||
EntityConverter::printMapping()
|
||||
EntityConverter::printMapping() const
|
||||
{
|
||||
std::map<int, std::string>::iterator it;
|
||||
for (it=pickupMapping_.begin(); it!=pickupMapping_.end(); ++it)
|
||||
std::cout << std::endl << "Reflex pickup ID mapped to Xonotic pickup names: " << std::endl;
|
||||
std::map<int, std::string>::const_iterator it;
|
||||
for ( it=pickupMapping_.begin(); it!=pickupMapping_.end(); ++it )
|
||||
std::cout << it->first << " => " << it->second << std::endl;
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
void
|
||||
EntityConverter::printTargetSources()
|
||||
EntityConverter::printTargetSources() const
|
||||
{
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for (it=targetMap_.begin(); it!=targetMap_.end(); ++it)
|
||||
std::cout << std::endl << "Target and Sources: " << std::endl;
|
||||
std::map<std::string, std::string>::const_iterator it;
|
||||
for ( it=targetMap_.begin(); it!=targetMap_.end(); ++it )
|
||||
std::cout << it->first << " => " << it->second << std::endl;
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,17 @@ class EntityConverter
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
void extractMapInfo(std::queue<std::vector<std::string>> entities);
|
||||
/*
|
||||
*--------------------------------------------------------------------------------------
|
||||
* Class: EntityConverter
|
||||
* Method: EntityConverter :: extractMapInfo
|
||||
* Description: Get information needed by the converter that can't be obtained
|
||||
* in entity-by-entity conversion (teleport and jump pad
|
||||
* Parameter: vector of vector of string entities, ALL entities in a .map file
|
||||
* THROWS: runtime_error when encountering malformed entity
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
void extractMapInfo(const std::vector<std::vector<std::string>> &entities);
|
||||
|
||||
|
||||
|
||||
@ -113,14 +124,14 @@ class EntityConverter
|
||||
* Return: vector of strings, the converted entity
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
std::vector<std::string> convertPickup(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertPlayerSpawn(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertJumpPad(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertTeleporter(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertTarget(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertRaceStart(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertRaceFinish(const std::vector<std::string> &lines);
|
||||
std::vector<std::string> convertPointLight(const std::vector<std::string> &lines);
|
||||
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> convertJumpPad(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> convertRaceStart(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;
|
||||
|
||||
|
||||
|
||||
@ -194,7 +205,7 @@ class EntityConverter
|
||||
* Parameter: float b, RETURN BY REFERENCE: converted blue value
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
void hexToRGB(const std::string &hex, float &r, float &g, float &b);
|
||||
void hexToRGB(const std::string &hex, float &r, float &g, float &b) const;
|
||||
/*
|
||||
*--------------------------------------------------------------------------------------
|
||||
* Class: EntityConverter
|
||||
@ -207,8 +218,8 @@ class EntityConverter
|
||||
|
||||
|
||||
|
||||
void printMapping(); //DEBUG
|
||||
void printTargetSources(); //DEBUG
|
||||
void printMapping() const; //DEBUG
|
||||
void printTargetSources() const; //DEBUG
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user