Lists and powers of 2

BlitzMax Forums/BlitzMax Beginners Area/Lists and powers of 2

Yrkoon57(Posted 2009) [#1]
The code below basically is from a german tutorial (I think) with the added "tweak" by me that I remove the "tanks" that go offscreen from the list, originally in order to speed up things.
This all works fine, but what can be easily observed is that the speed does not increase gradually, but in distinctive jumps (which only become obvious when the number of tanks is higher than 32).

But why is this ?
I see distinctive Jumps when the object number displayed falls below 1024, 512, 256, 128 (after that, it becomes too fast for me to detect altered speeds)




Global Number_of_Tanks  =  2048

Type Tank 
   Field  X#
   Field  Y# 
   Field  Dir% 
   Field  Armor%     = 100 
   Field  Speed#     = 2.8
   Field  Size%      = 25 
   Global TankNumber = 0 
End Type 

Global x = 1024
Global y =  768
SeedRnd MilliSecs()
Graphics x, y,32,60,1 
Global TankList:TList  =  CreateList( )
For Nr  =  1 To Number_of_Tanks   
   Local NewTank:Tank     
   NewTank  =  New Tank 
   NewTank.Armor  =  Rand( 1, 5 ) * 10 
   NewTank.X      =  Rand( 5, x ) ; 
   NewTank.Y      =  Rand( 5, y )

   NewTank.Dir    =  Rand( 0, 360 ) 
   ListAddLast TankList, NewTank  
   Tank.TankNumber:+ 1  
Next    

While Not KeyDown( Key_Escape ) 
    
   For T:Tank  =  EachIn TankList   
       c = CountList(tanklist) 
       If c = 0
          Exit
       EndIf 
       DrawRect( T.X, T.Y, T.Size, T.Size ) 
       DrawText "Number of Tanks : " + c,  20, 20 
       T.X:+ T.Speed * Cos( T.Dir ) *2
       T.Y:+ T.Speed * Sin( T.Dir )  
       If (     T.X > X ) 'And ( ( t.y > y ) Or ( t.y < 0 ) )
          RemoveLink( ListFindLink( Tanklist, t ) )
        ElseIf  T.x < 0'  And ( t.y > y Or t.y < 0 )
          RemoveLink( ListFindLink( Tanklist, t ) )
       ElseIf ( T.Y > Y ) 'And ( ( t.y > y ) Or ( t.y < 0 ) )
           RemoveLink( ListFindLink( Tanklist, t ) )
       ElseIf   T.Y < 0'  And ( t.y >y Or t.y <0 )
          RemoveLink( ListFindLink( Tanklist, t ) )
       EndIf 
   Next 
    
   Flip   ; 
   Cls 
   If c = 0
      Exit
   EndIf 
Wend 



Zeke(Posted 2009) [#2]
DrawText is bottleneck...

remove DrawText "Number of Tanks : " + c, 20, 20
and add that after Next:
DrawText "Number of Tanks : " + tanklist.count() , 20 , 20

Use bitmapfonts.

Never use DrawText in loops...


Yrkoon57(Posted 2009) [#3]
Ah.... thanx, Zeke.

>Never use DrawText in loops...
Should have thought of that myself - from a general performance viewpoint.
Yet it is still a mystery to me why the speed increase wasn't smooth because of that condition I provoked.
Nevertheless, thx again.
Y.