Hi, I couldn’t find the answer to this and I’m hoping someone knows off the top of their head.
I heard that pointers are kind of slow on iPhone… but I don’t know if passing parameters would be faster (unless I suppose they are used many times).
I want to know if it is more efficient (in iPhone development) to pass parameters from a object to a function… or to reference the object’s variables through a pointer from the method.
Also I want to know whether doing a radius check, which would allow for fewer calculations, would be faster than doing a nested if with single dimensional checks… eg:
Doing a couple single dimension checks first to avoid multiplication 99% of the time:
float xDiff = 0;
float zDiff = 0;
float sqrDist = 0;
float minCollisionDistance = 2;
float minSqrCollisionDistance = 4;
for (int i = 0; i < enemies.Count; i++) {
xDiff = enemies[i].x - x;
if (Mathf.Abs(xDiff) < minCollisionDistance) {
zDiff = enemies[i].z - z;
if (Mathf.Abs(zDiff) < minCollisionDistance) {
sqrDist = xDiff * xDiff + zDiff * zDiff;
if (sqrDist < minSqrCollisionDistance) {
PerformSomething();
}
}
}
}
or would this be faster to cut out the extra checks:
float xDiff = 0;
float zDiff = 0;
float sqrDist = 0;
for (int i = 0; i < enemies.Count; i++) {
xDiff = enemies[i].x - x;
zDiff = enemies[i].z - z;
sqrDist = xDiff * xDiff + zDiff * zDiff;
if (sqrDist < minSqrCollisionDistance) {
PerformSomething();
}
}
The first one will 90 percent of the time not need to check further than the first check ( if (Mathf.Abs(xDiff) < minCollisionDistance) )… but if the Mathf.Abs is about the same speed as the multiplications in the second one then it would be less efficient.
Also… should I be iterating through a List using a “(for int i = 0 ; i < list.Count; i++)” or would it be better to use a iterator.
Also, and maybe this is what I should have asked, is there anywhere good documentation to scripting for the iPhone hardware. I’ve only ever come across bits and pieces.