my vertical scrolling is slow

BlitzMax Forums/BlitzMax Beginners Area/my vertical scrolling is slow

hub(Posted 2006) [#1]
Hi !

i'm interested only by vertical scrolling. i use this piece of code into my project. When i increase the number of tiles, the scrolling is slow. Coz the for-next loop inside the Compute_one_row_Scrolling() and Draw_one_row (). How to avoid the for-next loop ? I'm searching a better solution.

i my game i use an editor to produce a level, next i read a file. so i must keep this structure.

Col = 0 to 32, Row 0 to 1000 or more.

Type TBrick

Field Col
Field Row

End Type

(indexed by Row, and Col)

i know scrolling examples into tutorials. i prefer some help to correct this code.

Many thanks for your help !




ImaginaryHuman(Posted 2006) [#2]
32000 tile images being drawn? Not surprised it's slow.


hub(Posted 2006) [#3]
no : it's an example. Of course only visibles tiles being drawn to screen !!!. Please test the code to see the pb.


SoggyP(Posted 2006) [#4]
Hello.

Personally, I'd:
- hold the tiles in an array, not a list;
- apply a global decal offset to the values;
- create images instead of drawing rects.

The difficulty is that every inner loop you're iterating through all the tiles 24 times, regardless of if they're on screen or not, and then iterating through them once again 24 times to display them (again regardless of if they're on screen or not). That's a lot of tiles.

If you're not sure what I mean, reduce the number of rows to 1 and then increase the number of rows to 10000 to see a change in the time taken. t remains constant for each value.

Goodbye.


SoggyP(Posted 2006) [#5]
Hello.

Take a look at visits and tiles in the following:


And try changing the number of rows from 100 to 1000 to 10000.

Goodbye.


hub(Posted 2006) [#6]
The difficulty is that every inner loop you're iterating through all the tiles 24 times, regardless of if they're on screen or not, and then iterating through them once again 24 times to display them (again regardless of if they're on screen or not). That's a lot of tiles.
agree with this it's my pb !


create images instead of drawing rects.


i use images into my game




The difficulty is that every inner loop you're iterating through all the tiles 24 times, regardless of if they're on screen or not, and then iterating through them once again 24 times to display them

note that i separate logic and drawing into the game to apply delta time.


- hold the tiles in an array, not a list;
- apply a global decal offset to the values;

good idea.

Many thanks for your idea, is somebody know how to avoid this for-next loops ??? Finally i'm searching a better code structure ! My first idea produce bad code !!!


SoggyP(Posted 2006) [#7]
Hello.

Ok, what is the sort function there for?

Goodbye.


hub(Posted 2006) [#8]
Ok, what is the sort function there for?
oups... for nothing in this case. i use it into my game as the tiles are not yet sorted when you create them into the editor.




tonyg(Posted 2006) [#9]
Put the Tbricks in an array with dimensions the width/height of your 'wall'. Then keep track of screen_offset and draw from that index to the number of bricks that can fit on a screen.


hub(Posted 2006) [#10]
Put the Tbricks in an array with dimensions the width/height of your 'wall'. Then keep track of screen_offset and draw from that index to the number of bricks that can fit on a screen.

no sure to understand your idea. Is it this :
use an one dimension array, determine an index for each tile ? i've thinking about this idea to direct access to a tile. The problem is that produce a huge array...
32 x 24 x 1000. with a lot of null values (have not a tile for each array cell).

Not that the previous editor screen is a test, there are no 'walls' into the game. See the ingame screenshoot picture.


tonyg(Posted 2006) [#11]
I was responding to the code you posted but I would still consider a two dimension array even with the null values.
I might not be thinking straight by why would it be 32*24*1000? If there are 1000 rows and each row contains 32 bricks isn't that array[32,1000]?
Somebody else might be able to say whether a tmap might help with your tilelist indexed against it's x position (can you have duplicate indexes in a tmap?) converted to a string.
You can then use your screen_pos (x value for topleft of your world map) and compare it against the indexes drawing anything that fits between screen_pos and screen_pos+max_number_per_screen.
I haven't really used tmaps but it might be possible.
This might be a bit too much for the Beginner's forum and I'm sure many people have written games which resemble you screenshots so there could be a simple answer.


hub(Posted 2006) [#12]
If there are 1000 rows and each row contains 32 bricks isn't that array[32,1000]?

oups, yes you're right. Sorry for the mystake.

This might be a bit too much for the Beginner's forum and I'm sure many people have written games which resemble you screenshots so there could be a simple answer

hope they also read this forum !


hub(Posted 2006) [#13]
Thanks, time to me to code something with your ideas... i'll post my results here.


hub(Posted 2006) [#14]
First attempt to code with arrays :




tonyg(Posted 2006) [#15]
Is this
		For Local y=0 To MAX_TILEMAP_HEIGHT - 1

still looping through everything rather than what's on-screen?


hub(Posted 2006) [#16]
yes, this is a very basic scrolling code !!!


hub(Posted 2006) [#17]
update !



Jesse(Posted 2006) [#18]
I suggest you do a flip(0) with the first flip to speed up the calculations and map creation.

I am working on a game using tile scrolling of size 32 x 32 is a random map generator if you want to try it out is here:
http://www.gamedev.net/community/gds/viewentry.asp?projectid=427815


hub(Posted 2006) [#19]
good suggestion jesse. Thanks. Good game too.