DMX/Binary: Difference between revisions

From Valve Developer Community
< DMX
Jump to navigation Jump to search
(Updated information on how the binary format is store and to inform on different encoding versions.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Version 5 ==
<source lang=cpp>
<source lang=cpp>
class BinaryDMX_v5
class Binary
{
{
char* header = "<!-- dmx encoding binary 5 format %s %i -->\n";
string header = "<!-- dmx encoding binary %i format %s %i -->\n";
// String table exists for version 2 and above.
int stringCount; // The number of strings in the string table.
string[] stringTable; // List of null terminated strings.


int nStrings; // number of strings in StringDict
int elementCount; // The number of elements in the data model.
char* StringDict[]; // null-terminated, tightly packed
DmElement[] elements; // List of elements in the data model.


int nElements; // number of elements in the entire data model
// For each element, it reads all the attributes attached to it.
 
// It begins by reading an int value to determine the count of attributes the element possesses.
DmeHeader ElementIndex; // the root element
// Subsequently, it reads all the DmAttribute instances based on the count and pushes each attribute to the element's attributes list.
DmeBody ElementBodies[]; // in the same order as the nested index
};
};


class DmeHeader
class DmElement
{
{
int Type; // string dictionary index
// This is an int value index to the string table if version is greater than 1 else it's a null terminated string.
int Name; // string dictionary index
string type; // The type of the element.
char GUID[16]; // little-endian
// This is an int value index to the string table if version is greater than 3 else it's a null terminated string.
string name; // The name of the element.
char[16] id; // The UUID of the element.


DmeHeader SubElems[]; // skip elements which already have an index entry
DmAttribute[] attributes; // The attributes the element has.
};
 
class DmeBody
{
int nAttributes;
DmeAttribute Attributes[];
};
};


class DmAttribute
class DmAttribute
{
{
int Name; // string dictionary index
// This is an int value index to the string table if version is greater than 1 else it's a null terminated string.
char AttributeType; // see below
string name; // The name of the attribute.
void* Value; // see below
char type; // The type of attribute, see below.
void* value; // see below
};
};
</source>
</source>
Line 42: Line 40:
Check <code>DmAttributeType_t</code> in <code>public/datamodel/dmattributetypes.h</code> to get the index of each attribute type.
Check <code>DmAttributeType_t</code> in <code>public/datamodel/dmattributetypes.h</code> to get the index of each attribute type.


{{note|<code>DmAttributeType_t</code> changes over time, so make sure that you're looking at the right version! Use [[Alien Swarm]] for binary v5.}}
{{note|<code>DmAttributeType_t</code> is different for each engine version, so make sure that you're looking at the right version!}}


=== Attribute Values ===
=== Attribute Values ===
Line 48: Line 46:
Most values are stored in their native binary format (check [[tier0]] for the layout of the fancier types). Exceptions are:
Most values are stored in their native binary format (check [[tier0]] for the layout of the fancier types). Exceptions are:


; Elements
: Element values are represented by an <code>int</code>. The value is the element's position in the element index.
:* <code>-1</code> means "no value"
:* <code>-2</code> followed by an ASCII UUID (yes, ASCII!) means a "external element" which exists but was excluded from the DMX
; Strings
; Strings
: String values are stored as an <code>int</code> index in the string dictionary. String ''array'' values are stored inline as a null-terminated <code>char</code> array.
: String values are stored as an <code>int</code> index in the string dictionary when version 4 or higher. String ''array'' values are stored inline as a null-terminated <code>char</code> array.
; Elements
; Binary (AT_VOID)
: Element values are represented by an <code>int</code>. The value is the element's position in the element index. -1 means "no value".
: Binary values are stored with an <code>int</code> count, then that many bytes immediately after.
; Arrays
; Object Id
: Arrays start with an <code>int</code> defining the number of items they contained and are tightly-packed.
: A UUID object stored if the version is lower than 3.
; Time
; Time
: Time values are <code>float</code> in memory but are stored in binary DMX as <code>(int)(this*10000)</code>.
: Time values are <code>float</code> in memory but are stored in binary DMX as <code>(int)(this*10000)</code>.
; Color
; Color
: Color values are <code>int</code> in memory but stored in binary DMX as <code>char[4]</code>.
: Color values are objects with four <code>int</code>s in memory but stored in binary DMX as <code>char[4]</code>.
 
; Matrix
== Version 2 ==
: A 4 by 4 float matrix.
 
; Arrays
As 5, except:
: Arrays start with an <code>int</code> defining the number of items they contained and are tightly-packed.
 
* String dictionary length and indices are <code>short</code>
* String array values are stored in the dictionary too
* Element names are inline
 
== Version 1 ==
 
As 5, except:
 
* There is no string dictionary; everything is inline
 
== Binary_v2 ==
 
This is a very early version of binary DMX which can be found in some of the SDK's sample TF2 animations (those exported in April 2007). It is ''not'' the same as the "real" version 2 (above).


Known differences from 5 are:
== Previous versions ==


* Header is <code><nowiki><!-- DMXVersion binary_v2 --></nowiki></code>
{| class="standard-table"
* There is no string dictionary; everything is inline
|-
! Version !! Changes
|-
| Binary_v2 || Earliest known version. Header is <code><nowiki><!-- DMXVersion binary_v2 -->\n</nowiki></code>.
|-
| 1 || Standard DMX header introduced: <code><nowiki><!-- dmx encoding binary %i format %s %i -->\n</nowiki></code>.
|-
| 2 || String dictionary added for element types and attribute names; length and indices are <code>short</code>.
|-
| 3 || <code>Object Id</code> attribute type replaced with <code>Time</code> attribute type.
|-
| 4 ||
String dictionary length is now <code>int</code>, even though indices are still <code>short</code>.
String values (non-array) and element names moved to string dictionary.
|-
| 5 ||
String dictionary indices are now <code>int</code> too.
|}


[[Category:File formats]]
[[Category:File formats]]

Latest revision as of 11:50, 14 May 2024

class Binary
{
	string header = "<!-- dmx encoding binary %i format %s %i -->\n";
	
	// String table exists for version 2 and above.
	int			stringCount;	// The number of strings in the string table.
	string[]	stringTable;	// List of null terminated strings.

	int			elementCount;	// The number of elements in the data model.
	DmElement[]	elements;		// List of elements in the data model.

	// For each element, it reads all the attributes attached to it.
	// It begins by reading an int value to determine the count of attributes the element possesses.
	// Subsequently, it reads all the DmAttribute instances based on the count and pushes each attribute to the element's attributes list.
};

class DmElement
{
	// This is an int value index to the string table if version is greater than 1 else it's a null terminated string.
	string		type;	// The type of the element.
	// This is an int value index to the string table if version is greater than 3 else it's a null terminated string.
	string		name;	// The name of the element.
	char[16]	id;		// The UUID of the element.

	DmAttribute[]	attributes;	// The attributes the element has.
};

class DmAttribute
{
	// This is an int value index to the string table if version is greater than 1 else it's a null terminated string.
	string	name;	// The name of the attribute.
	char	type;	// The type of attribute, see below.
	void*	value;	// see below
};

Attribute Types

Check DmAttributeType_t in public/datamodel/dmattributetypes.h to get the index of each attribute type.

Note.pngNote:DmAttributeType_t is different for each engine version, so make sure that you're looking at the right version!

Attribute Values

Most values are stored in their native binary format (check tier0 for the layout of the fancier types). Exceptions are:

Elements
Element values are represented by an int. The value is the element's position in the element index.
  • -1 means "no value"
  • -2 followed by an ASCII UUID (yes, ASCII!) means a "external element" which exists but was excluded from the DMX
Strings
String values are stored as an int index in the string dictionary when version 4 or higher. String array values are stored inline as a null-terminated char array.
Binary (AT_VOID)
Binary values are stored with an int count, then that many bytes immediately after.
Object Id
A UUID object stored if the version is lower than 3.
Time
Time values are float in memory but are stored in binary DMX as (int)(this*10000).
Color
Color values are objects with four ints in memory but stored in binary DMX as char[4].
Matrix
A 4 by 4 float matrix.
Arrays
Arrays start with an int defining the number of items they contained and are tightly-packed.

Previous versions

Version Changes
Binary_v2 Earliest known version. Header is <!-- DMXVersion binary_v2 -->\n.
1 Standard DMX header introduced: <!-- dmx encoding binary %i format %s %i -->\n.
2 String dictionary added for element types and attribute names; length and indices are short.
3 Object Id attribute type replaced with Time attribute type.
4

String dictionary length is now int, even though indices are still short. String values (non-array) and element names moved to string dictionary.

5

String dictionary indices are now int too.