I just implemented a portal system into my engine and came across an important design aspect that affects any complex BlitzMax program that uses lists.
I was wondering why my portal routine took 0 msecs in a small scene, and 30-60 msecs in a large scene with the same number of portals. I finally isolated the problem in a part of the code that freed a temporary object that had been created. The slowdown was caused entirely by the tlist.remove() command!
The tlist in question had about 600 items in the larger map. I guessed that the routine probably sorts through the list from start to finish, so I changed the code to add objects to the front of the tList, using tlist.addfirst() instead of tlist.addlast(). My portal routine sped up from 30-60 msecs to 0-1.
I think a good general rule when adding objects to a tlist is to use the tlist.addfirst() method. Your static objects will gradually sort themselves towards the back, while your dynamic objects that get created and freed a lot will always be quickly accessible to a tlist.remove() call.
I was wondering why my portal routine took 0 msecs in a small scene, and 30-60 msecs in a large scene with the same number of portals. I finally isolated the problem in a part of the code that freed a temporary object that had been created. The slowdown was caused entirely by the tlist.remove() command!
The tlist in question had about 600 items in the larger map. I guessed that the routine probably sorts through the list from start to finish, so I changed the code to add objects to the front of the tList, using tlist.addfirst() instead of tlist.addlast(). My portal routine sped up from 30-60 msecs to 0-1.
I think a good general rule when adding objects to a tlist is to use the tlist.addfirst() method. Your static objects will gradually sort themselves towards the back, while your dynamic objects that get created and freed a lot will always be quickly accessible to a tlist.remove() call.