Apr 14, 2012

Digger.NET in development, part 4

This post could also be named: "Why is it a good habit to search for and read the docs" or "Why is it a good habit to comment your code".

The base source code of a Digger Remastered is a C Windows application which uses DirectX for graphics output. Due to the source evolution nature of this game (at least I think so), which was a DOS application before, variables naming is somewhat... short. No camel case also. And almost no comments in source code. I've downloaded latest source code for Windows as my starting point. I thought it will not be very hard to understand the code of this, rather simple, game. I've deciphered some part of a high level game code, but then I've approached a graphics code. This is the place there I have stuck a big time. Can you guess what this code does?

void putis(void)
{
  int i;
  for (i=0;i<SPRITES;i++)
    if (sprrdrwf[i])
      gputi(sprx[i],spry[i],sprmov[i],sprwid[i],sprhei[i]);
}

As you can see, all variables here, except for i are global. Also complicates things, you know. This was also frustrating because I didn't actually need most of the graphics code, which uses pixel-by-pixel drawing since I use real bitmap sprites for drawing. But because this code also tightly coupled (related) with other game logiс (collision detection for example) I need to understand it too.

Not so long ago, I've decided to look for another sources on the site, Java in particular, in hope it will help to understand the graphics code. However, the Java sources were useless, but I've also downloaded (for some unknown reason) old windows sources and voila, I've found some text files inside the zip! The description I found inside was invaluable:

void putis(void)
 Redraw background images


quite unexpected from a name though, hmm. Considering there are tens of different obscure functions and global variables, and deciphering one of them can take hours, this file gonna save me big time (pun here!).

Strange thing though is, why not add this single line as a comment in source code file, just there it belongs, not in a big separate text file. Why? Why?! Why?!!

No comments:

Post a Comment