diff options
Diffstat (limited to 'src/map.cpp')
| -rw-r--r-- | src/map.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
| diff --git a/src/map.cpp b/src/map.cpp index ef0d6c3..36baab6 100644 --- a/src/map.cpp +++ b/src/map.cpp | |||
| @@ -11,7 +11,6 @@ static std::map<std::string, Map> maps; | |||
| 11 | 11 | ||
| 12 | Map::Map() | 12 | Map::Map() |
| 13 | { | 13 | { |
| 14 | title = (char*) calloc(1, sizeof(char)); | ||
| 15 | mapdata = (int*) calloc(1, sizeof(int)); | 14 | mapdata = (int*) calloc(1, sizeof(int)); |
| 16 | } | 15 | } |
| 17 | 16 | ||
| @@ -44,14 +43,7 @@ Map::Map(const std::string name) | |||
| 44 | if (!xmlStrcmp(node->name, (const xmlChar*) "name")) | 43 | if (!xmlStrcmp(node->name, (const xmlChar*) "name")) |
| 45 | { | 44 | { |
| 46 | xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); | 45 | xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); |
| 47 | int len = xmlStrlen(key); | 46 | title = (char*) key; |
| 48 | title = (char*) calloc(len + 1, sizeof(char)); | ||
| 49 | |||
| 50 | if (len > 0) | ||
| 51 | { | ||
| 52 | strcpy(title, (char*) key); | ||
| 53 | } | ||
| 54 | |||
| 55 | xmlFree(key); | 47 | xmlFree(key); |
| 56 | } else if (!xmlStrcmp(node->name, (const xmlChar*) "environment")) | 48 | } else if (!xmlStrcmp(node->name, (const xmlChar*) "environment")) |
| 57 | { | 49 | { |
| @@ -91,13 +83,23 @@ Map::Map(const std::string name) | |||
| 91 | } else if (!xmlStrcmp(node->name, (const xmlChar*) "leftmap")) | 83 | } else if (!xmlStrcmp(node->name, (const xmlChar*) "leftmap")) |
| 92 | { | 84 | { |
| 93 | xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); | 85 | xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); |
| 94 | leftMap = &Map::getNamedMap(std::string((char*) key)); | 86 | std::string mapname = (char*) key; |
| 95 | xmlFree(key); | 87 | xmlFree(key); |
| 88 | |||
| 89 | if (mapname.length() > 0) | ||
| 90 | { | ||
| 91 | leftMap = &Map::getNamedMap(mapname); | ||
| 92 | } | ||
| 96 | } else if (!xmlStrcmp(node->name, (const xmlChar*) "rightmap")) | 93 | } else if (!xmlStrcmp(node->name, (const xmlChar*) "rightmap")) |
| 97 | { | 94 | { |
| 98 | xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); | 95 | xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); |
| 99 | rightMap = &Map::getNamedMap(std::string((char*) key)); | 96 | std::string mapname = (char*) key; |
| 100 | xmlFree(key); | 97 | xmlFree(key); |
| 98 | |||
| 99 | if (mapname.length() > 0) | ||
| 100 | { | ||
| 101 | rightMap = &Map::getNamedMap(mapname); | ||
| 102 | } | ||
| 101 | } | 103 | } |
| 102 | } | 104 | } |
| 103 | 105 | ||
| @@ -109,9 +111,7 @@ Map::Map(const Map& map) | |||
| 109 | mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); | 111 | mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); |
| 110 | memcpy(mapdata, map.mapdata, MAP_WIDTH*MAP_HEIGHT*sizeof(int)); | 112 | memcpy(mapdata, map.mapdata, MAP_WIDTH*MAP_HEIGHT*sizeof(int)); |
| 111 | 113 | ||
| 112 | title = (char*) malloc((MAP_WIDTH+1)*sizeof(char)); | 114 | title = map.title; |
| 113 | strncpy(title, map.title, MAP_WIDTH+1); | ||
| 114 | |||
| 115 | leftMap = map.leftMap; | 115 | leftMap = map.leftMap; |
| 116 | rightMap = map.rightMap; | 116 | rightMap = map.rightMap; |
| 117 | 117 | ||
| @@ -128,7 +128,6 @@ Map::Map(Map&& map) : Map() | |||
| 128 | Map::~Map() | 128 | Map::~Map() |
| 129 | { | 129 | { |
| 130 | free(mapdata); | 130 | free(mapdata); |
| 131 | free(title); | ||
| 132 | } | 131 | } |
| 133 | 132 | ||
| 134 | Map& Map::operator= (Map map) | 133 | Map& Map::operator= (Map map) |
| @@ -153,7 +152,7 @@ const int* Map::getMapdata() const | |||
| 153 | return mapdata; | 152 | return mapdata; |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | const char* Map::getTitle() const | 155 | std::string Map::getTitle() const |
| 157 | { | 156 | { |
| 158 | return title; | 157 | return title; |
| 159 | } | 158 | } |
