optimize otb/xml a bit.

m_itemTypes was being resized too much than expected so is allocin
new itemtype each time it was not being found (which is fake).

otb loader is slow, not sure if it's because of the binary reader
or just the file format is stupid
This commit is contained in:
otfallen 2012-10-05 20:31:05 +00:00
parent 526885f70d
commit ced5c035b9
1 changed files with 8 additions and 15 deletions

View File

@ -109,15 +109,15 @@ void ThingTypeManager::loadOtb(const std::string& file)
if(signature != 0) if(signature != 0)
stdext::throw_exception("invalid otb file"); stdext::throw_exception("invalid otb file");
root->getU32(); // flags root->skip(4);
m_otbMajorVersion = root->getU32(); m_otbMajorVersion = root->getU32();
m_otbMinorVersion = root->getU32(); m_otbMinorVersion = root->getU32();
root->getU32(); // build number root->skip(4);
root->skip(128); // description root->skip(128); // description
m_reverseItemTypes.clear(); m_reverseItemTypes.clear();
m_itemTypes.resize(root->getChildren().size(), m_nullItemType); m_itemTypes.resize(root->getChildren().size() + 1, m_nullItemType);
for(const BinaryTreePtr& node : root->getChildren()) { for(const BinaryTreePtr& node : root->getChildren()) {
ItemTypePtr itemType(new ItemType); ItemTypePtr itemType(new ItemType);
@ -185,7 +185,7 @@ void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem)
{ {
uint16 serverId = id; uint16 serverId = id;
ItemTypePtr itemType = nullptr; ItemTypePtr itemType = nullptr;
if(serverId > 20000 && id < 20100) { if(serverId > 20000 && serverId < 20100) {
serverId -= 20000; serverId -= 20000;
itemType = ItemTypePtr(new ItemType); itemType = ItemTypePtr(new ItemType);
@ -193,15 +193,8 @@ void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem)
addItemType(itemType); addItemType(itemType);
} }
if(!itemType) { itemType = getItemType(serverId);
itemType = getItemType(serverId); assert(itemType && "Internal error");
if(itemType == m_nullItemType) {
itemType = ItemTypePtr(new ItemType);
itemType->setServerId(id);
addItemType(itemType);
}
}
itemType->setName(elem->Attribute("name")); itemType->setName(elem->Attribute("name"));
for(TiXmlElement* attrib = elem->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) { for(TiXmlElement* attrib = elem->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) {
std::string key = attrib->Attribute("key"); std::string key = attrib->Attribute("key");
@ -238,8 +231,8 @@ void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem)
void ThingTypeManager::addItemType(const ItemTypePtr& itemType) void ThingTypeManager::addItemType(const ItemTypePtr& itemType)
{ {
uint16 id = itemType->getServerId(); uint16 id = itemType->getServerId();
if(m_itemTypes.size() <= id) if(id > m_itemTypes.size())
m_itemTypes.resize((id * 3) / 2 + 1, m_nullItemType); m_itemTypes.resize(id + 1, m_nullItemType);
m_itemTypes[id] = itemType; m_itemTypes[id] = itemType;
} }