Sunday, May 25, 2014

Need for Speed XNA update!

It's been at least 4 years since I did any work on my remake of the original need for speed game. Back then it got picked up by a few gamedev sites and I was contacted by EA Canada asking if I was interested in interviewing with them! (A completely different story to Square Enix and my Carnageddon remake!). Looking it now is a bit embarrassing - I cut a lot of  corners before the release, the code is messy but it does let you blast along the Alpine tracks and it's still sort of fun to play. With the end of XNA, and being between projects, I decided to do a quick port to Monogame and move the project to github.

I figured it would be a few days of work and I'd be done with the port, as Monogame implements almost all of XNA 4. Unfortunately, XNA 3 was the latest version when I made nfs, so first I had to update to XNA 4 and deal with all the breaking changes. Once that was done, it was running in Monogame pretty quickly. The problem was it wasn't as fun to play as I thought it was, and the code was much worse than I thought it would look :(  Somehow if I leave code for several years it seems to degrade! I started ripping, replacing, refactoring, all the things that software devs love to do! The  problem now was when I wrote the code I had built up a really good mental model of the Need for Speed track structure and how it was represented in code and in the data files.  It's quite complex, with many parts, represented by classes with names like TrackNode, TerrainSegment, TerrainRow, TerrainStrip etc. Looking back on it now, the code doesn't do a good job of explaining how these objects fitted together. I used to know that a TerrainSegment always had 4 TerrainRows, and each row had 10 TerrainStrips, but a few years later there was a lot of head scratching!

Anyway, a few weeks of late nights later, a huge amount of refactoring, bug fixing, and more digging around the original data files with a hex editor, OpenNFS1 is much cleaner and more faithful to the original. A couple of things that made the biggest look n feel difference was changing the field of view and aspect ratio to match screenshots of the original. The values I used before were way off, and resulted in a lack of feeling of speed. I've added some simple ai to race against, here are a couple of screenshots with 100 racers! The original game used some really fun optimizations to have 8 cars simulated at once, which I am also using, and 100 cars is actually pretty computationally simple because of it.

I'm going to write a few posts about how the tracks and scenery and physics are organized
in the original game (as far as I can guess from understanding the data files) because some of the ideas could work well for mobile games today. Also, if I don't write it down this time, I'll forget and hopefully it will be interesting for someone else too.

1 comment :