DMX/Binary: Difference between revisions

From Valve Developer Community
< DMX
Jump to navigation Jump to search
(Document AT_VOID/binary value format)
(Updated information on how the binary format is store and to inform on different encoding versions.)
 
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";
 
int nStrings; // number of strings in StringDict
// String table exists for version 2 and above.
char* StringDict[]; // null-terminated, tightly packed
int stringCount; // The number of strings in the string table.
string[] stringTable; // List of null terminated strings.


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


DmeHeader ElementIndex; // the root element
// For each element, it reads all the attributes attached to it.
DmeBody ElementBodies[]; // in the same order as the nested index
// 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 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.
DmeHeader SubElems[]; // skip elements which already have an index entry
char[16] id; // The UUID of the element.
};


class DmeBody
DmAttribute[] attributes; // The attributes the element has.
{
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.
; Binary (AT_VOID)
; Binary (AT_VOID)
: Binary values are stored with an <code>int</code> count, then that many bytes immediately after.
: Binary values are stored with an <code>int</code> count, then that many bytes immediately after.
; Elements
; Object Id
: Element values are represented by an <code>int</code>. The value is the element's position in the element index.
: A UUID object stored if the version is lower than 3.
:* <code>-1</code> means "no value"
:* <code>-2</code> followed by an ASCII GUID (yes, ASCII!) means a "stub element" which exists but was excluded from the DMX
; Arrays
: Arrays start with an <code>int</code> defining the number of items they contained and are tightly-packed.
; 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 objects with four <code>int</code>s 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
: A 4 by 4 float matrix.
; Arrays
: Arrays start with an <code>int</code> defining the number of items they contained and are tightly-packed.


== Previous versions ==
== Previous versions ==
Line 75: Line 77:
| 2 || String dictionary added for element types and attribute names; length and indices are <code>short</code>.
| 2 || String dictionary added for element types and attribute names; length and indices are <code>short</code>.
|-
|-
| 3 || <code>Time</code> attribute type added.
| 3 || <code>Object Id</code> attribute type replaced with <code>Time</code> attribute type.
|-
|-
| 4 ||
| 4 ||
* String dictionary length is now <code>int</code>, even though indices are still <code>short</code>.
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.
String values (non-array) and element names moved to string dictionary.
|-
|-
| 5 ||
| 5 ||
* String dictionary indices are now <code>int</code> too.
String dictionary indices are now <code>int</code> too.
* Stub elements added.
|}
|}


[[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.