Friday, September 18, 2009

Rigs Of Rods - understanding a new codebase

Before to get into some coding, I'm trying to get an overview of RoR's codebase. Unfortunately it's not very clean. No big deal, I created monsters worst that this... But really, trying to figure out what does a function of thousand lines called frameStarted is depressing. I would have like they took time to split what can be.. Sub-functions, sub-classes and packages not only give a felling of order, but also help comprehension.

Indeed, when you arrive in a project which is already well advanced, get some understanding of how the stuff works is the first thing to do. If someone, say Robert, is here to explain it to you, it is somehow easy. Robert will sit on a chair next to you and go straight to key classes, gives you a little sentence explaining what each class or function is supposed to do and how they are related to other classes.

If the project is big, he will skip what doesn't interest you, eventually tell you that you don't have to understand this or that to accomplish your task.

On a well structured code, the brain will classify everything in little boxes saying: this is a class for handling the terrain, this class I don't care for now, classes in this package are about physics, etc.

Alright, but when nobody is there to explain? Well, that is what comments are about, they need to replace Robert, give a picture of what is the code does. That is why all classes should at least have a little explanation that can be read by someone who doesn't know much about the code.

I can give an illustration, taken from a exam revision program I wrote:

// A file where answers are stored (with compression)
class AnswerArchive;

There it is. It's a nice comments that probably says enough for a man that already knows about the project internal details. But doesn't give the class reason of existence in the big picture, so it's little help for newcomers.

Let's try again.

// Overview:
// Answers given by the user needs to be stored to allow review of previous exams later in time.
// - the ExamReview class loads data from an AnswerArchive for this purpose.
// - the ExamState class appends given answers to the AnswerArchive at the end of a session.
// Compression is applied to the data, because the mobile version have a low storage capacity.

// A file where answers are stored (with compression).
class AnswerArchive;

Now we know who uses this class and why it exists. Because what it does is not the only thing one would like to know about a class or function, why it does it also is important.

Well, I really wish RoR developers took time to do it. They didn't so I think I'll better try to find some "Robert" in forum!

Wednesday, September 16, 2009

Rigs Of Rods - first thoughts

Our virtual driving project may radically change direction. Since we started it, "Rigs of Rods" got open-sourced and it's a very good simulator. Probably more interesting than Torcs was.

So my job now consists in understanding a new code-base and trying to get involved. Well, getting involved is basically about founding something to do that both interests the RoR's projects leaders and interests us.

After some hard time loading the repository and making it compile and execute on my computer, I played for some hours...

First feeling: the game is ok. In fact it's not really a game, just a simulator. You are given the choice between eight maps, then you pick a vehicle and drive around... You can drive cars, trucks, planes or boats. There are probably some nice physics models behind them, however somehow buggy.

Few things happened:
- I've been stuck into a wall.
- I had my car completely lost in space.
- The game suddenly became incredibly slow.

But, most of the time it's ok.

The simulation of engines sound is very good.

The graphics are correct, nothing more. But really it's too slow for what it does... My 7600GT shouldn't have such hard time display particles and vegetation. The textures shadows are buggy (sometime the shadows appear "above" me), the implementation of HDR is horrible to see. I'm sure there are some improvement in both speed and quality I can make there, I'd like to.

Concerning the geometry, roads sometime falls into the ground and require more smoothness. Hard angles make the car jump and we lose control.. I think I'll go into this code, because I still like to think providing data compatibility between Torcs, RoR and OpenRacing should open some interesting possibilities. We'll see that later...

Anyway, this is a nice simulator that I hope we can improve enough to host the our Virtual Darpa Challenge!