Configfile format

From VDrift
Revision as of 06:10, 20 April 2007 by Venzon (talk | contribs)
Jump to: navigation, search

Many of VDrift's text-based data and settings files are written in a format native to the game. In the source code it is the CONFIGFILE class.

Format

  • This format resembles the ini-style format somewhat.
  • It is not heirarchical, it is categorical.
  • Comments begin with # and can occur at any point in a line.
  • Categories are defined by a heading line with an identifier. The identifier is commonly placed between [ and ] brackets for readability, but this is not actually required.
  • Data items are defined by a line with the form name = value
  • Whitespace before or after an identifier, name, or value is ignored, but line breaks are important.
  • Spaces are allowed in item or category identifiers and will be preserved.
  • Data values can be almost anything.
  • Case is important for category and item identifiers, as well as string values, but nothing else.
  • UTF-8 is not yet supported.

Parsing

The files are parsed one line at a time. Any characters after a # character are discarded (this is used to allow comments in the file). Characters [ and ] are stripped from the line. If a line has no = character, then the line is interpreted as a heading. Otherwise, the line is interpreted as a setting, with the characters to the left of the = character interpreted as the name of the setting, and the characters to the right of the = character interpreted as the value of the setting. Whitespace before and after the heading, name, or setting is stripped.

Categories and data items

In this format, categories are defined by a heading of the form [ category ] where category is the name of the category. Items in the category include all the items from the category heading to the next category heading, or the end of the file.

Items before the first category heading have no category. They are referenced by their names preceded by a . character.

Example

A file in this format might look like this.

name = Example

[ first ]
stuff = 567
blah = hello
radius = 0.555

[ 2nd ]
beans = on
now = 1
position = 5,6,7

In the file, there are two categories, each with three data items. These items would be referenced by the following identifier strings, in the order they occur:

  • .name
  • first.stuff
  • first.blah
  • first.radius
  • 2nd.beans
  • 2nd.now
  • 2nd.position

How data items' values are typed

The format employs a somewhat loose typing scheme. That is, data items do not need to have their types explicitly defined. In the game code, an item can be queried as any type, and depending on the value of the item, certain values can be interpreted differently when requested as different types. Values can be requested as strings, integers, floating point numbers, a vector of 3 floats, or boolean types. For instance, the item 2nd.now from the example above would have the value 1 if interpreted as an integer. If interpreted as a boolean, its value would be true; as a string, its value would be "1"; as a floating-point number, its value would be 1.0.

The following values will equal true when interpreted as boolean values:

  • true
  • yes
  • on
  • 1

The obvious opposite values are equal to false.

To have a value interpreted as a vector of 3 floats simply add commas between the three floats:

  • somevector = 1.0, 2.1, 15