PocketMatrix forums

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

Multiscrolling loop

Sorry to keep posting, but I've just started on eVC, and after PocketC, and I must say it's way cooler. anyhow, I've magaged to make a screen buffer, twice the normal size (240x640), I can scroll up it etc, but when I get to the top /bottom I'd like to continue to scroll, but with information from the other end of the buffer, so you can have the screen showing half of the bottom, and top etc or my larger buffer.... whats the easyest way to do this..... :)

-brendan
brendan · 16 Jan 2002, 03:10 UTC — I'm doing this....
At the moment I'm doing somthing like this:

Code:
i = i +10;
if (i > 320) i = 0;
PIXEL* source = star_scr + i * 240;
PIXEL* dst = screen_buffer;
for ( int y = 0; y < 320; y++ )
{
for ( int x = 0; x < 240; x++ )
{
PIXEL spritepixel = *source++;
if (spritepixel != 0) *dst = spritepixel;
dst++;
}
}


[admin edit: please use CODE blocks]
you might be better off using memcpy as it will be faster (remember every pixel is 2 bytes)
so instead your x loop you could have something like
Code:
memcpy(dst,source,480); //(240*2=480)


PS.actually looked on your code, do you really need the if statement?
Code:
[b]if (spritepixel != 0)[/b] *dst = spritepixel;

I'm not sure if you're aware of the fact, that:
1.Because of this if, it copies only pixels with color value other then 0 (doesn't seem like something for a scroller)
2.It's much slower with the if statement (althrought you need it for transparent sprites)
3.If this if statement is what you wish, memcpy won't be able to reproduce your effect so you can't use it. Althrought if you don't want this if statement to be there simple leave
Code:
*dst = spritepixel;
, better idea yet would be to do the copy without the spritepixel variable (not sure exactly how EasyCE works so I might be wrong here, I'm guessing the meaning of spritepixel variable)
Code:
*dst=*source++;
, still, memcpy will be much faster (up to nearly 100% I would say, at least on IPAQ's)
If you want to wrap, basically what you want is to read line 1 when you say '641'. So, if you copied like this:

Code:

int startline = 560; // your scroll position
PIXEL* dst = getbuffer();
PIXEL* src = scrollbuffer;
int y = startline;
for ( int i = 0; i < 320; i++ )
{
PIXEL* src = src + (y % 640) * 240;
memcpy( dst, src, 480 );
dst += 240;
y++;
}


In this fragment, 'scrollbuffer' is your 240x640 bitmap. The '% 640' makes sure you wrap around. You copy 480 bytes at a time using the memcpy, and you advance the destination pointer by 240 pixels.

Note that '%' is a slow operation. For optimum performance, you need to split this loop into two loops: One that draws the lines until the 'wraparound line', and one that draws the other lines. That's slightly more complicated, and I didn't get my first coffee yet, so I'm not going to type that in. :)

- Jacco.
brendan · 17 Jan 2002, 23:06 UTC — better way, I think
I think I've a better way !!! yes / no, it works!

Code:

void GQ_move_buffer_up(int x, int y,int size, PIXEL* source)
// temp has been pre-defined, that way I don't create / destroy every time I call func.... just got to be aware of size limits
{
memcpy(GQ_temp + x * size,source, (x * y - size * x) * 2);
memcpy(GQ_temp,source + x * y - size * x, size * x * 2);
memcpy(source,GQ_temp, x * y * 2);
}


[admin edit: please use CODE blocks :)]