Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible improvement for jump function #2

Open
alvidux opened this issue Oct 25, 2014 · 0 comments
Open

Possible improvement for jump function #2

alvidux opened this issue Oct 25, 2014 · 0 comments

Comments

@alvidux
Copy link

alvidux commented Oct 25, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant