#24534 - ChronoDK - Thu Aug 05, 2004 10:14 am
I'm having trouble getting some scroll-code working.
Code: |
void UpdateMap(const unsigned short* source, unsigned short* dest, short source_width, short x, short y)
{
short row, tile;
for(row = 0; row < 21; row++)
{
for(tile = 0; tile < 31; tile++)
{
dest[tile + row * 32] = source[(tile + x) + ((row + y) * source_width)];
}
}
}
void UpdateMap2(const unsigned short* source, unsigned short* dest, short source_width, short x, short y)
{
short row, tile;
for(row = 0; row < 21; row++)
{
for(tile = 0; tile < 31; tile++)
{
DMAFastCopy(&source[(tile + x) + ((row + y) * source_width)], &dest[tile + row * 32], 16, DMA_32NOW);
}
}
}
|
The first function works fine when it only has to update one background, but when I need to scroll two backgrounds it's too slow.
Then I tried with DMA, using Harbours DMAFastCopy, but it's not even fast enough for one background.
Am I doing something wrong or should I try another approach? I need to be able to scroll two large 256-color backgrounds at the same time.
#24539 - poslundc - Thu Aug 05, 2004 1:40 pm
From the look of things, you're copying an entire 20x30 set of tiles into VRAM... it is unsurprising you don't have time to accomplish the entire thing twice in your VBlank period.
Try to restrict your tile usage to a single set per screen/level/whatever and then just reuse tiles as necessary in constructing your map.
Dan.
#24541 - ProblemBaby - Thu Aug 05, 2004 1:57 pm
Use the Wrap function (REG_BGXCNT |= 0x2000).[/code]
#24553 - sajiimori - Thu Aug 05, 2004 5:22 pm
If you scroll less than 8 pixels per frame, you'll never have to copy more than one row/column of tiles at a time (except for the first frame).
#24561 - dagamer34 - Thu Aug 05, 2004 11:14 pm
sajiimori wrote: |
If you scroll less than 8 pixels per frame, you'll never have to copy more than one row/column of tiles at a time (except for the first frame). |
Yeah, too bad that most of the time you will be scrolling sideways, meaning DMA can't be used to copy data. Though using a rotated background would be a good solution.
_________________
Little kids and Playstation 2's don't mix. :(
#24564 - tepples - Fri Aug 06, 2004 12:04 am
There are 32 bytes per 8x8 pixel 16-color tile, and 32 bytes is a highly convenient chunk for an LDMIA/STMIA update loop.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#24568 - Miked0801 - Fri Aug 06, 2004 1:35 am
Which is exactly how we do it in our engine...
#24569 - dagamer34 - Fri Aug 06, 2004 1:53 am
tepples wrote: |
There are 32 bytes per 8x8 pixel 16-color tile, and 32 bytes is a highly convenient chunk for an LDMIA/STMIA update loop. |
Convienient if you are pretty fluent ARM assembly... I can't say that I am. :(
_________________
Little kids and Playstation 2's don't mix. :(
#24576 - ChronoDK - Fri Aug 06, 2004 7:57 am
Whoops - the code for only updating the map when I had scrolled 8 pixels had been commented out... It updated the map every frame and tried to hardware-scroll anyway :-)
So the first function works just fine now. I'm a bit worried if it will be fast enough when I get more things running though...
Miked0801 wrote: |
Which is exactly how we do it in our engine... |
More hints would be helpful :-)
#24590 - sajiimori - Fri Aug 06, 2004 5:56 pm
Hints about the assembly stuff? I wouldn't worry about it yet -- the speed of your code can be increased by 30x by only copying new tiles. Get your algorithm right first, then if it's still not fast enough you can think about low-level optimizations.
#24612 - Miked0801 - Sat Aug 07, 2004 9:26 pm
I can honestly say that even doing full screen updates (with DMA transfers in VBlank) written in C will be fast enough for almost any thing you need to do. We released a bunch of comerical games with that style of scroll engine and only switched over to edge drawing when we started doing dynamic char loading. It isn't that hard to get a pretty fast scrollerdoing whole screen updates.
#24646 - dovoto - Sun Aug 08, 2004 4:55 pm
If you are interested there is example background rendering code (about 20 increasingly complex background demos) on my site. They cover up to 4 way scrolling and start simple and get complex. The code may be a bit outdated but it should still be sound in concept.
www.thepernproject.com ->tutorials -> day 6 old html
-jason
_________________
www.drunkencoders.com