From 3ca85cbe872fedd4291912de7ad37a08e5264332 Mon Sep 17 00:00:00 2001 From: BeniS Date: Sat, 2 Mar 2013 18:33:14 +1300 Subject: [PATCH] Removed Position dependencies inside the framework --- src/client/creatures.cpp | 6 +++++- src/client/houses.cpp | 7 ++++++- src/client/item.cpp | 2 +- src/client/mapio.cpp | 30 ++++++++++++++++++++++++------ src/framework/core/binarytree.cpp | 17 ++++------------- src/framework/core/binarytree.h | 3 +-- src/framework/core/filestream.h | 2 +- src/framework/xml/tinyxml.h | 9 --------- 8 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/client/creatures.cpp b/src/client/creatures.cpp index e925002e..0a606eac 100644 --- a/src/client/creatures.cpp +++ b/src/client/creatures.cpp @@ -49,7 +49,11 @@ void CreatureManager::terminate() void Spawn::load(TiXmlElement* node) { - Position centerPos = node->readPos("center"); + Position centerPos; + centerPos.x = node->readType("centerx"); + centerPos.y = node->readType("centery"); + centerPos.z = node->readType("centerz"); + setCenterPos(centerPos); setRadius(node->readType("radius")); diff --git a/src/client/houses.cpp b/src/client/houses.cpp index 38c6be80..93ddc91e 100644 --- a/src/client/houses.cpp +++ b/src/client/houses.cpp @@ -65,7 +65,12 @@ void House::load(const TiXmlElement *elem) setSize(elem->readType("size")); setTownId(elem->readType("townid")); m_isGuildHall = elem->readType("guildhall"); - setEntry(elem->readPos("entry")); + + Position entryPos; + entryPos.x = elem->readType("entryx"); + entryPos.y = elem->readType("entryy"); + entryPos.z = elem->readType("entryz"); + setEntry(entryPos); } void House::save(TiXmlElement*& elem) diff --git a/src/client/item.cpp b/src/client/item.cpp index a5438157..6570fc5a 100644 --- a/src/client/item.cpp +++ b/src/client/item.cpp @@ -179,7 +179,7 @@ void Item::serializeItem(const OutputBinaryTreePtr& out) Position dest = m_attribs.get(ATTR_TELE_DEST); if(dest.isValid()) { out->addU8(ATTR_TELE_DEST); - out->addPos(dest); + out->addPos(dest.x, dest.y, dest.z); } if(isDepot()) { diff --git a/src/client/mapio.cpp b/src/client/mapio.cpp index ee35ecbf..95df337c 100644 --- a/src/client/mapio.cpp +++ b/src/client/mapio.cpp @@ -94,7 +94,11 @@ void Map::loadOtbm(const std::string& fileName, const UIWidgetPtr& pbar) for(const BinaryTreePtr& nodeMapData : node->getChildren()) { uint8 mapDataType = nodeMapData->getU8(); if(mapDataType == OTBM_TILE_AREA) { - Position basePos = nodeMapData->getPosition(); + + Position basePos; + basePos.x = nodeMapData->getU16(); + basePos.y = nodeMapData->getU16(); + basePos.z = nodeMapData->getU8(); for(const BinaryTreePtr &nodeTile : nodeMapData->getChildren()) { uint8 type = nodeTile->getU8(); @@ -187,7 +191,12 @@ void Map::loadOtbm(const std::string& fileName, const UIWidgetPtr& pbar) uint32 townId = nodeTown->getU32(); std::string townName = nodeTown->getString(); - Position townCoords = nodeTown->getPosition(); + + Position townCoords; + townCoords.x = nodeTown->getU16(); + townCoords.y = nodeTown->getU16(); + townCoords.z = nodeTown->getU8(); + if(!(town = g_towns.getTown(townId))) { town = TownPtr(new Town(townId, townName, townCoords)); g_towns.addTown(town); @@ -199,7 +208,12 @@ void Map::loadOtbm(const std::string& fileName, const UIWidgetPtr& pbar) stdext::throw_exception("invalid waypoint node."); std::string name = nodeWaypoint->getString(); - Position waypointPos = nodeWaypoint->getPosition(); + + Position waypointPos; + waypointPos.x = nodeWaypoint->getU16(); + waypointPos.y = nodeWaypoint->getU16(); + waypointPos.z = nodeWaypoint->getU8(); + if(waypointPos.isValid() && !name.empty() && m_waypoints.find(waypointPos) == m_waypoints.end()) m_waypoints.insert(std::make_pair(waypointPos, name)); } @@ -312,7 +326,7 @@ void Map::saveOtbm(const std::string& fileName, const UIWidgetPtr&/* pbar*/) px = pos.x & 0xFF00; py = pos.y & 0xFF00; pz = pos.z; - root->addPos(Position(px, py, pz)); + root->addPos(px, py, pz); } root->startNode(tile->isHouseTile() ? OTBM_HOUSETILE : OTBM_TILE); @@ -353,7 +367,9 @@ void Map::saveOtbm(const std::string& fileName, const UIWidgetPtr&/* pbar*/) for(const TownPtr& town : g_towns.getTowns()) { root->addU32(town->getId()); root->addString(town->getName()); - root->addPos(town->getPos()); + + Position townPos = town->getPos(); + root->addPos(townPos.x, townPos.y, townPos.z); } root->endNode(); @@ -361,7 +377,9 @@ void Map::saveOtbm(const std::string& fileName, const UIWidgetPtr&/* pbar*/) root->startNode(OTBM_WAYPOINTS); for(const auto& it : m_waypoints) { root->addString(it.second); - root->addPos(it.first); + + Position pos = it.first; + root->addPos(pos.x, pos.y, pos.z); } root->endNode(); } diff --git a/src/framework/core/binarytree.cpp b/src/framework/core/binarytree.cpp index 2bc78f49..2ed9b719 100644 --- a/src/framework/core/binarytree.cpp +++ b/src/framework/core/binarytree.cpp @@ -165,15 +165,6 @@ std::string BinaryTree::getString(uint16 len) return ret; } -Position BinaryTree::getPosition() -{ - Position ret; - ret.x = getU16(); - ret.y = getU16(); - ret.z = getU8(); - return ret; -} - Point BinaryTree::getPoint() { Point ret; @@ -216,11 +207,11 @@ void OutputBinaryTree::addString(const std::string& v) write((const uint8*)v.c_str(), v.length()); } -void OutputBinaryTree::addPos(const Position& pos) +void OutputBinaryTree::addPos(uint16 x, uint16 y, uint8 z) { - addU16(pos.x); - addU16(pos.y); - addU8(pos.z); + addU16(x); + addU16(y); + addU8(z); } void OutputBinaryTree::addPoint(const Point& point) diff --git a/src/framework/core/binarytree.h b/src/framework/core/binarytree.h index ab360fa5..f2e9c6d6 100644 --- a/src/framework/core/binarytree.h +++ b/src/framework/core/binarytree.h @@ -49,7 +49,6 @@ public: uint32 getU32(); uint64 getU64(); std::string getString(uint16 len = 0); - Position getPosition(); Point getPoint(); BinaryTreeVec getChildren(); @@ -74,7 +73,7 @@ public: void addU16(uint16 v); void addU32(uint32 v); void addString(const std::string& v); - void addPos(const Position& pos); + void addPos(uint16 x, uint16 y, uint8 z); void addPoint(const Point& point); void startNode(uint8 node); diff --git a/src/framework/core/filestream.h b/src/framework/core/filestream.h index 123d4b9d..7d89f549 100644 --- a/src/framework/core/filestream.h +++ b/src/framework/core/filestream.h @@ -65,7 +65,7 @@ public: void addU32(uint32 v); void addU64(uint64 v); void addString(const std::string& v); - void addPos(const Position& pos) { addU16(pos.x); addU16(pos.y); addU8(pos.z); } + void addPos(uint16 x, uint16 y, uint8 z) { addU16(x); addU16(y); addU8(z); } void addPoint(const Point& p) { addU8(p.x); addU8(p.y); } FileStreamPtr asFileStream() { return static_self_cast(); } diff --git a/src/framework/xml/tinyxml.h b/src/framework/xml/tinyxml.h index 3b5155f3..cc12f1f0 100644 --- a/src/framework/xml/tinyxml.h +++ b/src/framework/xml/tinyxml.h @@ -962,15 +962,6 @@ public: return ret; } - Position readPos(const std::string& base = std::string()) const - { - Position ret; - ret.x = readType(base + "x"); - ret.y = readType(base + "y"); - ret.z = readType(base + "z"); - return ret; - } - /** Template form of the attribute query which will try to read the attribute into the specified type. Very easy, very powerful, but be careful to make sure to call this with the correct type.