This page covers the new driveline format introduced along SuperTuxKart 0.7
Detailed concept: QuadGraph
While the description so far is exactly what is supported by the track exporter, the actual concept implemented in STK allows more complicated structure. This is done by maintaining two data structures: one containing the list of all quads, and one describing how the quads are connected with each other, the so called quad graph. The main difference between the two data structures is that one quad in the list of all quads can be used several times in the graph. The graph consists of nodes - as a default, each quad corresponds to a graph node with the same number - this is exactly what the track exporter assumes. But this is not necessary: A part of the track might not be used for a particular race (think of a city track where several different race tracks can be defined), or some quads might be used more than once (e.g. a figure 8 race track: the quad in the 'intersection' would be used twice)
The graph defines for each graph node which quad it belongs to, and which are the possible successors. Usually each quad will have exactly one successor, but in case of a shortcut or branch of the track it might have more than one.
Given the quad definitions from the picture, the following graphs could be defined:
A graph with nodes 1 to 29, corresponding to the quads 1 to 29. The order is then
1 → 2 → 3 → ... → 29 → 1.
A graph with nodes 1 to 29, corresponding to the quads 1 to 29 and the graph:
1 → 29 → 28 → ... → 2 → 1.
This gives a similar simple loop as the one above, but it is driven in reverse (ie. counter-clockwise).
Simple Loop with Shortcut
For this we need a graph with 34 nodes, corresponding to the 34 quads. The main loop will be defined as in example 1, but additionally we add:
15 → 30 → 31 ... → 34 → 23
This allows the AI to pick any of the two ways (the criteria for which way is picked are not defined yet - atm it's a random selection).
XXXXXXXXX The numbers indicate the number of the quads. This part does not define in which order the quads should be driven, or if the shortcut is to be used or not, it only defines which part of the track can be used. YYYYYYYYYYYYY
A Loop Inside of the Track
The driveline structures also allows us to define a loop, i.e. forcing the AI to drive a circle before continuing, see picture:
(note that this is most likely an absurd example only - for a track like this to be fair the player karts would have to do the same loop, which means there must be a mean to indicate this to the player, which we currently don't have).
To do this, we need additional graph nodes for the sections that are driven twice. So graph nodes 1 to 34 corresponds to the quads 1 to 34, and then additional graph nodes 35 to 43 which are mapped to the quads 15 to 23 (again). So the quads 15 to 23 have each two graph nodes associated with them, but each graph node still has exactly one quad. Then we can define the following graph:
1 → 2 → ... 14 → 15 → 16 → ... → 23 → 34 → 33 → ... → 30 → ...
This defines the first part of the loop: driving backwards on the shortcut to graph node 30 (which is quad 30). Then we use quad 15 for the second time, so we use the additional graph nodes here:
... 30 → 35  → 36  → ... → 43  → 24 → 25 → ... → 29 → 1
In  are the corresponding quad numbers for the graph nodes 35 to 43. By having the additional graph node layers the AI will simply follow the graph till the end (so there are no loops in the graph, except for starting a new lap), but the mappings of graph nodes to quads force the AI to drive a loop.
How to create drivelines with the track exporter
The track exporter is able to create quad and graph data structures from specific meshes in the track. While it can't handle all theoretical cases (e.g. a looped track as the last example above is not possible, to do this you have to manually edit the graph file), it can handle all kinds of shortcuts and alternative ways.
Creating a Shortcut or Alternative Way
If you want to add a shortcut (or alternative way), use a similar structure as for the main driveline, but give the game logic property 'type' the value 'driveline' (as opposed to main-driveline)
The shortcut is added in the picture using again two vertices to indicate where the start point is. The export script will then automatically export the additional quads, and create the graph from the closest quad of the main driveline to the beginning of the shortcut, and from the end of the shortcut to the closest quad.
How to convert old drivelines to the new format
The old driveline format used two meshes - one for the left side, and one for the right side. To convert these to the new format:
- For each of the two drivelines remove the edge that crosses the starting line. So instead of having a loop you have two lines, each line having a starting point and an ending point indicating the direction in which the karts are driving (see picture above).
- Combine the two meshes into a single mesh.
- Create a new edge connecting the two starting points.
- Create a new edge connecting the two ending points.
- Select the two starting vertices, extrude them (vertices only), to indicate where the first quad to drive on is.
- Add the game logic property 'type', and set it to 'main-driveline'
Now you should be ready to export the track.
The file format
While it is not at all necessary to know or understand the file format used, here a short description which should help in debugging any problems, or modeling more complex graphs than the default one created by the exporter script.
The created .quad file is plain ASCII, e.g.:
<?xml version="1.0"?> <quads> <quad p0="15.575774,33.574879,0.000000" p1="-20.480236,11.145029,-0.000000" p2="-36.736404,14.047918,-0.000000" p3="-36.095619,34.736038,-0.000000"/> <quad p0="0:3" p1="0:2" p2="-89.494789,13.467787,-0.000000" p3="-90.163483,34.155022,-0.000000"/> <quad p0="1:3" p1="1:2" p2="-108.047676,9.295321,-0.000000" p3="-129.087753,34.263454,-0.000001"/> ...
A quad is defined by specifying four coordinates. This can be done either by using four 3d coordinates (as in the first quad line), or by referring to a point of an already defined quad: the latter case uses p0="Q:P" which means: use point P of quad Q as point 0 of the current quad.
Similarly the graph files are plain ASCII, too:
<?xml version="1.0"?> <graph> <node-list from-quad="0" to-quad="54"/> <edge-loop from="0" to="54"/> </graph>
The first section described the mapping of quads to graph nodes - it will always be a 1:1 mapping, i.e. each quad will be used in exactly one graph node. Then the connection of the graph nodes are described. Besides defining a loop, a single edge can be defined as well: <edge from="15" to="23"/>