Hi all.
I'm really interested in the core of rsps and want to understand the code sources rather then just assume they work.
Now, I'm reading into Regions, I tried to look online but there wasn't many people explaining the inner work of why certain code is there.
I've added javoc documentation to the code below, but I really don't understand:
Code:
/**
* Unsure how to explain this method
*
* @Param x
* @Param y
* @Param height
* @Return
*/
private int getClip(int x, int y, int height) {
int regionAbsX = (id >> 8) * 64;
int regionAbsY = (id & 0xff) * 64;
if (clips[height] == null) {
return 0;
}
return clips[height][x - regionAbsX][y - regionAbsY];
}
Code:
/**
* Checks if the current position is legal
*
* @Param x - current x position
* @Param y - current y position
* @Param height - current height
* @Return
*/
public static int getClipping(int x, int y, int height) {
if (height > 3) {
height = 0;
}
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region r : regions) {
if (r.id() == regionId) {
return r.getClip(x, y, height);
}
}
return 0;
}
From above:
1. why is the x and y coordinates shifted by 3 bits to the right?
2. why is the x and y coordinates after shift divided by 8? and why is x coord the only one shifted 8 bits to the left.
In addition:
Code:
/**
* Checks that the movement is legal.
*
* @Param x - current x position
* @Param y - current y position
* @Param height - current height
* @Param moveTypeX - end x position
* @Param moveTypeY - end y position
* @Return
*/
public static boolean getClipping(int x, int y, int height, int moveTypeX,
int moveTypeY) {
try {
if (height > 3) {
height = 0;
}
int checkX = x + moveTypeX;
int checkY = y + moveTypeY;
if (moveTypeX == -1 && moveTypeY == 0) {
return (getClipping(x, y, height) & 0x1280108) == 0;
} else if (moveTypeX == 1 && moveTypeY == 0) {
return (getClipping(x, y, height) & 0x1280180) == 0;
} else if (moveTypeX == 0 && moveTypeY == -1) {
return (getClipping(x, y, height) & 0x1280102) == 0;
} else if (moveTypeX == 0 && moveTypeY == 1) {
return (getClipping(x, y, height) & 0x1280120) == 0;
} else if (moveTypeX == -1 && moveTypeY == -1) {
return (getClipping(x, y, height) & 0x128010e) == 0
&& (getClipping(checkX - 1, checkY, height) & 0x1280108) == 0
&& (getClipping(checkX - 1, checkY, height) & 0x1280102) == 0;
} else if (moveTypeX == 1 && moveTypeY == -1) {
return (getClipping(x, y, height) & 0x1280183) == 0
&& (getClipping(checkX + 1, checkY, height) & 0x1280180) == 0
&& (getClipping(checkX, checkY - 1, height) & 0x1280102) == 0;
} else if (moveTypeX == -1 && moveTypeY == 1) {
return (getClipping(x, y, height) & 0x1280138) == 0
&& (getClipping(checkX - 1, checkY, height) & 0x1280108) == 0
&& (getClipping(checkX, checkY + 1, height) & 0x1280120) == 0;
} else if (moveTypeX == 1 && moveTypeY == 1) {
return (getClipping(x, y, height) & 0x12801e0) == 0
&& (getClipping(checkX + 1, checkY, height) & 0x1280180) == 0
&& (getClipping(checkX, checkY + 1, height) & 0x1280120) == 0;
} else {
System.out.println("[FATAL ERROR]: At getClipping: " + x + ", "
+ y + ", " + height + ", " + moveTypeX + ", "
+ moveTypeY);
return false;
}
} catch (Exception e) {
return true;
}
}
Now, from above, I understand that this code is only checking 1 tile away from the player. However, I'm unsure what the
Code:
return (getClipping(x, y, height) & 0x1280120) == 0;
is doing. Obviously, it checks the position 1 tile away, but what does the Mask mean here as they are different for each direction? I also understand that it returns false if not 0 etc.
I'm looking for a explanation of what is occurring exactly here, I'm still very new to the rsps scene but I like to learn and understand. Thanks