Archive for September, 2008

Unnamed data language

Sunday, September 28th, 2008

I’ve never really been satisified with any existing data languages (see my last post).  They never do all the things I want or are too general, complicated or cumbersome to use.  So, I decided to come up with my own language.  It is a middle ground between Dungeon Siege skrit and id’s decl language.  The language is basically a list of sections and keyvals (like decls) and schema definitions (like skrit) to allow type checking and data driven editors.

The grammar is pretty simple:

Section         ::= "[" <name> <name> "] "{" <SectionContents> "}"
SectionContents ::= <SectionContent> | <SectionContent> <SectionContents>
SectionContent  ::= <KeyVal> | <Section>
KeyVal          ::= <name> <Values> <EOL>
Values          ::= <Value> | <Value> <Values>
Value           ::= <string> | <name>

Put simply, each definition is a section which contains a list of keyvals or other sections.  Keyvals are allowed to have an arbitrary number of values.  The key and section names are not required to be unique.

Here’s a simple example:

[schema material]
{
  Type        string metal "material type for audio and effects"
  Translucent bool   false "if the material can be seen through"

  [keyval Texture]
  {
    Type string Diffuse "type of texture (diffuse, normal, etc)"
    File string textures/default "Texture file"
  }

  [keyval Uniform]
  {
    Name  string Uniform   "the name of the uniform"
    Value float4 "1 1 1 1" "the uniform value"
  }
}

[material test]
{
  Type        concrete
  Translucent false

  Texture Diffuse   textures/concrete_diffuse
  Texture NormalMap textures/concrete_normal
  Uniform Color     "1 1 1 1"
  Uniform Specular  "1 0 0 1"
}

In this example, the data is defined in the material definition while the schema is used to typecheck the data in the material definition.  In schema, keyvals are defined as follows:

<name> <type> <default> <docstring>  // single value keyval

[keyval <name>] // multi-value keyval
{
  <name> <type> <default> <docstring> // value 1
  <name> <type> <default> <docstring> // value 2
  <name> <type> <default> <docstring> // value 3
}

The Type and Translucent keyvals from the material definition are examples of single value keyvals while Texture and Uniform are examples of multi-value keyvals.

The information defined in schema not only allows typechecking and verification of data, but it can also be used to data drive a gui editor. The user chooses the schema of the type of object to create and the editor creates the default structure and data for the object using the schema.  The editor just displays a property sheet view of the data and can provide special controls for editing each piece of data based on it’s datatype.  It can even display the doc string as a tooltip.

The most powerful feature of this system is that entirely new objects can be created simply by writing a new schema.  Once the new schema is defined the gui editor can be used to create new objects of that type.  All without having to edit any code.

References:

Scott Bilas: “A Data-Driven Game Object System”
http://www.drizzle.com/~scottb/gdc/game-objects.ppt