RenderLists

BlitzMax Forums/BlitzMax Beginners Area/RenderLists

Ant(Posted 2006) [#1]
Hi, I was thinking about how to tidy up my code and give me more control (more easily) over what is drawn. I remember from programming the Net Yaroze, that when you wanted to draw an image, you added it to a list which was processed and drawn at the end of the main game loop (as opposed to numerous drawing commands throughout hte code). Does anyone do anything similar using lists in BMax?


FlameDuck(Posted 2006) [#2]
Does anyone do anything similar using lists in BMax?
Yup. Cool thing is you can even do Z-ordering by overriding the compare method and just calling myList.sort() - provided you don't have too many objects in the list.


Ant(Posted 2006) [#3]
Nice!


FlameDuck(Posted 2006) [#4]
Just be aware that TList.sort() is implemented using bubble sort, which has a quadratic time complexity, which can be a significant factor with lots of elements.

I have some example code too, that's pretty messy (but working) that I can send you if you want.


Ant(Posted 2006) [#5]
I'd appreciate it if you could


CoderLaureate(Posted 2006) [#6]
I did the same for my sprite engine, only I created a new Class of my own that inherrited the TList functionality. Then I added my own properties and methods to it.

OOP IS AWESOME!!!


VP(Posted 2006) [#7]
For a fairly tidy main loop, take a look at the source for GridWars (Google for it, you'll find it at yakyak.org). UpdateAll() and RenderAll() are very tidy, enabled by using Lists.

The enemy Types could have been tidier by using an Abstract Type as a parent, but other than that it's a good tutorial :)


Yan(Posted 2006) [#8]
Here's some code I played around with when I first got BMax.

Bear in mind that I didn't really have a clue what I was doing as I'd never used an OO language before bmax.

It's pretty clunky but I quite like the idea of having layers.




Cajun17(Posted 2006) [#9]
I created a pretty solid z-ordering render list system in c++ for doing some iso stuff. One thing I did to get a big speed boost was to store things that changed their z/depth/layer separate from things that didn't. Things like terrain tiles, background images, HUDs don't need to be sorted if they're all static.

Of course if nothing changes their z then there's no point to even worry about it.


FlameDuck(Posted 2006) [#10]
Sorry I've taken so long to reply, I've been in transit. Unfortunately I left my real source code in Denmark, so here is a small example I created just for you (kinda).




Ant(Posted 2006) [#11]
Fantastic stuff - you are too kind ;-)


CoderLaureate(Posted 2006) [#12]
Here's just a snippet of some code from one of my programs. I use OOP to create a new version of the TList class. I have more methods than just "Render", but I wanted to just show you the basics...

Type BallGroup Extends TList
     Method Render(WithCollisions:Int = True)
          ForEach Local Ball:BallSprite in Self
               If Ball.Visible Then
                    Ball.Render(WithCollisions)
               End If
          Next
     End Method
End Type

Local Balls:BallGroup = new BallGroup
For Local i:Int = 1 to 10
     Balls.AddLast(new Ball)
Next

While Not KeyHit(KEY_ESCAPE)
     Cls
     Balls.Render(False)
     Flip
Wend


-j9t