Apr 15, 2012

Digger.NET in development, part 5

Well, I extremely satysfied right now, since I've done complete main screen of my XNA port of a Digger Remastered. The currently main page looks like:

I'm impressed how easy it's for a complete gamedev noob (like me) to do things in XNA. So, original internal framerate for Digger is something like 15 frames per second. Question: how much it takes to set it in XNA game? Answer: one line, just add this to your main Game class:
// original frame rate is 15 fps (67 ms per frame)
this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 67);
So-o-o nice! So nice I will count the XNA one of the best frameworks which comed from Microsoft (I'm hoping Microsoft will not slow down or stall the thing with it's new Metro-Shmetro and all the native stuff which it puhing quite intensively lately, IMHO).

This is especially evident if you look at the original C code, it's so complex. The graphics and drawing code is incredibly complex. I'm not going to blame the author, seems like he did much more complex job than I but this:
bool sprrdrwf[SPRITES+1];
bool sprrecf[SPRITES+1];
bool sprenf[SPRITES];
Sint4 sprch[SPRITES+1];
Uint3 *sprmov[SPRITES];
Sint4 sprx[SPRITES+1];
Sint4 spry[SPRITES+1];
Sint4 sprwid[SPRITES+1];
Sint4 sprhei[SPRITES+1];
Sint4 sprbwid[SPRITES];
Sint4 sprbhei[SPRITES];
Sint4 sprnch[SPRITES];
Sint4 sprnwid[SPRITES];
Sint4 sprnhei[SPRITES];
Sint4 sprnbwid[SPRITES];
Sint4 sprnbhei[SPRITES];
is just nonsence. At least you can pack each x, y, wid, hei etc. coordinate like data in a structure with two fields. And this is just a tip of an iceberg. Consider this young fella from sprite.c:
void drawspr(Sint4 n,Sint4 x,Sint4 y)
{
  Sint4 t1,t2,t3,t4;
  x&=-4;
  clearrdrwf();
  setrdrwflgs(n);
  t1=sprx[n];
  t2=spry[n];
  t3=sprwid[n];
  t4=sprhei[n];
  sprx[n]=x;
  spry[n]=y;
  sprwid[n]=sprnwid[n];
  sprhei[n]=sprnhei[n];
  clearrecf();
  setrdrwflgs(n);
  sprhei[n]=t4;
  sprwid[n]=t3;
  spry[n]=t2;
  sprx[n]=t1;
  sprrdrwf[n]=TRUE;
  putis();
  sprenf[n]=TRUE;
  sprx[n]=x;
  spry[n]=y;
  sprch[n]=sprnch[n];
  sprwid[n]=sprnwid[n];
  sprhei[n]=sprnhei[n];
  sprbwid[n]=sprnbwid[n];
  sprbhei[n]=sprnbhei[n];
  ggeti(sprx[n],spry[n],sprmov[n],sprwid[n],sprhei[n]);
  putims();
  bcollides(n);
}
no comment (pun here!). How many global variables you can count here? Maybe you want to know that ggeti is? Actually it's a function pointer, to another function (which is actually quite an elegant solution to switch CGA and VGA graphics mode):
void vgageti(Sint4 x,Sint4 y,Uint3 *p,Sint4 w,Sint4 h)
{
  Uint5 i;
  for (i=0;i<h*2;i++)
    if (i+y*2 < 400)
      farmemcpy( (char far*) (p + (Uint5) i*w*8l), back_bitmap_bits+ (Uint5) ((y*2l+i)*640l + x*2l) , w*8);
}
how many magic numbers you can count here? Developer suggests contacting him in case of any questions. But last modification date for source is year 2004. I feel it's little rude to notify person on his completely forgotten project. This is so sad he didn't leave enough comments then he could.

No comments:

Post a Comment