PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

can it get better?

HI all I have the following function thats performs a number of functions:

it takes a tile from a master graphics sheet (buffer), places in into another pic (buffer), upon doing that it checks to make sure the pic is not behind any onther object by using a master z-buffer array, and also checks part of the image is not transparent, oh, it also makes sure your not trying to place it off screen (within the 240x320 buffer size)

can anyone see anyways of speeding it up?

Code:

void place_item_trans_Z(int ty, int zx, int zy, int destsizex, int xpos, int ypos, int xsize, int ysize, int number_itemsx, int item, int transcolor, PIXEL* src, PIXEL* dest)
{
//ty bottom of image to place, zx,zy location in z_buffer
unsigned int dest_loc = (destsizex * ypos) + xpos;
unsigned int source_width = number_itemsx * xsize;
unsigned int source_loc = ((item / number_itemsx) * source_width * ysize) +
((item % number_itemsx) * xsize);
int calc;
for (int y = 0; y < ysize; y++)
{
if ((y+ypos < 320) && (y+ypos >= 0))
{
for (int x = 0; x < xsize; x++)
{
if ((x+xpos < 240) && (x+xpos >= 0))
{
if (level[zx + x][zy + y].z_buffer <= ty)
{
calc = source_loc + x;
if (src[calc] != transcolor) dest[dest_loc + x] = src[calc];
}
}
}
}
dest_loc += destsizex; // move down a row in dest
source_loc += source_width; // move down a row in source
}
}


One of the Q's I has was, would it be faster to check to transparency first, then do the z_buffer, or the other way around?

-thanks
Its quicker to test for trans first ;-)
any other comments!
It'll be faster to clip your extents before you enter the for loops, rather than clipping each pixel against 0<=x<=240 and 0<=y<=320.
...and you could check transparencies in a row instead of on a per pixel basis, if your graphics "like" it :)

cryo
I dont think my graphics "like it"..., mmm well maybe they do?, not sure.... have not tried it, my arrays are definded as a 16 bit PIXEL, (it's based on easyce), maybe I can hack it up a bit to be 32bit, and process 2 pixels at a time...

as for checking for clipping first.... my brain is already overloading from this function... I'll have to get my head around it a bit more before "playing around with it", I've still got a headache after implememting z-buffers into my code =-)

-B