So, I have a main loop that is pretty heavy. In it, we have movement, collision and magnetism for each object, and my game can get some hundred objects on the screen at the same time.
It doesn't produce much slowdown really, but I think lower end systems wouldn't be able to run this so well. So, at the very least, I'm optimizing the loop a lot.
Now, I have some optimizing questions:
Question 1:
Methods and functions can be very clean and nice, but do they use extra resources complared to just having the code directly in the loop?
For example, to do collisions between objects, the distance between objects are constantly checked. I have a function that returns the distance between two objects, and it gets used several hundred times a second at it's worst. Would putting the distance code directly into the loop help optimize some?
Question 2:
When I refer to objects, does ever step within it cause a slight extra resource use?
For example, let's say that I do this:
would this be faster or slower?:
Since, although we use two extra local variables, we avoid accessing values though so many objects.
Question3:
If a draw command is called with an X and Y position that is outside the screen (like -500,-200), will it be done or ignored?
It doesn't produce much slowdown really, but I think lower end systems wouldn't be able to run this so well. So, at the very least, I'm optimizing the loop a lot.
Now, I have some optimizing questions:
Question 1:
Methods and functions can be very clean and nice, but do they use extra resources complared to just having the code directly in the loop?
For example, to do collisions between objects, the distance between objects are constantly checked. I have a function that returns the distance between two objects, and it gets used several hundred times a second at it's worst. Would putting the distance code directly into the loop help optimize some?
Question 2:
When I refer to objects, does ever step within it cause a slight extra resource use?
For example, let's say that I do this:
Object1.XPosition = Self.ParentUniverse.Player.Location1X Object1.YPosition = Self.ParentUniverse.Player.Location1Y Object2.XPosition = Self.ParentUniverse.Player.Location1X Object2.YPosition = Self.ParentUniverse.Player.Location1Y
would this be faster or slower?:
Local temp1 = Self.ParentUniverse.Player.Location1X Local temp2 = Self.ParentUniverse.Player.Location1X Object1.XPosition = temp1 Object1.YPosition = temp2 Object2.XPosition = temp1 Object2.YPosition = temp2
Since, although we use two extra local variables, we avoid accessing values though so many objects.
Question3:
If a draw command is called with an X and Y position that is outside the screen (like -500,-200), will it be done or ignored?