mirror of
https://github.com/edubart/otclient.git
synced 2025-10-17 13:03:27 +02:00
stop using pairs instead of index loops, please, it's so much slower
This commit is contained in:
@@ -162,3 +162,73 @@ std::string BinaryTree::getString()
|
||||
m_pos += len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
BinaryTreePtr BinaryTree::makeChild(uint8 type)
|
||||
{
|
||||
BinaryTreePtr child(new BinaryTree(m_fin));
|
||||
child->setType(type);
|
||||
children.append(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
void BinaryTree::setType(uint8 type)
|
||||
{
|
||||
writeU8(0xFE);
|
||||
writeU8(type);
|
||||
}
|
||||
|
||||
void BinaryTree::writeU8(uint8 u8)
|
||||
{
|
||||
m_buffer.add(u8);
|
||||
}
|
||||
|
||||
void BinaryTree::writeU16(uint16 u16)
|
||||
{
|
||||
stdext::writeLE16(m_buffer.data(), u16);
|
||||
}
|
||||
|
||||
void BinaryTree::writeU32(uint32 u32)
|
||||
{
|
||||
stdext::writeLE32(m_buffer.data(), u32);
|
||||
}
|
||||
|
||||
void BinaryTree::writeString(const std::string& s)
|
||||
{
|
||||
size_t len = s.length();
|
||||
writeU16(len);
|
||||
m_buffer.grow(m_pos + len);
|
||||
memcpy(&m_buffer[m_pos], s.c_str(), len);
|
||||
m_pos += len;
|
||||
}
|
||||
|
||||
void BinaryTree::writePos(const Position& p)
|
||||
{
|
||||
if(!p.isValid())
|
||||
stdext::throw_exception("invalid position passed to BinaryTree::writePos");
|
||||
|
||||
writeU16(p.x);
|
||||
writeU16(p.y);
|
||||
writeU8(p.z);
|
||||
}
|
||||
|
||||
void BinaryTree::writePoint(const Point& p)
|
||||
{
|
||||
if(p.isNull())
|
||||
stdext::throw_exception("invalid point passed to BinaryTree::writePoint");
|
||||
|
||||
writeU8(p.x);
|
||||
writeU8(p.y);
|
||||
}
|
||||
|
||||
void BinaryTree::writeToFile()
|
||||
{
|
||||
if(!m_fin)
|
||||
stdext::throw_exception("attempt to write binary node to closed file");
|
||||
|
||||
/// first write self data
|
||||
m_fin->write(&m_buffer[0], m_buffer.size());
|
||||
|
||||
/// write children data
|
||||
for(const BinaryTreePtr& child : m_children)
|
||||
child->writeToFile();
|
||||
}
|
||||
|
@@ -52,6 +52,16 @@ public:
|
||||
Position getPosition() { return Position(getU16(), getU16(), getU8()); }
|
||||
Point getPoint() { return Point(getU8(), getU8()); }
|
||||
|
||||
void setType(uint8 type);
|
||||
void writeU8(uint8 u8);
|
||||
void writeU16(uint16 u16);
|
||||
void writeU32(uint32 u32);
|
||||
void writeString(const std::string& s);
|
||||
void writePos(const Position& p);
|
||||
void writePoint(const Point& p);
|
||||
BinaryTreePtr makeChild(uint8 type);
|
||||
void writeToFile();
|
||||
|
||||
BinaryTreeVec getChildren();
|
||||
bool canRead() { unserialize(); return m_pos < m_buffer.size(); }
|
||||
|
||||
|
@@ -256,6 +256,13 @@ BinaryTreePtr FileStream::getBinaryTree()
|
||||
return BinaryTreePtr(new BinaryTree(asFileStream()));
|
||||
}
|
||||
|
||||
BinaryTreePtr FileStream::makeTree()
|
||||
{
|
||||
BinaryTreePtr root(new BinaryTree(asFileStream()));
|
||||
root->setType(0);
|
||||
return root;
|
||||
}
|
||||
|
||||
void FileStream::addU8(uint8 v)
|
||||
{
|
||||
if(!m_caching) {
|
||||
|
@@ -59,8 +59,7 @@ public:
|
||||
void addU32(uint32 v);
|
||||
void addU64(uint64 v);
|
||||
void addString(const std::string& v);
|
||||
void startNode(uint8 nodeType) { addU8(0xFE); addU8(nodeType); }
|
||||
void endNode() { addU8(0xFF); }
|
||||
BinaryTreePtr makeTree();
|
||||
|
||||
FileStreamPtr asFileStream() { return std::static_pointer_cast<FileStream>(shared_from_this()); }
|
||||
|
||||
|
Reference in New Issue
Block a user