English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 26 June 2021, 10:33   #1
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Background store/restore question

Hi folks,

I've been tinkering away at a little game demo and it's going well, but I've hit a problem which seems to get getting bigger, so just want some advice before I commit to a technique.

I'm using the Blitter to draw the game's moving objects, but I'm doing it using modular type slices to construct an animation frame - the offsets of which are read off of a table and added to the main X/Y position. It works really well and I have stuff animating, but since I'm using the blitter on a single playfield, the background store & restore is getting very tricky to do with all these little pieces, and my drawing routine is just ballooning due to it (plus I'm still an assembly noob, so there's that as well). I was previously copying and restoring a big rectangle from the background for each object, but that wasn't very flexible.

I'm wondering if it might just be easier to copy and restore the whole (visible) 320x208 screen each frame, and that would restore the background for every screen object in one go without having to tediously do it piece by piece for every moving object? The problem with that is that it's a scrolling screen (twice the size of the visible screen, using a column blit on both sides for tiles, and then a pointer reset when the end is reached).

It would certainly save a LOT of hassle just refreshing the whole screen's background instead of saving/restoring a whole load of little bits, and I know the blitter is capable of copying very large rectangles, but if there's going to be a massive performance hit (I'm doing it on ECS A600) then I'll need to think of something else (I thought about using duel playfield mode to simulate a Megadrive style sprite layer, but I forgot that splits the bitplanes between each playfield).

Is this screen copy method maybe something worth pursuing?

Thanks!
Brick Nash is offline  
Old 26 June 2021, 11:09   #2
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Solving that hassle will result in much better performance of your game, restoring the entire screen will pretty much take up the entire video frame.

You can restore faster using a few methods.

1) have a pristine copy of the background at all times and restore using a combination of the saved blit offset, modulo and blit size. (This is the method i normally use)

2) use tile based restores, mark which tiles are dirty and simply restore them. This saves you chip ram over option 1

3) use the method you mentioned and save/blit/restore ... the problem is its slow and uses memory

4) redraw the entire screen which is very slow, but depends how your game is made up action wise.

Geezer
mcgeezer is offline  
Old 26 June 2021, 11:24   #3
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by mcgeezer View Post
Solving that hassle will result in much better performance of your game, restoring the entire screen will pretty much take up the entire video frame.

You can restore faster using a few methods.

1) have a pristine copy of the background at all times and restore using a combination of the saved blit offset, modulo and blit size. (This is the method i normally use)

2) use tile based restores, mark which tiles are dirty and simply restore them. This saves you chip ram over option 1

3) use the method you mentioned and save/blit/restore ... the problem is its slow and uses memory

4) redraw the entire screen which is very slow, but depends how your game is made up action wise.

Geezer
Thanks for the reply.

The tile restore from Option 2 seems interesting, as I'm holding a tile sheet in memory anyway for the backgrounds.

Option 1 seems like the way to go though, but wouldn't that require saving whatever the screen is displaying at that moment ? (I'm using a HW scroll, so the background would change with the visible screen).

Thanks again!
Brick Nash is offline  
Old 26 June 2021, 11:42   #4
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Do you have moving objects everywhere on the screen ?
If you have large areas that don't change often, you could restore only the part that encompasses all moving objects (finding this out is just coordinate comparisons to get min/max). It would already be faster than restoring the whole screen.
meynaf is offline  
Old 26 June 2021, 12:11   #5
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by meynaf View Post
Do you have moving objects everywhere on the screen ?
If you have large areas that don't change often, you could restore only the part that encompasses all moving objects (finding this out is just coordinate comparisons to get min/max). It would already be faster than restoring the whole screen.
I was previously just working out what the overall rectangle size of each animation frame was and just copying/restoring that for each object in one go, but they were pretty big, and trying to keep a steady origin point with changing frame sizes was a nightmare.

I think I may need to work out how to have a buffer(s) which can change size on the fly, but I don't know how to do that yet.

I think McGeezer's tile-restore method sound like it would work. I saw something similar on the Amstrad a few years ago, but that was just for static screen, so I may need to think about this.

I wish the Amiga (or at least the ECS) had a separate objects layer to blit to, but I guess this is all part of the challenge.
Brick Nash is offline  
Old 26 June 2021, 12:38   #6
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,211
Quote:
Originally Posted by Brick Nash View Post
I wish the Amiga (or at least the ECS) had a separate objects layer to blit to, but I guess this is all part of the challenge.
You can effectively do that using dual playfield (one playfield for background and 2nd playfield for moving bobs)... That way you probably *could* just clear the whole screen (using a combination of blitter clear and movem's with the CPU concurrently).

The ideal situation for you though, would probably be either:
  • The "dirty tile" replacement method (could use 32x32 tiles for decreased CPU use, at the expense of a little more blitter use)
  • Calculating the bounds of each "collection" of small bobs that make up each object, and using that for restore
DanScott is offline  
Old 26 June 2021, 13:11   #7
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Brick Nash View Post
Thanks for the reply.

Option 1 seems like the way to go though, but wouldn't that require saving whatever the screen is displaying at that moment ? (I'm using a HW scroll, so the background would change with the visible screen).

Thanks again!
No, you don't need to save what's already there. When you render the screen backgrounds you do it on three screens instead of two, so you always have that third screen available to restore thus negating the need to save.

I think you mentioned above as well that you blit a whole wall of tiles... in scrolling games and depending on your speed you only need to blit a small number of tiles. So for example, if your screen height was 256 and your scroll speed of bplcon1 was 1 then you only need to blit 1 16x16 tile for each position updated in bplcon1.

If you give more info on what you are doing we can probably give more clearer answers to best solve the problem.
mcgeezer is offline  
Old 26 June 2021, 13:49   #8
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by DanScott View Post
You can effectively do that using dual playfield (one playfield for background and 2nd playfield for moving bobs)... That way you probably *could* just clear the whole screen (using a combination of blitter clear and movem's with the CPU concurrently).

The ideal situation for you though, would probably be either:
  • The "dirty tile" replacement method (could use 32x32 tiles for decreased CPU use, at the expense of a little more blitter use)
  • Calculating the bounds of each "collection" of small bobs that make up each object, and using that for restore
I think the dirty tile method is what I'm going to go for. It seems like the perfect compromise. I already have a 16 colour palette and shared graphics linked to that so I'd likely need to spend time redoing them for a duel playfield setup with the 7 colours each. Just replacing the tiles seems much easier!

Quote:
Originally Posted by mcgeezer View Post
No, you don't need to save what's already there. When you render the screen backgrounds you do it on three screens instead of two, so you always have that third screen available to restore thus negating the need to save.

I think you mentioned above as well that you blit a whole wall of tiles... in scrolling games and depending on your speed you only need to blit a small number of tiles. So for example, if your screen height was 256 and your scroll speed of bplcon1 was 1 then you only need to blit 1 16x16 tile for each position updated in bplcon1.

If you give more info on what you are doing we can probably give more clearer answers to best solve the problem.
I think I get you now. A screen to show, a screen to draw on, and a screen that just draws a copy of the background?

For the backgrounds, I'm just moving through a map, and blitting one column of 16x16 tiles (same column) at either side of the visible screen in hidden areas. That way I can reset the pointers and still continue to seamlessly scroll through the map.

It's scrolling 2 pixels at a time (Poking increments or decrements of $22 to BPLCON1's scroll value until a pointer reset) and this is based on whether the X-pos of the player is past a certain point of the screen (push scroll).

I'm really interested in the tile replacer as I that seems to be the most effective, so I think I'll go with that.
Brick Nash is offline  
Old 26 June 2021, 15:05   #9
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Brick Nash View Post
For the backgrounds, I'm just moving through a map, and blitting one column of 16x16 tiles (same column) at either side of the visible screen in hidden areas. That way I can reset the pointers and still continue to seamlessly scroll through the map.

It's scrolling 2 pixels at a time (Poking increments or decrements of $22 to BPLCON1's scroll value until a pointer reset) and this is based on whether the X-pos of the player is past a certain point of the screen (push scroll).

.

You'll get a big performance boost by only blitting 2 tiles per frame instead of an entire column. It is very simple to do. Make your screen 1 word wider, and for testing open up diwstrt/diwstop so you can see the tiles being copied in per frame as bplcon1 updates the two tiles.... entirely up to you though.
mcgeezer is offline  
Old 26 June 2021, 15:40   #10
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by mcgeezer View Post
You'll get a big performance boost by only blitting 2 tiles per frame instead of an entire column. It is very simple to do. Make your screen 1 word wider, and for testing open up diwstrt/diwstop so you can see the tiles being copied in per frame as bplcon1 updates the two tiles.... entirely up to you though.
Do you mean for every increment/decrement of BPLCON1 I would blit 1 new tile into both the columns, instead of blitting the two entire column in one go when the pointers are updated?

I guess that would be easy enough to change, and if there's a performance boost then that would be great.
Brick Nash is offline  
Old 26 June 2021, 16:01   #11
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Brick Nash View Post
Do you mean for every increment/decrement of BPLCON1 I would blit 1 new tile into both the columns, instead of blitting the two entire column in one go when the pointers are updated?

I guess that would be easy enough to change, and if there's a performance boost then that would be great.
That's exactly what I mean.

Yep - big performance boost because you are doing much less blits.
mcgeezer is offline  
Old 26 June 2021, 16:44   #12
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Brick Nash View Post
For the backgrounds, I'm just moving through a map, and blitting one column of 16x16 tiles (same column) at either side of the visible screen in hidden areas. That way I can reset the pointers and still continue to seamlessly scroll through the map.
If your map is not endless you can just add mapwidth - displaywidth words to the size of your bitmap. So you can continue scrolling without having to blit a second column or reset the pointers. Halves your total number of blits again.
phx is offline  
Old 26 June 2021, 17:19   #13
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by mcgeezer View Post
That's exactly what I mean.

Yep - big performance boost because you are doing much less blits.
Great advice! Thanks. Sorry, for sounding thick, I just wanted to be sure.

Quote:
Originally Posted by phx View Post
If your map is not endless you can just add mapwidth - displaywidth words to the size of your bitmap. So you can continue scrolling without having to blit a second column or reset the pointers. Halves your total number of blits again.
Do you mean just make the size of the total area width the same size as the map (minus the visible part?) and just scroll through it? That would save a lot of recalculating stuff if there's no bpl pointers to reset.

At the moment, my total screen width is 704 and the visible part is 320. As I say, I'm just resetting to the starting point when I hit the right edge of the total area (but staying within the map position).

My map's width is 1280 (80 words), so it's exactly 4 times the size of the visible screen, although I may want to vary the size later on (but none would be endless).
Brick Nash is offline  
Old 26 June 2021, 17:38   #14
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Brick Nash View Post
Do you mean just make the size of the total area width the same size as the map (minus the visible part?) and just scroll through it?
No. That would waste a lot of Chip RAM. Just add the total number of words you would have to move the BPLxPT when scrolling to the rightmost position on the map.

Quote:
At the moment, my total screen width is 704 and the visible part is 320.
Then you can save a lot of Chip RAM. Three extra columns are needed (368). And the extra words for scrolling through the map.

Quote:
As I say, I'm just resetting to the starting point when I hit the right edge of the total area (but staying within the map position).
Not needed.

Quote:
My map's width is 1280 (80 words)
Which means you have to allocate a bitmap for 368x256(?) pixels plus 60 (80-20) words. For four planes this would be: 23*2*256*4+60*2 = 47104 bytes.
The 60 additional words allow you to continue scrolling to the right border.
phx is offline  
Old 26 June 2021, 19:03   #15
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by phx View Post
Which means you have to allocate a bitmap for 368x256(?) pixels plus 60 (80-20) words. For four planes this would be: 23*2*256*4+60*2 = 47104 bytes.
The 60 additional words allow you to continue scrolling to the right border.
Ok, I think I get the jist of what you mean (sorry, I'm still quite a noob at this). So it's basically just one screen with two edges for the blits and one extra for the scroll?

Are there any examples anywhere I could maybe have a look at for a reference?
Brick Nash is offline  
Old 26 June 2021, 19:18   #16
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Brick Nash View Post
Ok, I think I get the jist of what you mean (sorry, I'm still quite a noob at this). So it's basically just one screen with two edges for the blits and one extra for the scroll?

Are there any examples anywhere I could maybe have a look at for a reference?
Boot up Apidya with winuae with the action replay cart and have a look how the screen scrolls to the right... exactly the same technique.
mcgeezer is offline  
Old 26 June 2021, 20:05   #17
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Brick Nash View Post
Ok, I think I get the jist of what you mean (sorry, I'm still quite a noob at this). So it's basically just one screen with two edges for the blits and one extra for the scroll?
Exactly! And a few extra words on the bottom to be able to scroll the whole map width.

Quote:
Are there any examples anywhere I could maybe have a look at for a reference?
There is always Georg Steger's legendary Scrolling Trick on Aminet, which everybody who wants to implement proper scrolling should have read by now.
Don't remember the exact path, as Aminet is down again, but it is definitely
ScrollingTrick.lha
.
phx is offline  
Old 26 June 2021, 20:33   #18
Grumpa
Registered User
 
Join Date: Nov 2020
Location: Fareham, UK
Posts: 2
In case it's not available at the moment, ScrollingTrick.lha is in the zone for you...
Grumpa is offline  
Old 26 June 2021, 20:50   #19
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Excellent!

Thanks for the help chaps.
Brick Nash is offline  
Old 27 June 2021, 11:40   #20
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by Grumpa View Post
In case it's not available at the moment, ScrollingTrick.lha is in the zone for you...
Thanks mate! Got it now, so will have a look at it today

I gave the 1 screen technique that phx suggested a try though, and it seemed to work straight off the bat. No resetting bitplane pointers and it scrolls nicely to the end of the map. I didn't add any extra words though, I just changed the BM width to 368 and it was fine.
Brick Nash is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying restore old HDD JackTheKnife support.Hardware 12 03 March 2021 04:17
[Restore]Amiga 1200 Kwizoke restore (if possible) blog... Mr. Trog support.Hardware 9 02 September 2020 21:44
Trying to dust off and restore my old Amigas Alent New to Emulation or Amiga scene 6 09 March 2018 21:33
Restore system sprite Lazycow Coders. Asm / Hardware 27 01 November 2017 23:06
Double question about saving background nandius_c Coders. Asm / Hardware 5 15 January 2014 10:34

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:36.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.17951 seconds with 13 queries