cJumpPointSearch icon indicating copy to clipboard operation
cJumpPointSearch copied to clipboard

Possible improvement for jump function

Open alvidux opened this issue 11 years ago • 0 comments

Possible improvement for jump function. Limits: x,y max values 0-32767 (0x7FFF)

How about instead of allocating memory every time you jump: int *Jump(...) { return int *i = (int *) malloc(2 * sizeof(int)); }

you could replace it with bit operations, and return int number instead (NULL will be equal to -1):

define _xy(x, y) ((x) | ((y) << 16))

define _xyGetX(i) ((i) & 0xFFFF)

define _xyGetY(i) ((i) >> 16)

int Jump(...) { if(!IsWalkableAt(x, y)) return -1; ... return _xy(x, y); ... }

void IdentifySuccessors(...) { ... int jumpPoint = Jump(...); if(jumpPoint == -1) continue; short jumpPointX = _xyGetX(jumpPoint); short jumpPointY = _xyGetY(jumpPoint); ... }

alvidux avatar Oct 25 '14 08:10 alvidux