2017-06-07 06:52:54 +05:30
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: EntityConverter.hpp
|
|
|
|
*
|
|
|
|
* Description: Convert reflex entities to xonotic entities
|
2017-07-03 08:52:09 +05:30
|
|
|
* - Simple; operates on single entity at a time
|
|
|
|
* - Only context provided is information on what entities are related.
|
|
|
|
* (i.e. a teleport and it's destination) Can get this information
|
|
|
|
* through the pre-scan constructor of the .map file or by providing
|
|
|
|
* a queue of all the entities in the file.
|
|
|
|
* - Throws exceptions upon encountering malformed entities and when
|
|
|
|
* IO errors occur during object instantiation
|
2017-06-07 06:52:54 +05:30
|
|
|
*
|
|
|
|
* Version: 1.0
|
|
|
|
* Created: 05/27/2017 08:21:14 AM
|
|
|
|
* Revision: none
|
|
|
|
* Compiler: gcc
|
|
|
|
*
|
|
|
|
* Author: suhrke@teknik.io
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ENTITY_CONVERTER_HPP
|
|
|
|
#define ENTITY_CONVERTER_HPP
|
|
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2017-07-04 06:40:05 +05:30
|
|
|
#include <queue>
|
2017-06-07 06:52:54 +05:30
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class EntityConverter
|
|
|
|
{
|
|
|
|
public:
|
2017-07-03 08:52:09 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: Constructor
|
|
|
|
* Description: Creates entity format mapping
|
|
|
|
* CAUTION: Requires matchRelated method to be called after this
|
|
|
|
* Requires: .ent filename for mapping entities from reflex format to xonotic format
|
|
|
|
* THROWS: runtime_error on .ent format error
|
|
|
|
* THROWS: std::ios::failure on IO failure
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
EntityConverter(std::string entityMapFile);
|
2017-07-04 05:34:06 +05:30
|
|
|
/* *--------------------------------------------------------------------------------------
|
2017-07-03 08:52:09 +05:30
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: Constructor
|
|
|
|
* Description: Creates entity format mapping and pre-scans for related entities
|
|
|
|
* Parameter: string entityMapFile, file maps source to target entity formats
|
|
|
|
* Parameter: string reflexMapFile, for pre-scan
|
|
|
|
* THROWS: runtime_error on .ent format error
|
|
|
|
* THROWS: std::ios::failure on IO failure
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-06-07 14:16:43 +05:30
|
|
|
EntityConverter(std::string entityMapFile, std::string reflexMapFile);
|
2017-07-03 08:52:09 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: convert
|
|
|
|
* Description: Converts a single entity from reflex to xonotic format
|
2017-07-03 12:11:59 +05:30
|
|
|
* Parameter: vector of strings lines, lines that comprise a single entity
|
2017-07-03 08:52:09 +05:30
|
|
|
* Return: vector of strings, single entity in the converted format
|
2017-07-05 15:51:51 +05:30
|
|
|
* *IF entity is not supported, returns EMPTY vector
|
2017-07-03 08:52:09 +05:30
|
|
|
* THROWS: runtime_error on malformed .map file
|
2017-07-03 12:11:59 +05:30
|
|
|
* THROWS: runtime_error when called before related entities are matched
|
2017-07-03 08:52:09 +05:30
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-06-07 06:52:54 +05:30
|
|
|
std::vector<std::string> convert(std::vector<std::string> lines);
|
2017-07-03 12:11:59 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: matchRelated
|
|
|
|
* Description: Finds related entities (targets of teleports, etc), call after parsing
|
|
|
|
* the entire .map
|
|
|
|
* Parameter: queue of vector of string entities, ALL entities in a .map file
|
|
|
|
* THROWS: runtime_error when encountering malformed entity
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void matchRelated(std::queue<std::vector<std::string>> entities);
|
2017-07-03 08:52:09 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-07 06:52:54 +05:30
|
|
|
protected:
|
2017-07-03 08:52:09 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-07 06:52:54 +05:30
|
|
|
private:
|
2017-07-05 17:40:31 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: getOffsetHeight
|
|
|
|
* Description: Returns a constant
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
float getHeightOffset() { return 32.0; }
|
|
|
|
|
2017-07-03 08:52:09 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: getAttributeType
|
|
|
|
* Description: Extracts the type from a line
|
|
|
|
* Parameter: string "line", entity keyword followed by the type
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-06-07 06:52:54 +05:30
|
|
|
std::string getAttributeType(std::string line);
|
2017-07-03 08:52:09 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: mapEntities
|
|
|
|
* Description: Prepare pickupMapping_
|
|
|
|
* Parameter: string mapFile, filename of pickup mapping
|
|
|
|
* Return: true if no error, false if error
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void mapEntities(std::string mapFile);
|
2017-07-04 10:49:50 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: addIfRelated
|
|
|
|
* Description: If the entity contains a related target/etc, add to map
|
|
|
|
* Paramater: string line, the previous line (contains entity type)
|
|
|
|
* Parameter: istream is, an ifstream or a stringstream containing a
|
|
|
|
* single entity
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void addIfRelated(std::string &line, std::istream &is);
|
2017-07-05 17:40:31 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* 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);
|
2017-07-03 08:52:09 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: convert~EntityName~
|
|
|
|
* Description: Multiple methods to convert entity from reflex to xonotic format
|
|
|
|
* Parameter: vector of strings entity, multi-lined entity
|
|
|
|
* Return: vector of strings, the converted entity
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
std::vector<std::string> convertPickup(std::vector<std::string> &entity);
|
|
|
|
std::vector<std::string> convertPlayerSpawn(std::vector<std::string> &entity);
|
|
|
|
std::vector<std::string> convertJumpPad(std::vector<std::string> &entity);
|
|
|
|
std::vector<std::string> convertTeleporter(std::vector<std::string> &entity);
|
|
|
|
std::vector<std::string> convertTarget(std::vector<std::string> &entity);
|
|
|
|
std::vector<std::string> convertRaceStart(std::vector<std::string> &entity);
|
|
|
|
std::vector<std::string> convertRaceFinish(std::vector<std::string> &entity);
|
|
|
|
|
2017-07-05 17:40:31 +05:30
|
|
|
|
2017-06-07 14:16:43 +05:30
|
|
|
void printMapping(); //DEBUG
|
|
|
|
void printTargetSources(); //DEBUG
|
|
|
|
|
2017-07-03 08:52:09 +05:30
|
|
|
// Related entities must be matched prior to entity conversion
|
|
|
|
bool areEntitiesMatched_;
|
2017-06-07 14:16:43 +05:30
|
|
|
// Map Reflex pickup IDs to Xonotic pickup identifiers
|
|
|
|
std::map<int, std::string> pickupMapping_;
|
|
|
|
// Map targets (by name) to their source type
|
|
|
|
std::map<std::string, std::string> targetMap_;
|
2017-06-07 06:52:54 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
#endif //ENTITY_CONVERTER_HPP
|
|
|
|
|