mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
update documentation
This commit is contained in:
parent
1f3cf59c7f
commit
8ac7c451e1
1 changed files with 30 additions and 27 deletions
|
@ -298,41 +298,44 @@ Before 5.12.0 it looked like this:
|
||||||
CREATE TABLE `blocks` (`pos` INT NOT NULL PRIMARY KEY, `data` BLOB);
|
CREATE TABLE `blocks` (`pos` INT NOT NULL PRIMARY KEY, `data` BLOB);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Position Hashing
|
## Position Encoding
|
||||||
|
|
||||||
Applies to the pre-5.12.0 schema:
|
Applies to the pre-5.12.0 schema:
|
||||||
|
|
||||||
`pos` (a node position hash) is created from the three coordinates of a
|
`pos` (a node position encoding) is created from the three coordinates of a
|
||||||
`MapBlock` using this algorithm, defined here in Python:
|
`MapBlock` using the following simple equation:
|
||||||
|
|
||||||
```python
|
```C
|
||||||
def getBlockAsInteger(p):
|
pos = (z << 24) + (y << 12) + x;
|
||||||
return int64(p[2]*16777216 + p[1]*4096 + p[0])
|
```
|
||||||
|
or, equivalently, `pos = (z * 0x1000000) + (y * 0x1000) + x`.
|
||||||
|
|
||||||
def int64(u):
|
A position can be decoded using:
|
||||||
while u >= 2**63:
|
|
||||||
u -= 2**64
|
```C
|
||||||
while u <= -2**63:
|
pos = pos + 0x800800800;
|
||||||
u += 2**64
|
x = (pos & 0xFFF) - 0x800;
|
||||||
return u
|
y = ((pos >> 12) & 0xFFF) - 0x800;
|
||||||
|
z = ((pos >> 24) & 0xFFF) - 0x800;
|
||||||
```
|
```
|
||||||
|
|
||||||
It can be converted the other way by using this code:
|
Positions are sequential along the x axis (as easily seen from the position equation above).
|
||||||
|
It is possible to retrieve all blocks from an interval using the following SQL statement:
|
||||||
|
|
||||||
```python
|
```sql
|
||||||
def getIntegerAsBlock(i):
|
SELECT
|
||||||
x = unsignedToSigned(i % 4096, 2048)
|
`pos`,
|
||||||
i = int((i - x) / 4096)
|
`data`,
|
||||||
y = unsignedToSigned(i % 4096, 2048)
|
( (`pos` + 0x800800800) & 0xFFF) - 0x800 as x,
|
||||||
i = int((i - y) / 4096)
|
(((`pos` + 0x800800800) >> 12) & 0xFFF) - 0x800 as y,
|
||||||
z = unsignedToSigned(i % 4096, 2048)
|
(((`pos` + 0x800800800) >> 24) & 0xFFF) - 0x800 as z
|
||||||
return x,y,z
|
FROM `blocks` WHERE
|
||||||
|
( (`pos` + 0x800800800) & 0xFFF) - 0x800 >= ? AND -- minx
|
||||||
def unsignedToSigned(i, max_positive):
|
( (`pos` + 0x800800800) & 0xFFF) - 0x800 <= ? AND -- maxx
|
||||||
if i < max_positive:
|
(((`pos` + 0x800800800) >> 12) & 0xFFF) - 0x800 >= ? AND -- miny
|
||||||
return i
|
(((`pos` + 0x800800800) >> 12) & 0xFFF) - 0x800 <= ? AND -- maxy
|
||||||
else:
|
`pos` >= (? << 24) - 0x800800 AND -- minz
|
||||||
return i - 2*max_positive
|
`pos` <= (? << 24) + 0x7FF7FF; -- maxz
|
||||||
```
|
```
|
||||||
|
|
||||||
## Blob
|
## Blob
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue