From 13f946689e28e99ac71172925f63f4320798a0ee Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 5 Mar 2018 16:07:07 -0500 Subject: Added entity indexing Changed the world format so that map objects are indexed (per map). The next available map object index is cached for each map. --- tools/mapedit/src/world.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tools/mapedit/src/world.cpp') diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index 79f5a58..9983731 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp @@ -94,6 +94,11 @@ World::World(std::string filename) map->setTitle((char*) titleKey, false); xmlFree(titleKey); + xmlChar* noiKey = xmlGetProp(node, (xmlChar*) "nextObject"); + if (noiKey == 0) throw MapLoadException("map missing nextObject attribute"); + map->setNextObjectIndex(atoi((char*) noiKey)); + xmlFree(noiKey); + for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next) { if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) @@ -125,7 +130,12 @@ World::World(std::string filename) int ypos = atoi((char*) yKey); xmlFree(yKey); - auto data = std::make_shared(obj, xpos, ypos); + xmlChar* indexKey = xmlGetProp(mapNode, (const xmlChar*) "index"); + if (indexKey == 0) throw MapLoadException("entity missing index attribute"); + int objIndex = atoi((char*) indexKey); + xmlFree(indexKey); + + auto data = std::make_shared(obj, xpos, ypos, objIndex); map->addObject(data, false); @@ -312,6 +322,10 @@ void World::save(std::string name, wxTreeCtrl* mapTree) // title= rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "title", (xmlChar*) map.getTitle().c_str()); if (rc < 0) throw MapWriteException(name); + + // nextObject= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "nextObject", "%zu", map.getNextObjectIndex()); + if (rc < 0) throw MapWriteException(name); // getPosition().second); if (rc < 0) throw MapWriteException(name); + // index= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "index", "%zu", object->getIndex()); + if (rc < 0) throw MapWriteException(name); + for (auto item : object->getItems()) { //