Now otb reader is properly working
This commit is contained in:
parent
e65a8456e9
commit
2c7ae6e521
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
void BinaryTree::unserialize(const FileStreamPtr& fin)
|
void BinaryTree::unserialize(const FileStreamPtr& fin)
|
||||||
{
|
{
|
||||||
m_type = fin->getU32();
|
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
uint8 byte = fin->getU8();
|
uint8 byte = fin->getU8();
|
||||||
switch(byte) {
|
switch(byte) {
|
||||||
|
@ -48,6 +46,11 @@ void BinaryTree::unserialize(const FileStreamPtr& fin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BinaryTree::serialize(const FileStreamPtr& fin)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void BinaryTree::seek(uint pos)
|
void BinaryTree::seek(uint pos)
|
||||||
{
|
{
|
||||||
if(pos > m_buffer.size())
|
if(pos > m_buffer.size())
|
||||||
|
|
|
@ -35,9 +35,10 @@ enum {
|
||||||
class BinaryTree : public std::enable_shared_from_this<BinaryTree>
|
class BinaryTree : public std::enable_shared_from_this<BinaryTree>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BinaryTree(const BinaryTreePtr& parent = nullptr) : m_type(0), m_pos(0), m_parent(parent) { }
|
BinaryTree(const BinaryTreePtr& parent = nullptr) : m_pos(0), m_parent(parent) { }
|
||||||
|
|
||||||
void unserialize(const FileStreamPtr& fin);
|
void unserialize(const FileStreamPtr& fin);
|
||||||
|
void serialize(const FileStreamPtr& fin);
|
||||||
|
|
||||||
void seek(uint pos);
|
void seek(uint pos);
|
||||||
void skip(uint len) { seek(tell() + len); }
|
void skip(uint len) { seek(tell() + len); }
|
||||||
|
@ -52,12 +53,9 @@ public:
|
||||||
|
|
||||||
BinaryTreeVec getChildren() { return m_children; }
|
BinaryTreeVec getChildren() { return m_children; }
|
||||||
BinaryTreePtr getParent() { return m_parent.lock(); }
|
BinaryTreePtr getParent() { return m_parent.lock(); }
|
||||||
uint32 getType() { return m_type; }
|
|
||||||
bool canRead() { return m_pos < m_buffer.size(); }
|
bool canRead() { return m_pos < m_buffer.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setParent(const BinaryTreePtr& parent) { m_parent = parent; }
|
|
||||||
uint m_type;
|
|
||||||
uint m_pos;
|
uint m_pos;
|
||||||
|
|
||||||
BinaryTreeVec m_children;
|
BinaryTreeVec m_children;
|
||||||
|
|
|
@ -39,12 +39,9 @@ void ThingTypeManager::init()
|
||||||
{
|
{
|
||||||
m_nullDatType = ThingTypeDatPtr(new ThingTypeDat);
|
m_nullDatType = ThingTypeDatPtr(new ThingTypeDat);
|
||||||
m_nullOtbType = ThingTypeOtbPtr(new ThingTypeOtb);
|
m_nullOtbType = ThingTypeOtbPtr(new ThingTypeOtb);
|
||||||
m_otbVersion = 0;
|
|
||||||
m_datSignature = 0;
|
m_datSignature = 0;
|
||||||
m_otbVersion = 0;
|
|
||||||
m_otbMinorVersion = 0;
|
m_otbMinorVersion = 0;
|
||||||
m_otbMajorVersion = 0;
|
m_otbMajorVersion = 0;
|
||||||
m_datSignature = 0;
|
|
||||||
m_datLoaded = false;
|
m_datLoaded = false;
|
||||||
m_xmlLoaded = false;
|
m_xmlLoaded = false;
|
||||||
m_otbLoaded = false;
|
m_otbLoaded = false;
|
||||||
|
@ -97,15 +94,17 @@ bool ThingTypeManager::loadOtb(const std::string& file)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
FileStreamPtr fin = g_resources.openFile(file);
|
FileStreamPtr fin = g_resources.openFile(file);
|
||||||
if (!fin)
|
|
||||||
stdext::throw_exception("unable to open file");
|
|
||||||
|
|
||||||
m_otbVersion = fin->getU32();
|
uint signature = fin->getU32();
|
||||||
if (m_otbVersion != 0x00)
|
if(signature != 0)
|
||||||
stdext::throw_exception("invalid file version");
|
stdext::throw_exception("invalid otb file");
|
||||||
|
|
||||||
BinaryTreePtr root = fin->getBinaryTree();
|
BinaryTreePtr root = fin->getBinaryTree();
|
||||||
|
|
||||||
|
signature = root->getU32();
|
||||||
|
if(signature != 0)
|
||||||
|
stdext::throw_exception("invalid otb file");
|
||||||
|
|
||||||
root->getU32(); // flags
|
root->getU32(); // flags
|
||||||
|
|
||||||
m_otbMajorVersion = root->getU32();
|
m_otbMajorVersion = root->getU32();
|
||||||
|
|
|
@ -49,7 +49,6 @@ public:
|
||||||
const ThingTypeOtbPtr& getOtbType(uint16 id);
|
const ThingTypeOtbPtr& getOtbType(uint16 id);
|
||||||
|
|
||||||
uint32 getDatSignature() { return m_datSignature; }
|
uint32 getDatSignature() { return m_datSignature; }
|
||||||
uint32 getOtbVersion() { return m_otbVersion; }
|
|
||||||
uint32 getOtbMajorVersion() { return m_otbMajorVersion; }
|
uint32 getOtbMajorVersion() { return m_otbMajorVersion; }
|
||||||
uint32 getOtbMinorVersion() { return m_otbMinorVersion; }
|
uint32 getOtbMinorVersion() { return m_otbMinorVersion; }
|
||||||
|
|
||||||
|
@ -71,7 +70,6 @@ private:
|
||||||
bool m_xmlLoaded;
|
bool m_xmlLoaded;
|
||||||
bool m_otbLoaded;
|
bool m_otbLoaded;
|
||||||
|
|
||||||
uint32 m_otbVersion;
|
|
||||||
uint32 m_otbMinorVersion;
|
uint32 m_otbMinorVersion;
|
||||||
uint32 m_otbMajorVersion;
|
uint32 m_otbMajorVersion;
|
||||||
uint32 m_datSignature;
|
uint32 m_datSignature;
|
||||||
|
|
|
@ -37,11 +37,9 @@ void ThingTypeOtb::unserialize(const BinaryTreePtr& node)
|
||||||
{
|
{
|
||||||
m_null = false;
|
m_null = false;
|
||||||
|
|
||||||
uint8 zero = node->getU8();
|
|
||||||
assert(zero == 0);
|
|
||||||
m_category = (OtbCategory)node->getU8();
|
m_category = (OtbCategory)node->getU8();
|
||||||
|
|
||||||
node->getU32(); // skip flags
|
node->getU32(); // flags
|
||||||
|
|
||||||
while(node->canRead()) {
|
while(node->canRead()) {
|
||||||
uint8 attr = node->getU8();
|
uint8 attr = node->getU8();
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
#include <framework/luascript/luaobject.h>
|
#include <framework/luascript/luaobject.h>
|
||||||
|
|
||||||
enum OtbCategory {
|
enum OtbCategory {
|
||||||
OtbGround = 0,
|
OtbInvalidCateogry = 0,
|
||||||
|
OtbGround,
|
||||||
OtbContainer,
|
OtbContainer,
|
||||||
OtbWeapon,
|
OtbWeapon,
|
||||||
OtbAmmunition,
|
OtbAmmunition,
|
||||||
|
@ -41,8 +42,7 @@ enum OtbCategory {
|
||||||
OtbSplash,
|
OtbSplash,
|
||||||
OtbFluid,
|
OtbFluid,
|
||||||
OtbDoor,
|
OtbDoor,
|
||||||
OtbLastCategory,
|
OtbLastCategory
|
||||||
OtbInvalidCateogry = OtbLastCategory
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OtbAttrib {
|
enum OtbAttrib {
|
||||||
|
|
Loading…
Reference in New Issue