Skip to content

Possible improvement for jump function #2

@alvidux

Description

@alvidux

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);
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions