Optimizing Code

Blitz3D Forums/Blitz3D Beginners Area/Optimizing Code

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You can optimise to a certain extent. Elminate any functions that don't need to be checked. For instance:
playermoved=ProcessPlayerInput()
  ;if player moved, return 1, else return 0
enemymoved=ProcessAIResponse()
  ;if enemy moved, return 1, else return 0
If NumBullets > 0 then UpdateBullets()    ;only update bullets if there are actually some there
If PlayerMoved then UpdatePlayer()    ;only update player entities if player moved.
If EnemyMoved then UpdateEnemies()    ;only update enemy entities if they actually moved.
If (numbullets+playermoved+enemymoved) > 0 then
    CheckCollisions()
    UpdateScore()
    End If
       ;only update the score if someone moved or some 
bullets hit something and earned some points. And more 
importantly, only checks collisions if something actually 
happened.

Most of that won't really save you CPU time, but its just a hint to show you how you can skip unnecesary operations. Most time consuming is checking collisions and refreshing all the entity positions if they don't need to be done. Why check if the player collided with any one of 300 (or whatever) entities, if the player didn't move, the enemies didn't move, and there are no bullets?

This example will only save you a couple of hundredths of a second. Its not an answer - more a point in the right direction. :) Most importantly - if nothing in the scene has changed, DON'T UPDATEWORLD. Just RENDERWORLD. You'll save some more cycles there. :)

+BlackD