I’ve never previously worried about collision performance, however recently I’ve become picky about it.
If I have about 500 objects, all doing collision checks it is quit costly.
My frame rate may be alright on an A63 3000+ OC’d, however not everyone has an overclocked high end CPU.
This is where the trouble comes in.
Basically if the method returns (NONE, NONE), it detect no collision and nothing further is done.
Is my code in any way optimal as a collision routine?
public Compass[] directionOfCollision(Entity entity)
{
Compass[] direction = new Compass[] {Compass.NONE, Compass.NONE}; //Compass is an enum
float
entXMin = entity.bounds.x,
entYMin = entity.bounds.y,
entXMax = entity.bounds.x + entity.bounds.width,
entYMax = entity.bounds.y - entity.bounds.height;
float
xMin = bounds.x,
yMin = bounds.y,
xMax = bounds.x + bounds.width,
yMax = bounds.y - bounds.height;
if(entXMin >= xMin)
direction[0] = Compass.WEST;
else if(entXMax <= xMax)
direction[0] = Compass.EAST;
if(entYMin <= yMin)
direction[1] = Compass.NORTH;
else if(entYMax >= yMax)
direction[1] = Compass.SOUTH;
return direction;
}