Does all the code that you put into your games affect the speed? I mean: is 100 lines of code faster than 200?
Printable View
Does all the code that you put into your games affect the speed? I mean: is 100 lines of code faster than 200?
it probably would somewhat.. but I don't think you'd notice it. I always make sure I have "Only One action when event loops" where only 1 action is needed, which I'm sure would speed up everything a bit. I'd say it depends alot on whether it's actually processing all 200 of those events. But again, on faster systems (as in more than 1Ghz), it'd be barely noticeable.
depends on what happens in those 100 or 200 events.. I'd guess that more would happen in 200 events...
200 events is really small. You can go up to 700/800 without noticable speed loss. With a good machine of course.
Francois, is the order of events, both in the overall list, and the ordering of conditions in a single event, important?
For example, if I had an action like:
If object is overlapping something
If 1 + 1 = 3
Would it be more efficient to reorder that event, so the 1+1=3 (ie, a less complicated check) will cause the code to not be run faster?
IE, short circuiting
As a general rule, you should put whatever is more likely to fail first, so that less conditions are run. The only exception is "true events" which don't work properly or at all unless they are the first condition in a line, "On loop" "On click" "On collision" etc.
Yes, you usually put the true events first. In build 243, true events will be printed in RED, so that you can see exactly which one is a true of fake event.
In your example, I think that the 1+1=3 would be faster than the collision detection, depending on the number of objects. The collision detection has to go through all the objects list to find out which is colliding, and it has to explore the objects pixel by pixel when the rectangle are interconnected.
A little off topic but a question for Francois: in the collision detection, does it simply go through all pixels in the intersecting rectangles or do you optimize it by accessing semi-random pixels in the rectangle? (like every 5x5 pixel is checked first) (that way the probability that a pixel will be colliding is bigger)
It goes through all pixels in the intersecting rectangles until it detects a collision, but it tests up to 32 pixels at the same time (as there is one but per pixel in the collision mask), so it's very quick.
Yves.