I am writing in C++ for a low-spec device (~3MB RAM, ~70MHz CPU) and I am wondering which will run more efficiently (And by how much). This is a simplified segment of code that will run 120-600 times a second:
void checkCollisions(int x, int y)
{
int p1x = x, p1y = y+2;
int p2x = x, p2y = y+3;
int p3x = x+3, p3y = y+3;
// And so on...
if (wallAt(p1x-1, p1y) || wallAt(p2x-1, p2y))
setCollision(LEFT, true);
if (wallAt(p1x, p1y) || wallAt(p4x, p4y) || wallAt(p5x, p5y))
inGround = true;
else
inGround = false;
// And so on...
}
Or replacing the integers with their definitions:
void checkCollisionsAlt(int x, int y)
{
if (wallAt(x-1, y+2) || wallAt(x-1, y+3))
setCollision(LEFT, true);
if (wallAt(x, y+2) || wallAt(x+3, y) || wallAt(x+2, y))
inGround = true;
else
inGround = false;
// And so on...
}
Here's a diagram of the example:
The first one is more understandable, but I would expect uses more memory. How much of a difference does it make?