diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index 8dac498..96e2614 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -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> entities) { @@ -101,7 +92,7 @@ EntityConverter::extractMapInfo(std::queue> entities) } else { while ( ! entities.empty() ) { - std::vector entity = entities.front(); + std::vector entity( entities.front() ); entities.pop(); std::stringstream ss; @@ -120,6 +111,32 @@ EntityConverter::extractMapInfo(std::queue> entities) +void +EntityConverter::extractMapInfo(const std::vector> &entities) +{ + if( haveMapInfo_ ) { + std::cerr << "Map info already extracted, doing nothing" << std::endl; + } + else { + for ( int i = 0; i < entities.size(); i++ ) { + std::vector entity( entities[i] ); + + std::stringstream ss; + std::copy(entity.begin(), entity.end(), + std::ostream_iterator(ss, "\n")); + + std::string nextLine; + if ( getline(ss, nextLine )) { + extractFromEntity(nextLine, ss); + } + } + } + + haveMapInfo_ = true; +} + + + std::vector EntityConverter::convert(const std::vector &lines) { @@ -208,7 +225,7 @@ EntityConverter::convert(const std::vector &lines) * PROTECTED *-----------------------------------------------------------------------------*/ std::vector -EntityConverter::convertPickup(const std::vector &lines) +EntityConverter::convertPickup(const std::vector &lines) const { std::vector convertedLines; //can ignore angle of pickups in xonotic format @@ -245,7 +262,7 @@ EntityConverter::convertPickup(const std::vector &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 &lines) *-------------------------------------------------------------------------------------- */ std::vector -EntityConverter::convertPlayerSpawn(const std::vector &lines) +EntityConverter::convertPlayerSpawn(const std::vector &lines) const { std::vector convertedLines; // Requires position coordinate @@ -377,7 +394,7 @@ EntityConverter::convertPlayerSpawn(const std::vector &lines) std::vector -EntityConverter::convertJumpPad(const std::vector &lines) +EntityConverter::convertJumpPad(const std::vector &lines) const { std::vector convertedLines; std::string targetName; @@ -402,7 +419,7 @@ EntityConverter::convertJumpPad(const std::vector &lines) std::vector -EntityConverter::convertTeleporter(const std::vector &lines) +EntityConverter::convertTeleporter(const std::vector &lines) const { std::vector convertedLines; std::string targetName; @@ -427,7 +444,7 @@ EntityConverter::convertTeleporter(const std::vector &lines) std::vector -EntityConverter::convertTarget(const std::vector &lines) +EntityConverter::convertTarget(const std::vector &lines) const { std::vector convertedLines; //position and name required, angles optional @@ -475,7 +492,7 @@ EntityConverter::convertTarget(const std::vector &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 &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 &lines) std::vector -EntityConverter::convertRaceStart(const std::vector &lines) +EntityConverter::convertRaceStart(const std::vector &lines) const { std::vector convertedLines; convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n"); @@ -525,7 +542,7 @@ EntityConverter::convertRaceStart(const std::vector &lines) std::vector -EntityConverter::convertRaceFinish(const std::vector &lines) +EntityConverter::convertRaceFinish(const std::vector &lines) const { std::vector convertedLines; convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n"); @@ -537,7 +554,7 @@ EntityConverter::convertRaceFinish(const std::vector &lines) std::vector -EntityConverter::convertPointLight(const std::vector &lines) +EntityConverter::convertPointLight(const std::vector &lines) const { std::vector 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::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::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::iterator it; - for (it=targetMap_.begin(); it!=targetMap_.end(); ++it) + std::cout << std::endl << "Target and Sources: " << std::endl; + std::map::const_iterator it; + for ( it=targetMap_.begin(); it!=targetMap_.end(); ++it ) std::cout << it->first << " => " << it->second << std::endl; } diff --git a/ReflexToQ3/includes/EntityConverter.hpp b/ReflexToQ3/includes/EntityConverter.hpp index 456a00f..52cce09 100644 --- a/ReflexToQ3/includes/EntityConverter.hpp +++ b/ReflexToQ3/includes/EntityConverter.hpp @@ -98,6 +98,17 @@ class EntityConverter *-------------------------------------------------------------------------------------- */ void extractMapInfo(std::queue> 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> &entities); @@ -113,14 +124,14 @@ class EntityConverter * Return: vector of strings, the converted entity *-------------------------------------------------------------------------------------- */ - std::vector convertPickup(const std::vector &lines); - std::vector convertPlayerSpawn(const std::vector &lines); - std::vector convertJumpPad(const std::vector &lines); - std::vector convertTeleporter(const std::vector &lines); - std::vector convertTarget(const std::vector &lines); - std::vector convertRaceStart(const std::vector &lines); - std::vector convertRaceFinish(const std::vector &lines); - std::vector convertPointLight(const std::vector &lines); + std::vector convertPickup(const std::vector &lines) const; + std::vector convertPlayerSpawn(const std::vector &lines) const; + std::vector convertJumpPad(const std::vector &lines) const; + std::vector convertTeleporter(const std::vector &lines) const; + std::vector convertTarget(const std::vector &lines) const; + std::vector convertRaceStart(const std::vector &lines) const; + std::vector convertRaceFinish(const std::vector &lines) const; + std::vector convertPointLight(const std::vector &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 };