mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 00:24:40 +00:00
binary parsing working
finally....
This commit is contained in:
parent
140e9dbfc6
commit
b074b9fc1f
4 changed files with 124 additions and 62 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
bool TamlBinaryParser::accept(const char* pFilename, TamlVisitor& visitor)
|
bool TamlBinaryParser::accept(const char* pFilename, TamlVisitor& visitor)
|
||||||
{
|
{
|
||||||
|
isRoot = true;
|
||||||
PROFILE_SCOPE(TamlBinaryParser_Accept);
|
PROFILE_SCOPE(TamlBinaryParser_Accept);
|
||||||
AssertFatal(pFilename != NULL, "TamlBinaryParser::accept - NULL filename.");
|
AssertFatal(pFilename != NULL, "TamlBinaryParser::accept - NULL filename.");
|
||||||
|
|
||||||
|
|
@ -28,6 +29,8 @@ bool TamlBinaryParser::accept(const char* pFilename, TamlVisitor& visitor)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setParsingFilename(pFilename);
|
||||||
|
|
||||||
U32 versionId;
|
U32 versionId;
|
||||||
stream.read(&versionId);
|
stream.read(&versionId);
|
||||||
|
|
||||||
|
|
@ -47,6 +50,9 @@ bool TamlBinaryParser::accept(const char* pFilename, TamlVisitor& visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.close();
|
stream.close();
|
||||||
|
|
||||||
|
setParsingFilename(StringTable->EmptyString());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,108 +62,151 @@ bool TamlBinaryParser::parseElement(Stream& stream, TamlVisitor& visitor, const
|
||||||
{
|
{
|
||||||
PROFILE_SCOPE(TamlBinaryParser_ParseElement);
|
PROFILE_SCOPE(TamlBinaryParser_ParseElement);
|
||||||
|
|
||||||
// Read the type and name.
|
// --- Read element header ---
|
||||||
StringTableEntry typeName = stream.readSTString();
|
StringTableEntry pElementName = stream.readSTString();
|
||||||
StringTableEntry objectName = stream.readSTString();
|
StringTableEntry pObjectName = stream.readSTString();
|
||||||
|
|
||||||
// Read references.
|
// Read references.
|
||||||
U32 refId, refToId;
|
U32 refId, refToId;
|
||||||
stream.read(&refId);
|
stream.read(&refId);
|
||||||
stream.read(&refToId);
|
stream.read(&refToId);
|
||||||
|
|
||||||
|
// If this is a reference to another object, skip it.
|
||||||
|
if (refToId != 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
// Create a property visitor state.
|
// Create a property visitor state.
|
||||||
TamlVisitor::PropertyState propertyState;
|
TamlVisitor::PropertyState propertyState;
|
||||||
propertyState.setObjectName(typeName, false);
|
|
||||||
|
|
||||||
if (objectName != StringTable->EmptyString())
|
propertyState.setObjectName(pElementName, isRoot);
|
||||||
propertyState.setProperty("Name", objectName);
|
if (pObjectName != StringTable->EmptyString())
|
||||||
|
propertyState.setProperty("Name", pObjectName);
|
||||||
|
|
||||||
if (!visitor.visit(*this, propertyState))
|
if(isRoot)
|
||||||
return false;
|
isRoot = false;
|
||||||
|
|
||||||
// Parse attributes.
|
// --- Attributes ---
|
||||||
U32 attrCount;
|
parseAttributes(stream, visitor, versionId, propertyState);
|
||||||
stream.read(&attrCount);
|
// --- Children ---
|
||||||
|
parseChildren(stream, visitor, versionId);
|
||||||
|
// --- Custom elements ---
|
||||||
|
parseCustomElements(stream, visitor, versionId);
|
||||||
|
|
||||||
char valueBuffer[4096];
|
|
||||||
for (U32 i = 0; i < attrCount; ++i)
|
|
||||||
{
|
|
||||||
StringTableEntry attrName = stream.readSTString();
|
|
||||||
stream.readLongString(sizeof(valueBuffer), valueBuffer);
|
|
||||||
propertyState.setProperty(attrName, valueBuffer);
|
|
||||||
visitor.visit(*this, propertyState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse children.
|
|
||||||
U32 childCount;
|
|
||||||
stream.read(&childCount);
|
|
||||||
for (U32 c = 0; c < childCount; ++c)
|
|
||||||
{
|
|
||||||
if (!parseElement(stream, visitor, versionId))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse custom nodes.
|
|
||||||
U32 customCount;
|
|
||||||
stream.read(&customCount);
|
|
||||||
for (U32 cn = 0; cn < customCount; ++cn)
|
|
||||||
{
|
|
||||||
StringTableEntry customNodeName = stream.readSTString();
|
|
||||||
propertyState.setProperty("CustomNode", customNodeName);
|
|
||||||
visitor.visit(*this, propertyState);
|
|
||||||
parseCustomNode(stream, visitor, versionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TamlBinaryParser::parseAttributes(Stream& stream, TamlVisitor& visitor, const U32 versionId, TamlVisitor::PropertyState& state)
|
||||||
|
{
|
||||||
|
PROFILE_SCOPE(TamlBinaryParser_ParseAttributes);
|
||||||
|
|
||||||
|
U32 attributeCount;
|
||||||
|
stream.read(&attributeCount);
|
||||||
|
if (attributeCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char valueBuffer[4096];
|
||||||
|
for (U32 i = 0; i < attributeCount; ++i)
|
||||||
|
{
|
||||||
|
StringTableEntry attrName = stream.readSTString();
|
||||||
|
stream.readLongString(4096, valueBuffer);
|
||||||
|
state.setProperty(attrName, valueBuffer);
|
||||||
|
const bool visitStatus = visitor.visit(*this, state);
|
||||||
|
if (!visitStatus)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool TamlBinaryParser::parseCustomNode(Stream& stream, TamlVisitor& visitor, const U32 versionId)
|
void TamlBinaryParser::parseChildren(Stream& stream, TamlVisitor& visitor, const U32 versionId)
|
||||||
|
{
|
||||||
|
PROFILE_SCOPE(TamlBinaryParser_ParseChildren);
|
||||||
|
|
||||||
|
U32 childCount = 0;
|
||||||
|
stream.read(&childCount);
|
||||||
|
if (childCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (U32 i = 0; i < childCount; ++i)
|
||||||
|
{
|
||||||
|
parseElement(stream, visitor, versionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TamlBinaryParser::parseCustomElements(Stream& stream, TamlVisitor& visitor, const U32 versionId)
|
||||||
|
{
|
||||||
|
PROFILE_SCOPE(TamlBinaryParser_ParseCustomElements);
|
||||||
|
|
||||||
|
U32 customNodeCount = 0;
|
||||||
|
stream.read(&customNodeCount);
|
||||||
|
if (customNodeCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TamlVisitor::PropertyState state;
|
||||||
|
|
||||||
|
for (U32 nodeIndex = 0; nodeIndex < customNodeCount; ++nodeIndex)
|
||||||
|
{
|
||||||
|
StringTableEntry nodeName = stream.readSTString();
|
||||||
|
state.setObjectName(nodeName, false);
|
||||||
|
|
||||||
|
U32 nodeChildrenCount = 0;
|
||||||
|
stream.read(&nodeChildrenCount);
|
||||||
|
if (nodeChildrenCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(U32 nodeChild = 0; nodeChild < nodeChildrenCount; ++nodeChild)
|
||||||
|
parseCustomNode(stream, visitor, versionId, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool TamlBinaryParser::parseCustomNode(Stream& stream, TamlVisitor& visitor, const U32 versionId, TamlVisitor::PropertyState& state)
|
||||||
{
|
{
|
||||||
PROFILE_SCOPE(TamlBinaryParser_ParseCustomNode);
|
PROFILE_SCOPE(TamlBinaryParser_ParseCustomNode);
|
||||||
|
|
||||||
bool isProxyObject;
|
bool isProxyObject;
|
||||||
stream.read(&isProxyObject);
|
stream.read(&isProxyObject);
|
||||||
|
|
||||||
if (isProxyObject)
|
if (isProxyObject)
|
||||||
{
|
{
|
||||||
// Parse nested proxy element.
|
// Parse nested proxy element.
|
||||||
return parseElement(stream, visitor, versionId);
|
return parseElement(stream, visitor, versionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read custom node name and text.
|
|
||||||
StringTableEntry nodeName = stream.readSTString();
|
StringTableEntry nodeName = stream.readSTString();
|
||||||
|
|
||||||
char textBuffer[1024];
|
char nodeValue[MAX_TAML_NODE_FIELDVALUE_LENGTH];
|
||||||
stream.readLongString(sizeof(textBuffer), textBuffer);
|
|
||||||
|
|
||||||
// Create visitor state for the node.
|
stream.readLongString(MAX_TAML_NODE_FIELDVALUE_LENGTH, nodeValue);
|
||||||
TamlVisitor::PropertyState nodeState;
|
|
||||||
nodeState.setObjectName(nodeName, false);
|
|
||||||
nodeState.setProperty("Text", textBuffer);
|
|
||||||
visitor.visit(*this, nodeState);
|
|
||||||
|
|
||||||
// Parse child nodes.
|
|
||||||
U32 childCount;
|
U32 childCount;
|
||||||
stream.read(&childCount);
|
stream.read(&childCount);
|
||||||
for (U32 i = 0; i < childCount; ++i)
|
for (U32 i = 0; i < childCount; ++i)
|
||||||
{
|
{
|
||||||
if (!parseCustomNode(stream, visitor, versionId))
|
if (!parseCustomNode(stream, visitor, versionId, state))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse fields.
|
|
||||||
U32 fieldCount;
|
U32 fieldCount;
|
||||||
stream.read(&fieldCount);
|
stream.read(&fieldCount);
|
||||||
|
|
||||||
char valueBuffer[1024];
|
if (fieldCount > 0)
|
||||||
for (U32 f = 0; f < fieldCount; ++f)
|
|
||||||
{
|
{
|
||||||
StringTableEntry fieldName = stream.readSTString();
|
char valueBuffer[MAX_TAML_NODE_FIELDVALUE_LENGTH];
|
||||||
stream.readLongString(sizeof(valueBuffer), valueBuffer);
|
for (U32 f = 0; f < fieldCount; ++f)
|
||||||
nodeState.setProperty(fieldName, valueBuffer);
|
{
|
||||||
visitor.visit(*this, nodeState);
|
StringTableEntry fieldName = stream.readSTString();
|
||||||
|
stream.readLongString(MAX_TAML_NODE_FIELDVALUE_LENGTH, valueBuffer);
|
||||||
|
state.setProperty(fieldName, valueBuffer);
|
||||||
|
const bool visitStatus = visitor.visit(*this, state);
|
||||||
|
if (!visitStatus)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parseElement(Stream& stream, TamlVisitor& visitor, const U32 versionId);
|
bool parseElement(Stream& stream, TamlVisitor& visitor, const U32 versionId);
|
||||||
bool parseCustomNode(Stream& stream, TamlVisitor& visitor, const U32 versionId);
|
void parseAttributes(Stream& stream, TamlVisitor& visitor, const U32 versionId, TamlVisitor::PropertyState& state);
|
||||||
|
void parseChildren(Stream& stream, TamlVisitor& visitor, const U32 versionId);
|
||||||
|
void parseCustomElements(Stream& stream, TamlVisitor& visitor, const U32 versionId);
|
||||||
|
bool parseCustomNode(Stream& stream, TamlVisitor& visitor, const U32 versionId, TamlVisitor::PropertyState& state);
|
||||||
|
|
||||||
|
bool isRoot;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !_TAML_BINARYPARSER_H_
|
#endif // !_TAML_BINARYPARSER_H_
|
||||||
|
|
|
||||||
|
|
@ -345,8 +345,14 @@ void TamlBinaryReader::parseCustomElements( Stream& stream, TamlCallbacks* pCall
|
||||||
// Add custom node.
|
// Add custom node.
|
||||||
TamlCustomNode* pCustomNode = customNodes.addNode( nodeName );
|
TamlCustomNode* pCustomNode = customNodes.addNode( nodeName );
|
||||||
|
|
||||||
|
U32 nodeChildrenCount = 0;
|
||||||
|
stream.read(&nodeChildrenCount);
|
||||||
|
if (nodeChildrenCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
// Parse the custom node.
|
// Parse the custom node.
|
||||||
parseCustomNode( stream, pCustomNode, versionId );
|
for (U32 nodeChild = 0; nodeChild < nodeChildrenCount; ++nodeChild)
|
||||||
|
parseCustomNode( stream, pCustomNode, versionId );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we have callbacks?
|
// Do we have callbacks?
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,8 @@ void TamlBinaryWriter::writeCustomElements( Stream& stream, const TamlWriteNode*
|
||||||
// Fetch node children.
|
// Fetch node children.
|
||||||
const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
|
const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
|
||||||
|
|
||||||
|
stream.write((U32)nodeChildren.size());
|
||||||
|
|
||||||
// Iterate children nodes.
|
// Iterate children nodes.
|
||||||
for( TamlCustomNodeVector::const_iterator childNodeItr = nodeChildren.begin(); childNodeItr != nodeChildren.end(); ++childNodeItr )
|
for( TamlCustomNodeVector::const_iterator childNodeItr = nodeChildren.begin(); childNodeItr != nodeChildren.end(); ++childNodeItr )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue