[quote=“Zeldar,post:3,topic:56440”]
The purpose of that line is to store two integers in one long.
Imagine the integers x and y as binary strings. An int is 32 bits in length, and a long is 64 bits in length, which means we can pack two ints into one long. If the value of x is 127, in binary it looks like this:
00000000000000000000000001111111
When we cast it to a long, it looks like this:
0000000000000000000000000000000000000000000000000000000001111111
We’re using a longer string to represent the same number, which is the reason for all the new zeroes on the left. Then we shift it 32 places – the length of an int – to the left:
0000000000000000000000000111111100000000000000000000000000000000
This is the meaning of “x << 32.” For our purposes, it gives us room to store a second integer on the right side.
That leaves the integer y. Let’s say its value is 72. In binary, it looks like this:
00000000000000000000000001001000
The operator | is a bitwise “or,” which means that every bit in the result has a value of 1 where at least one of the operands has a value of 1. This might be easier to understand in table form:
[tr][td]A[/td][td]B[/td][td]A | B[/td][/tr]
[tr][td]1[/td][td]1[/td][td]1[/td][/tr]
[tr][td]1[/td][td]0[/td][td]1[/td][/tr]
[tr][td]0[/td][td]1[/td][td]1[/td][/tr]
[tr][td]0[/td][td]0[/td][td]0[/td][/tr]
Since “(long)x << 32” produces a long, for the purposes of the “or” operation, y gets promoted to a long as well. Look at the strings next to each other:
0000000000000000000000000111111100000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000001001000
The result of the or operator looks like this:
0000000000000000000000000111111100000000000000000000000001001000
You can see that it’s almost like we “dropped” one number into the other, where we made room for it. What actually happened is that every 1 in the left-hand operand (x << 32) corresponded to a 0 in the right-hand operand (y), and every 1 in the right-hand operand corresponded to a 0 in the left-hand operand as well, thereby putting the two original 32-bit patterns side by side.
Hopefully that explanation makes at least some sense.
As for the ideal data structure here, a HashMap won’t work if you can have multiple entities per cell.
if(ScreenIngame.getEntity(this.getPbX(), this.getPbY(), EntityFire.class) != null && this.isDestructible())
{
this.deleteEntity();
}
Instead of running the above check for every entity every frame, do it when a new entity enters a cell. When you spawn fire, have it check if it overlaps with a destructible block. When you spawn a destructible block, have it check for fire.