Quote:Original post by red_sodium
Quote:you should in 99% of the cases never use an if in a time critical situation, so this should never bother you, if you end up with an if in an innerloop you are on deep water anyway, try rethink your algorithm.
That doesn't make any sense. What should be used instead, then?
Sometimes you *have* to check to see if something happens or not, eg,
for( int i = 0; i < objects.size(); i++ ) { if( objects->Collided() ) { return true; }}
Not that I'm actually sugesting you do this but...
bool result = false;for( int i = 0; i < objects.size(); i++ ) { result |= objects->Collided();}return result;}
Of course this isn't the innermost loop in this case. It's probably in Collided().
Min/max clipping without if's:
inline int clipMinMax(int value, const int minVal = 0, const int maxVal = 255) { int bLess = value < minVal, bGreater = value > maxVal; return (maxVal & (-(int)bGreater)) | ( ((minVal & (-(int)bLess)) | (value & (-(int)!bLess)) ) & (-(int)!bGreater));}
You get the idea. Just please don't do this kind of stuff until you KNOW it's going to make the biggest speed increase!