2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-10-23 01:18:44 +04:00
|
|
|
|
|
|
|
#include "database.h"
|
2013-09-10 15:49:43 +02:00
|
|
|
#include "irrlichttypes.h"
|
2012-10-23 01:18:44 +04:00
|
|
|
|
2014-04-22 12:52:48 -04:00
|
|
|
|
|
|
|
/****************
|
2025-02-25 23:11:43 +01:00
|
|
|
* The position encoding is a bit messed up because negative
|
|
|
|
* values were not taken into account.
|
|
|
|
* But this also maps 0,0,0 to 0, which is nice, and we mostly
|
|
|
|
* need forward encoding in Luanti.
|
2014-04-22 12:52:48 -04:00
|
|
|
*/
|
2017-04-23 14:35:08 +02:00
|
|
|
s64 MapDatabase::getBlockAsInteger(const v3s16 &pos)
|
2014-04-15 16:07:53 -04:00
|
|
|
{
|
2025-02-25 23:11:43 +01:00
|
|
|
return ((s64) pos.Z << 24) + ((s64) pos.Y << 12) + pos.X;
|
2012-10-23 01:18:44 +04:00
|
|
|
}
|
|
|
|
|
2014-04-22 12:52:48 -04:00
|
|
|
|
2017-04-23 14:35:08 +02:00
|
|
|
v3s16 MapDatabase::getIntegerAsBlock(s64 i)
|
2014-04-15 16:07:53 -04:00
|
|
|
{
|
2025-02-25 23:11:43 +01:00
|
|
|
// Offset so that all negative coordinates become non-negative
|
|
|
|
i = i + 0x800800800;
|
|
|
|
// Which is now easier to decode using simple bit masks:
|
|
|
|
return { (s16)( (i & 0xFFF) - 0x800),
|
|
|
|
(s16)(((i >> 12) & 0xFFF) - 0x800),
|
|
|
|
(s16)(((i >> 24) & 0xFFF) - 0x800) };
|
2012-10-23 01:18:44 +04:00
|
|
|
}
|