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>
|
|
|
|
|
2017-07-06 04:30:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-06 00:23:45 +05:30
|
|
|
|
2017-07-06 07:28:07 +05:30
|
|
|
|
|
|
|
|
|
|
|
struct MapInfo
|
|
|
|
{
|
|
|
|
bool cts;
|
|
|
|
bool ctf;
|
|
|
|
bool ffa;
|
|
|
|
bool tdm;
|
|
|
|
bool duel;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-07 06:52:54 +05:30
|
|
|
class EntityConverter
|
|
|
|
{
|
|
|
|
public:
|
2017-07-03 08:52:09 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: Constructor
|
|
|
|
* Description: Creates entity format mapping
|
2017-07-06 07:28:07 +05:30
|
|
|
* CAUTION: Requires extractMapInfo method to be called after this
|
2017-07-03 08:52:09 +05:30
|
|
|
* 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
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 09:02:49 +05:30
|
|
|
EntityConverter(const std::string &entityMapFile);
|
2017-07-04 05:34:06 +05:30
|
|
|
/* *--------------------------------------------------------------------------------------
|
2017-07-03 08:52:09 +05:30
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: Constructor
|
2017-07-06 07:28:07 +05:30
|
|
|
* Description: Creates entity format mapping and pre-scans for map info
|
2017-07-03 08:52:09 +05:30
|
|
|
* 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-07-06 09:02:49 +05:30
|
|
|
EntityConverter(const std::string &entityMapFile, const 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-06 07:28:07 +05:30
|
|
|
* THROWS: runtime_error when called before map info has been extracted
|
2017-07-03 08:52:09 +05:30
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 09:02:49 +05:30
|
|
|
std::vector<std::string> convert(const std::vector<std::string> &lines);
|
2017-07-03 12:11:59 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
2017-07-06 07:28:07 +05:30
|
|
|
* Method: EntityConverter :: extractMapInfo
|
|
|
|
* Description: Get information needed by the converter that can't be obtained
|
|
|
|
* in entity-by-entity conversion (teleport and jump pad
|
2017-07-03 12:11:59 +05:30
|
|
|
* Parameter: queue of vector of string entities, ALL entities in a .map file
|
|
|
|
* THROWS: runtime_error when encountering malformed entity
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 09:02:49 +05:30
|
|
|
void extractMapInfo(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-05 17:40:31 +05:30
|
|
|
|
2017-07-06 04:30:22 +05:30
|
|
|
|
2017-07-05 17:40:31 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
2017-07-06 04:30:22 +05:30
|
|
|
* Method: EntityConverter :: convert~EntityName~
|
|
|
|
* Description: Multiple methods to convert entity from reflex to xonotic format
|
2017-07-06 11:06:39 +05:30
|
|
|
* Parameter: vector of strings lines, multi-lined entity
|
2017-07-06 04:30:22 +05:30
|
|
|
* Return: vector of strings, the converted entity
|
2017-07-05 17:40:31 +05:30
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 11:06:39 +05:30
|
|
|
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);
|
2017-07-06 04:30:22 +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-07-06 07:28:07 +05:30
|
|
|
// Related entities must be matched prior to entity conversion
|
|
|
|
bool haveMapInfo_;
|
|
|
|
MapInfo mapinfo_;
|
|
|
|
|
2017-07-06 04:30:22 +05:30
|
|
|
// Offsets for item/spawn height
|
|
|
|
const float OFFSET_PLAYER;
|
|
|
|
const float OFFSET_PICKUP;
|
2017-07-06 11:06:39 +05:30
|
|
|
// Brightness adjustment factor
|
2017-07-06 11:13:24 +05:30
|
|
|
const float BRIGHTNESS_ADJUST;
|
2017-07-05 17:40:31 +05:30
|
|
|
|
2017-07-06 04:30:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
private:
|
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-07-06 09:02:49 +05:30
|
|
|
std::string getAttributeType(const std::string &line) const;
|
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
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 09:02:49 +05:30
|
|
|
void mapEntities(const std::string &mapFile);
|
2017-07-04 10:49:50 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
2017-07-06 07:28:07 +05:30
|
|
|
* Method: EntityConverter :: extractFromEntity
|
|
|
|
* Description: Get map info from a single entity
|
2017-07-04 10:49:50 +05:30
|
|
|
* Paramater: string line, the previous line (contains entity type)
|
|
|
|
* Parameter: istream is, an ifstream or a stringstream containing a
|
|
|
|
* single entity
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 09:02:49 +05:30
|
|
|
void extractFromEntity(const std::string &line, std::istream &is);
|
2017-07-03 08:52:09 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
2017-07-06 04:30:22 +05:30
|
|
|
* Method: EntityConverter :: offset
|
|
|
|
* Description: Reflex coordinates place entities at the ground and Xonotic entities
|
|
|
|
* are at about center of player height. Offset accordingly.
|
|
|
|
* Paramater: string value, float value passed as string
|
|
|
|
* Parameter: float offset, amount to add to value
|
|
|
|
* Return: string, float value passed as string
|
2017-07-03 08:52:09 +05:30
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
2017-07-06 09:02:49 +05:30
|
|
|
std::string offset(const std::string &value, const float offset) const;
|
2017-07-06 11:06:39 +05:30
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: hexToRGB
|
|
|
|
* Description: Convert 8 digit hex value into separate red, green, and blue values
|
|
|
|
* Parameter: string hex, inputted hex value
|
|
|
|
* Parameter: float r, RETURN BY REFERENCE: converted red value
|
|
|
|
* Parameter: float g, RETURN BY REFERENCE: converted green value
|
|
|
|
* Parameter: float b, RETURN BY REFERENCE: converted blue value
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void hexToRGB(const std::string &hex, float &r, float &g, float &b);
|
|
|
|
/*
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
* Class: EntityConverter
|
|
|
|
* Method: EntityConverter :: adjustBrightness
|
|
|
|
* Description: Reflex uses significantly smaller values than Xonotic -> adjust
|
|
|
|
* Parameter: string value, original brightness value
|
|
|
|
*--------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
int adjustBrightness(const std::string &value) const;
|
2017-07-06 04:30:22 +05:30
|
|
|
|
2017-07-03 08:52:09 +05:30
|
|
|
|
2017-07-05 17:40:31 +05:30
|
|
|
|
2017-06-07 14:16:43 +05:30
|
|
|
void printMapping(); //DEBUG
|
|
|
|
void printTargetSources(); //DEBUG
|
|
|
|
|
2017-06-07 06:52:54 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
#endif //ENTITY_CONVERTER_HPP
|
|
|
|
|