Monday, February 25, 2013

Track Format Solved!

Following on from yesterday's post, I resolved OutRun's track format. This means we can press ahead with creating the level editor.

Firstly, I plotted the raw track data points as an x,y scatter graph in Excel. As you can see, the x,y co-ordinates that comprise the track data form a perfect circle. This is a pretty big clue.

The track is stored as a series of 2D co-ordinates on the perimeter of a circle (radius 4096). So to create the first left turn in Coconut Beach, you can start at 0, 4096 and iterate anti-clockwise from this point. For example, the start of the left turn is represented as follows. 

To sharpen the turn, you essentially step through the circle perimeter faster. To create a turn in the opposite direction, you iterate through the circle in the opposite direction. To create a straight you can simply stop wherever you are in the circle and continually output the current coordinate. 

I'm curious to know whether this technique for path generation is a common one, and whether it has a name. 


d from Shmups said...

Wow, this is such incredible news.
This really puts a smile on my face. Can't wait.

yt said...

Like all these things, it was pretty simple once I figured out the solution.

The code to take the circular coordinates and translate them to a scanline x position for the road obfuscated the problem somewhat and was actually a bit of a distraction.

I would have thought that the track path could be stored as a simpler list which represented the "change in x position" from the last position (rather than 2D co-ordinates). But maybe I'm missing something.

d from Shmups said...

Has there ever even been a track editor for a 2D racing game?
I have never heard or seen a track editor for a 2D racing game at all on any format. If I were rich I would pay you for your hard work.

yt said...

I created a 2D track editor for a mobile title back in 2004 when I was programming professionally.

It was originally used on a Wacky Races game that I developed.

The engine evolved and was used in a 2D version of Project Gotham Racing (handled by another programmer). I can't remember the extent to which the original track editor was used. The engine was definitely improved along the way, as mobile tech was improving rapidly at that point.

Video here.

Keep buying those lottery tickets!

Kungfu Steve said...

Very cool.

Did you figure out the Hills? The hills are what really make Outrun shine. Especially thrilling, on the blind hills... where you have no idea if your about to run into another car.

Also, I caught the post about the Spinner. Spinners are a common controller for racing games, and a common controller for arcade game enthusiast altogether.

Some use them for Tempest, or Arkanoid.. but then you have an Epic game like Supersprint... that just cant be played without a spinner.

Many arcade racers used Optical 360 degree wheels (spinners):

Turbo (Sega)
TX-1 (Tatsumi)
Pole Position I & II(Atari)
Supersprint & Championship Sprint
(also all the older b/w sprint games too)

Road Blasters
Hot Rod
Super Off Road

Other great spinner games:

Major Havok
Star Trek
Tac Scan
Discs Of Tron
Mad Planets
Crater Raider
Top Secret

Because PC games allow use of the mouse on most driving games... and because certain really great spinner games are in mame and other emulators.. many people choose to use a 360 degree wheel, which is just a spinner without the large wheel... or just use a spinner outright. That allows the ability to play any racing game, either 270 degree.. or 360 degree. It also allows for Atari's
Race Drivin & Hard Drivin... which actually used 10 turn pots. (no PC wheel will have that level of resolution, so a spinner is the only way to operate that game on a pc currently... (especially due to mames poor support on interfacing real arcade controllers.. )

Anyways, it would be a bit of a shame not to include mouse control for steering, as an option. (which is exactly what a spinner is. Its just the horizontal x-axis)

Kungfu Steve said...

By the way, Im not sure what the typical outrun wheels values are... but If I were to guess why the track data is a circle... it might be because it the level editor was programmed in a sort of 'live' manor... where the level creator actually uses the steering wheel to steer where the track is being drawing...

They may have also used the analog pedals to control the height of the hills.

yt said...

I'm leaving spinner implementation as an exciting programming challenge for whoever is interested in the feature. :)

I'm more interested in getting started on the track editor; and yes the long-term dream is track path, elevation, object placement, road width, palette choices and everything else you can think of.

yt said...

I don't think that idea is out of the question (i.e. the wheel for track path), as some of the track data co-ordinates for straight sections are not constant (i.e. they deviate around a value for no real reason).

Thiscould indicate some sort of hardware was being read in order to create the track paths. But maybe we'll never know.

Unknown said...

A post in the Arcadecontrols forum put me onto your project and I have to say I'm blown away by your progress. Subscribing to your blog for sure and looking forward to seeing a track editor for outrun! :D nice work indeed.

Ramjet :D

Adrian said...

Amazing work yt!

Unsurprisingly Super Hang-On also uses the same track format. Here's a plot of the first 2 stages of the beginner course (the track data is always referenced in paired stages). The first two stages make up approximately 320 degrees of a full circle. The data for this can be found at addresses 0x18352 - 0x1A761 in the sub-cpu address space.

I'm sure if you manage to create a track editor that can pump out Out Run tracks it will also be able to produce Super Hang-On tracks too (and maybe even original Hang-On).

Many thanks for your continued work on pulling my all-time favourite arcade game to pieces!

yt said...

Good work on Super Hang-On. As I mentioned in a previous post, a lot of the road CPU code is the same, but slightly simpler than OutRun. :)

Obviously if you create another two columns in your spreadsheet that add the previous x,y in those columns to the current ones you can render the actual path of the track.

Adrian said...

Hmmm, strange! I plotted the profile data as you described and things aren't all that they seem!

As I mentioned before, Super Hang-On always references the stages in pairs (so you've got 3 pairs of stages in beginner class, 5 pairs in junior class, etc). When rendering the data, stage 1 bends accurately follow the game as viewed from riding the bike but stage 2 bends from (and including) the bend where the checkpoint is are all inverted compared to the actual game! Very odd!

All I can think is that the sub-cpu code does some inverting once it reaches the second stage of each pair. Tomorrow I'll try rendering a different pair of stages, maybe from a different class, and see if the same behaviour holds true for other stages.

I presume Out Run only references a single stage at a time and so this issue doesn't arise for you.

Here's a grab of the profile of stages 1 and 2 of beginner class.

Sorry for derailing your original post.

yt said...

The road code lets you invert any track.

This is mainly used in OutRun for the road split section. There is one lot of data for both the left and the right split. The road is inverted accordingly :)

So possible that's whats going on in Hangon too..

Matías Moreno said...

It's easy to plot absolute X,Y coordinates by integrating circle coordinates. See last sheet here:

yt said...

Indeed that's what I mentioned in the post above :-)