Auto compiler optimalisation?
BlitzMax Forums/BlitzMax Beginners Area/Auto compiler optimalisation?
| ||
I'm making a Space Invaders Clone. Yes, thank you, it's very original, i know :) Im my Update() i restrict the player (the image of the player) to remain inside the screen. Now because i dont want half the ship to be offscreen i make a margin on x with the width of the player image. What i'm wondering is, is every call of Update() going to recalculate the width of the image and if so, should i define it once as a constant variable in the constructor of the player to save cpu-time or does the compiler optimize these kind of recuring calculations for me? Type TPlayer Extends TGameObject Function Create:TPlayer(px:Int, py:Int, pspeed:Int, pimg:String) Local P:TPlayer = New TPlayer P.x = px P.y = py P.speed = pspeed P.img = LoadImage(pimg) ListAddLast GameObjectList, P Return P End Function Method Update() If Self.x < ImageWidth(Self.img)/2 ; x = ImageWidth(Self.img)/2 If Self.x > ScreenWidth - (ImageWidth(Self.img)/2); x = ScreenWidth - (ImageWidth(Self.img)/2) End Method End Type |
| ||
As per the source :Function ImageWidth( image:TImage ) Return image.width End Function where image.width is defined as follows : Type TImage Extends TData Field width,height,flags .... So, no. It won't recalculate. |
| ||
Okay, so when the image is loaded BlitzMax calculates the image width and height once into it's own internal variable and i'm just asking for that variable every time. It doesn't actually count the pixels every time. Thanx Brucey |
| ||
Right, it doesn't even count pixels the first time it loads the image, it gets the dimensions which are stored in the file already as part of the file-loader. There is no pixel counting, but it would still be productive to define Local variables holding the dimensions rather than using function calls each time. |
| ||
Although a function call time is pretty insignificant, I would imagine ? |
| ||
yes they are... I wouldn't worry about it... that will not be where you need to optimise. |