[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linux games programming tutorial-part2



I had a quick look through your doc. Hereīs what I found:

> 2)How to use a graphic library.
> What is said here apply to ANY graphic library. The use of a graphic library include 

s/apply/applies/
s/include/includes/

> -1:Initialise the library

s/Initialise/Initialize/

Just some spelling errors that appear several times.

> -5:Eventually call a fonction that will quit properly the library

s/fonction/function/

> /* Initialise */
>   if (vga_init()!=0) {printf("Error initialising svgalib!\n");_exit(1);}

IIRC exit () (without the leading underscore) is the standard C function
for abnormal exit.

>start by "vga_" or "gl_", that's of course to allow the programmer to know which library the function own.

better: ... which library the function is in.

>   getchar();

wouldnīt getch () be better?

> This function read the pcx image from file to target, assuming the image is size bytes lenght:
> 
> void readpcximage(FILE * file,void * target,int size)
> {
>   unsigned char buf;
>   unsigned int counter;
>   int i=0;
>   while(i<=size)           /* Image not entirely read? */
>     {
>       fread(&buf,1,1,file);      /* Get one byte */

You should add a comment here that fread()ing single bytes can be quite
slow. For demonstration purposes itīs ok, but for real-world code
reading larger chunks at once (e.g. 8k-blocks) is better.

>       if ((buf&192)==192)        /* Check the 2 most significant bits */
>         {                        /* We have 11xxxxxx */
>           counter=(buf&63);      /* Number of times to repeat next byte */
>           fread(&buf,1,1,file);  /* Get next byte */
>           for(;counter>0;counter--)   /* and copy it counter times */
>             {
>               memcpy((target+i),&buf,1);

memcpy () is way too much overhead for copying just one single char.
target [i] = buf;   would be better.

>   target=(void *)malloc((*lenght)*(*height));
> Now it is usuable. We do the memory allocation when we know the size of the sprite, in order to don't waste memory. After the allocation we can safely load the sprite and display it.

Some note that usually the bytes per pixel has to be included in the
size calculation would be good here.

> See you on next part!

Iīm looking forward to it :)


	Christian