amulet-core 2.0a8__cp311-cp311-win_amd64.whl → 2.0.1a2.post250529084738__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of amulet-core might be problematic. Click here for more details.
- amulet/core/__init__.py +36 -0
- amulet/core/__pyinstaller/hook-amulet.core.py +4 -0
- amulet/core/_amulet_core.cp311-win_amd64.pyd +0 -0
- amulet/core/_amulet_core.pyi +7 -0
- amulet/{_version.py → core/_version.py} +3 -3
- amulet/core/amulet_core.dll +0 -0
- amulet/core/amulet_core.lib +0 -0
- amulet/core/amulet_coreConfig.cmake +18 -0
- amulet/{biome.pyi → core/biome/__init__.pyi} +3 -3
- amulet/core/biome/biome.hpp +53 -0
- amulet/{block.pyi → core/block/__init__.pyi} +25 -26
- amulet/core/block/block.hpp +156 -0
- amulet/{block_entity.pyi → core/block_entity/__init__.pyi} +7 -7
- amulet/core/block_entity/block_entity.hpp +84 -0
- amulet/{errors.py → core/chunk/__init__.pyi} +37 -33
- amulet/core/chunk/chunk.hpp +126 -0
- amulet/core/chunk/component/__init__.pyi +18 -0
- amulet/core/chunk/component/biome_3d_component.hpp +96 -0
- amulet/core/chunk/component/block_component.hpp +101 -0
- amulet/core/chunk/component/block_component.pyi +28 -0
- amulet/core/chunk/component/block_entity_component.hpp +119 -0
- amulet/core/chunk/component/section_array_map.hpp +129 -0
- amulet/{chunk_components.pyi → core/chunk/component/section_array_map.pyi} +4 -24
- amulet/core/dll.hpp +21 -0
- amulet/core/entity/__init__.pyi +105 -0
- amulet/core/entity/entity.hpp +100 -0
- amulet/{palette → core/palette}/__init__.pyi +2 -2
- amulet/core/palette/biome_palette.hpp +65 -0
- amulet/{palette → core/palette}/biome_palette.pyi +8 -8
- amulet/core/palette/block_palette.hpp +71 -0
- amulet/{palette → core/palette}/block_palette.pyi +12 -10
- amulet/core/selection/__init__.pyi +8 -0
- amulet/core/selection/box.hpp +86 -0
- amulet/core/selection/box.pyi +215 -0
- amulet/core/selection/group.hpp +80 -0
- amulet/core/selection/group.pyi +213 -0
- amulet/{version.pyi → core/version/__init__.pyi} +58 -10
- amulet/core/version/version.hpp +204 -0
- {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a2.post250529084738.dist-info}/METADATA +25 -20
- amulet_core-2.0.1a2.post250529084738.dist-info/RECORD +45 -0
- {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a2.post250529084738.dist-info}/WHEEL +1 -1
- amulet_core-2.0.1a2.post250529084738.dist-info/entry_points.txt +2 -0
- amulet/__init__.cp311-win_amd64.pyd +0 -0
- amulet/__init__.py.cpp +0 -45
- amulet/__init__.pyi +0 -30
- amulet/__pyinstaller/hook-amulet.py +0 -4
- amulet/_init.py +0 -26
- amulet/biome.cpp +0 -36
- amulet/biome.hpp +0 -43
- amulet/biome.py.cpp +0 -122
- amulet/block.cpp +0 -435
- amulet/block.hpp +0 -119
- amulet/block.py.cpp +0 -377
- amulet/block_entity.cpp +0 -12
- amulet/block_entity.hpp +0 -56
- amulet/block_entity.py.cpp +0 -115
- amulet/chunk.cpp +0 -16
- amulet/chunk.hpp +0 -100
- amulet/chunk.py.cpp +0 -80
- amulet/chunk.pyi +0 -28
- amulet/chunk_components/biome_3d_component.cpp +0 -5
- amulet/chunk_components/biome_3d_component.hpp +0 -79
- amulet/chunk_components/block_component.cpp +0 -41
- amulet/chunk_components/block_component.hpp +0 -88
- amulet/chunk_components/block_entity_component.cpp +0 -5
- amulet/chunk_components/block_entity_component.hpp +0 -147
- amulet/chunk_components/section_array_map.cpp +0 -129
- amulet/chunk_components/section_array_map.hpp +0 -147
- amulet/collections/eq.py.hpp +0 -37
- amulet/collections/hash.py.hpp +0 -27
- amulet/collections/holder.py.hpp +0 -37
- amulet/collections/iterator.py.hpp +0 -80
- amulet/collections/mapping.py.hpp +0 -199
- amulet/collections/mutable_mapping.py.hpp +0 -226
- amulet/collections/sequence.py.hpp +0 -163
- amulet/collections.pyi +0 -40
- amulet/data_types.py +0 -29
- amulet/entity.py +0 -182
- amulet/game/__init__.py +0 -7
- amulet/game/_game.py +0 -152
- amulet/game/_universal/__init__.py +0 -1
- amulet/game/_universal/_biome.py +0 -17
- amulet/game/_universal/_block.py +0 -47
- amulet/game/_universal/_version.py +0 -68
- amulet/game/abc/__init__.py +0 -22
- amulet/game/abc/_block_specification.py +0 -150
- amulet/game/abc/biome.py +0 -213
- amulet/game/abc/block.py +0 -331
- amulet/game/abc/game_version_container.py +0 -25
- amulet/game/abc/json_interface.py +0 -27
- amulet/game/abc/version.py +0 -44
- amulet/game/bedrock/__init__.py +0 -1
- amulet/game/bedrock/_biome.py +0 -35
- amulet/game/bedrock/_block.py +0 -42
- amulet/game/bedrock/_version.py +0 -165
- amulet/game/java/__init__.py +0 -2
- amulet/game/java/_biome.py +0 -35
- amulet/game/java/_block.py +0 -60
- amulet/game/java/_version.py +0 -176
- amulet/game/translate/__init__.py +0 -12
- amulet/game/translate/_functions/__init__.py +0 -15
- amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
- amulet/game/translate/_functions/_code_functions/_text.py +0 -553
- amulet/game/translate/_functions/_code_functions/banner_pattern.py +0 -67
- amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +0 -152
- amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +0 -88
- amulet/game/translate/_functions/_code_functions/bedrock_sign.py +0 -152
- amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +0 -16
- amulet/game/translate/_functions/_code_functions/custom_name.py +0 -146
- amulet/game/translate/_functions/_frozen.py +0 -66
- amulet/game/translate/_functions/_state.py +0 -54
- amulet/game/translate/_functions/_typing.py +0 -98
- amulet/game/translate/_functions/abc.py +0 -123
- amulet/game/translate/_functions/carry_nbt.py +0 -160
- amulet/game/translate/_functions/carry_properties.py +0 -80
- amulet/game/translate/_functions/code.py +0 -143
- amulet/game/translate/_functions/map_block_name.py +0 -66
- amulet/game/translate/_functions/map_nbt.py +0 -111
- amulet/game/translate/_functions/map_properties.py +0 -93
- amulet/game/translate/_functions/multiblock.py +0 -112
- amulet/game/translate/_functions/new_block.py +0 -42
- amulet/game/translate/_functions/new_entity.py +0 -43
- amulet/game/translate/_functions/new_nbt.py +0 -206
- amulet/game/translate/_functions/new_properties.py +0 -64
- amulet/game/translate/_functions/sequence.py +0 -51
- amulet/game/translate/_functions/walk_input_nbt.py +0 -331
- amulet/game/translate/_translator.py +0 -433
- amulet/img/__init__.py +0 -10
- amulet/img/missing_no.png +0 -0
- amulet/img/missing_pack.png +0 -0
- amulet/img/missing_world.png +0 -0
- amulet/io/binary_reader.hpp +0 -45
- amulet/io/binary_writer.hpp +0 -30
- amulet/item.py +0 -75
- amulet/level/__init__.pyi +0 -23
- amulet/level/_load.py +0 -100
- amulet/level/abc/__init__.py +0 -12
- amulet/level/abc/_chunk_handle.py +0 -358
- amulet/level/abc/_dimension.py +0 -86
- amulet/level/abc/_history/__init__.py +0 -1
- amulet/level/abc/_history/_cache.py +0 -224
- amulet/level/abc/_history/_history_manager.py +0 -291
- amulet/level/abc/_level/__init__.py +0 -5
- amulet/level/abc/_level/_compactable_level.py +0 -10
- amulet/level/abc/_level/_creatable_level.py +0 -28
- amulet/level/abc/_level/_disk_level.py +0 -17
- amulet/level/abc/_level/_level.py +0 -449
- amulet/level/abc/_level/_loadable_level.py +0 -42
- amulet/level/abc/_player_storage.py +0 -7
- amulet/level/abc/_raw_level.py +0 -187
- amulet/level/abc/_registry.py +0 -40
- amulet/level/java/__init__.pyi +0 -16
- amulet/level/java/_chunk_handle.py +0 -17
- amulet/level/java/_dimension.py +0 -20
- amulet/level/java/_level.py +0 -184
- amulet/level/java/_raw/__init__.pyi +0 -15
- amulet/level/java/_raw/_chunk.pyi +0 -23
- amulet/level/java/_raw/_constant.py +0 -9
- amulet/level/java/_raw/_data_pack/__init__.py +0 -2
- amulet/level/java/_raw/_data_pack/data_pack.py +0 -241
- amulet/level/java/_raw/_data_pack/data_pack_manager.py +0 -77
- amulet/level/java/_raw/_dimension.py +0 -86
- amulet/level/java/_raw/_level.py +0 -507
- amulet/level/java/_raw/_typing.py +0 -3
- amulet/level/java/_raw/java_chunk_decode.cpp +0 -531
- amulet/level/java/_raw/java_chunk_decode.hpp +0 -23
- amulet/level/java/_raw/java_chunk_encode.cpp +0 -25
- amulet/level/java/_raw/java_chunk_encode.hpp +0 -23
- amulet/level/java/anvil/__init__.py +0 -2
- amulet/level/java/anvil/_dimension.py +0 -170
- amulet/level/java/anvil/_region.py +0 -421
- amulet/level/java/anvil/_sector_manager.py +0 -223
- amulet/level/java/chunk.pyi +0 -81
- amulet/level/java/chunk_/_chunk.py +0 -260
- amulet/level/java/chunk_/components/inhabited_time.py +0 -12
- amulet/level/java/chunk_/components/last_update.py +0 -12
- amulet/level/java/chunk_/components/legacy_version.py +0 -12
- amulet/level/java/chunk_/components/light_populated.py +0 -12
- amulet/level/java/chunk_/components/named_height_2d.py +0 -37
- amulet/level/java/chunk_/components/status.py +0 -11
- amulet/level/java/chunk_/components/terrain_populated.py +0 -12
- amulet/level/java/chunk_components/data_version_component.cpp +0 -32
- amulet/level/java/chunk_components/data_version_component.hpp +0 -31
- amulet/level/java/chunk_components/java_raw_chunk_component.cpp +0 -56
- amulet/level/java/chunk_components/java_raw_chunk_component.hpp +0 -45
- amulet/level/java/chunk_components.pyi +0 -22
- amulet/level/java/java_chunk.cpp +0 -170
- amulet/level/java/java_chunk.hpp +0 -141
- amulet/level/java/long_array.hpp +0 -175
- amulet/level/java/long_array.pyi +0 -39
- amulet/level/temporary_level/__init__.py +0 -1
- amulet/level/temporary_level/_level.py +0 -16
- amulet/mesh/__init__.py +0 -0
- amulet/mesh/block/__init__.pyi +0 -301
- amulet/mesh/block/_cube.py +0 -198
- amulet/mesh/block/_missing_block.py +0 -20
- amulet/mesh/block/block_mesh.cpp +0 -107
- amulet/mesh/block/block_mesh.hpp +0 -207
- amulet/mesh/util.py +0 -17
- amulet/palette/biome_palette.hpp +0 -85
- amulet/palette/block_palette.cpp +0 -32
- amulet/palette/block_palette.hpp +0 -93
- amulet/player.py +0 -62
- amulet/pybind11/collections.hpp +0 -118
- amulet/pybind11/numpy.hpp +0 -26
- amulet/pybind11/py_module.hpp +0 -34
- amulet/pybind11/type_hints.hpp +0 -51
- amulet/pybind11/types.hpp +0 -25
- amulet/pybind11/typing.hpp +0 -7
- amulet/resource_pack/__init__.py +0 -63
- amulet/resource_pack/abc/__init__.py +0 -2
- amulet/resource_pack/abc/resource_pack.py +0 -38
- amulet/resource_pack/abc/resource_pack_manager.py +0 -85
- amulet/resource_pack/java/__init__.py +0 -2
- amulet/resource_pack/java/download_resources.py +0 -212
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
- amulet/resource_pack/java/resource_pack.py +0 -44
- amulet/resource_pack/java/resource_pack_manager.py +0 -563
- amulet/resource_pack/unknown_resource_pack.py +0 -10
- amulet/selection/__init__.py +0 -2
- amulet/selection/abstract_selection.py +0 -342
- amulet/selection/box.py +0 -852
- amulet/selection/group.py +0 -481
- amulet/utils/__init__.pyi +0 -23
- amulet/utils/call_spec/__init__.py +0 -24
- amulet/utils/call_spec/_call_spec.py +0 -257
- amulet/utils/cast.py +0 -10
- amulet/utils/comment_json.py +0 -188
- amulet/utils/format_utils.py +0 -41
- amulet/utils/generator.py +0 -18
- amulet/utils/matrix.py +0 -243
- amulet/utils/numpy.hpp +0 -36
- amulet/utils/numpy.pyi +0 -11
- amulet/utils/numpy_helpers.py +0 -19
- amulet/utils/shareable_lock.py +0 -335
- amulet/utils/signal/__init__.py +0 -10
- amulet/utils/signal/_signal.py +0 -228
- amulet/utils/task_manager.py +0 -235
- amulet/utils/typed_property.py +0 -111
- amulet/utils/weakref.py +0 -70
- amulet/utils/world_utils.py +0 -102
- amulet/version.cpp +0 -136
- amulet/version.hpp +0 -142
- amulet/version.py.cpp +0 -281
- amulet_core-2.0a8.dist-info/RECORD +0 -241
- amulet_core-2.0a8.dist-info/entry_points.txt +0 -2
- /amulet/{__pyinstaller → core/__pyinstaller}/__init__.py +0 -0
- /amulet/{py.typed → core/py.typed} +0 -0
- {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a2.post250529084738.dist-info}/top_level.txt +0 -0
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#include <cstdint>
|
|
2
|
-
#include <optional>
|
|
3
|
-
|
|
4
|
-
#include <amulet/io/binary_writer.hpp>
|
|
5
|
-
#include <amulet/io/binary_reader.hpp>
|
|
6
|
-
|
|
7
|
-
#include <amulet/level/java/chunk_components/data_version_component.hpp>
|
|
8
|
-
|
|
9
|
-
namespace Amulet {
|
|
10
|
-
const std::string DataVersionComponent::ComponentID = "Amulet::DataVersionComponent";
|
|
11
|
-
|
|
12
|
-
std::optional<std::string> DataVersionComponent::serialise() const {
|
|
13
|
-
if (_data_version) {
|
|
14
|
-
BinaryWriter writer;
|
|
15
|
-
writer.writeNumeric<std::int64_t>(_data_version.value());
|
|
16
|
-
return writer.getBuffer();
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
return std::nullopt;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
void DataVersionComponent::deserialise(std::optional<std::string> data) {
|
|
23
|
-
if (data) {
|
|
24
|
-
size_t position = 0;
|
|
25
|
-
BinaryReader reader(data.value(), position);
|
|
26
|
-
_data_version = reader.readNumeric<std::int64_t>();
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
_data_version = std::nullopt;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <optional>
|
|
4
|
-
#include <cstdint>
|
|
5
|
-
#include <string>
|
|
6
|
-
#include <stdexcept>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
namespace Amulet {
|
|
10
|
-
class DataVersionComponent {
|
|
11
|
-
private:
|
|
12
|
-
std::optional<std::int64_t> _data_version;
|
|
13
|
-
protected:
|
|
14
|
-
// Null constructor
|
|
15
|
-
DataVersionComponent() {};
|
|
16
|
-
// Default constructor
|
|
17
|
-
void init(std::int64_t data_version) { _data_version = data_version; }
|
|
18
|
-
// Serialise the component data
|
|
19
|
-
std::optional<std::string> serialise() const;
|
|
20
|
-
// Deserialise the component
|
|
21
|
-
void deserialise(std::optional<std::string>);
|
|
22
|
-
public:
|
|
23
|
-
static const std::string ComponentID;
|
|
24
|
-
std::int64_t get_data_version() {
|
|
25
|
-
if (_data_version) {
|
|
26
|
-
return *_data_version;
|
|
27
|
-
}
|
|
28
|
-
throw std::runtime_error("DataVersionComponent has not been loaded.");
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#include <optional>
|
|
2
|
-
#include <stdexcept>
|
|
3
|
-
|
|
4
|
-
#include <amulet/io/binary_writer.hpp>
|
|
5
|
-
#include <amulet/io/binary_reader.hpp>
|
|
6
|
-
|
|
7
|
-
#include <amulet_nbt/nbt_encoding/binary.hpp>
|
|
8
|
-
|
|
9
|
-
#include <amulet/level/java/chunk_components/java_raw_chunk_component.hpp>
|
|
10
|
-
|
|
11
|
-
namespace Amulet {
|
|
12
|
-
const std::string JavaRawChunkComponent::ComponentID = "Amulet::JavaRawChunkComponent";
|
|
13
|
-
|
|
14
|
-
std::optional<std::string> JavaRawChunkComponent::serialise() const {
|
|
15
|
-
if (_raw_data) {
|
|
16
|
-
BinaryWriter writer;
|
|
17
|
-
writer.writeNumeric<std::uint8_t>(1);
|
|
18
|
-
const auto& raw_data = _raw_data.value();
|
|
19
|
-
writer.writeNumeric<std::uint64_t>(raw_data->size());
|
|
20
|
-
for (const auto& [k, v] : *raw_data) {
|
|
21
|
-
writer.writeSizeAndBytes(k);
|
|
22
|
-
AmuletNBT::write_nbt(writer, *v);
|
|
23
|
-
}
|
|
24
|
-
return writer.getBuffer();
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return std::nullopt;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
void JavaRawChunkComponent::deserialise(std::optional<std::string> data) {
|
|
31
|
-
if (data) {
|
|
32
|
-
size_t position = 0;
|
|
33
|
-
BinaryReader reader(data.value(), position);
|
|
34
|
-
auto version = reader.readNumeric<std::uint8_t>();
|
|
35
|
-
switch (version) {
|
|
36
|
-
case 1:
|
|
37
|
-
{
|
|
38
|
-
auto raw_data = std::make_shared<Amulet::JavaRawChunkType>();
|
|
39
|
-
auto count = reader.readNumeric<std::uint64_t>();
|
|
40
|
-
for (auto i = 0; i < count; i++) {
|
|
41
|
-
auto key = reader.readSizeAndBytes();
|
|
42
|
-
auto tag = std::make_shared<AmuletNBT::NamedTag>(AmuletNBT::read_nbt(reader));
|
|
43
|
-
raw_data->emplace(key, tag);
|
|
44
|
-
}
|
|
45
|
-
_raw_data = raw_data;
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
default:
|
|
49
|
-
throw std::invalid_argument("Unsupported JavaRawChunkComponent version " + std::to_string(version));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
_raw_data = std::nullopt;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <optional>
|
|
4
|
-
#include <cstdint>
|
|
5
|
-
#include <string>
|
|
6
|
-
#include <stdexcept>
|
|
7
|
-
#include <memory>
|
|
8
|
-
#include <map>
|
|
9
|
-
#include <amulet_nbt/tag/named_tag.hpp>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
namespace Amulet {
|
|
13
|
-
typedef std::map<std::string, std::shared_ptr<AmuletNBT::NamedTag>> JavaRawChunkType;
|
|
14
|
-
|
|
15
|
-
class JavaRawChunkComponent {
|
|
16
|
-
private:
|
|
17
|
-
std::optional<std::shared_ptr<JavaRawChunkType>> _raw_data;
|
|
18
|
-
protected:
|
|
19
|
-
// Null constructor
|
|
20
|
-
JavaRawChunkComponent() {};
|
|
21
|
-
// Default constructor
|
|
22
|
-
void init(std::shared_ptr<JavaRawChunkType> raw_data) { _raw_data = raw_data; }
|
|
23
|
-
void init() { _raw_data = std::make_shared<JavaRawChunkType>(); }
|
|
24
|
-
// Serialise the component data
|
|
25
|
-
std::optional<std::string> serialise() const;
|
|
26
|
-
// Deserialise the component
|
|
27
|
-
void deserialise(std::optional<std::string>);
|
|
28
|
-
public:
|
|
29
|
-
static const std::string ComponentID;
|
|
30
|
-
std::shared_ptr<JavaRawChunkType> get_raw_data() {
|
|
31
|
-
if (_raw_data) {
|
|
32
|
-
return *_raw_data;
|
|
33
|
-
}
|
|
34
|
-
throw std::runtime_error("JavaRawChunkComponent has not been loaded.");
|
|
35
|
-
};
|
|
36
|
-
void set_raw_data(std::shared_ptr<JavaRawChunkType> raw_data) {
|
|
37
|
-
if (_raw_data) {
|
|
38
|
-
_raw_data = raw_data;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw std::runtime_error("JavaRawChunkComponent has not been loaded.");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import collections.abc
|
|
4
|
-
import typing
|
|
5
|
-
|
|
6
|
-
import amulet_nbt
|
|
7
|
-
|
|
8
|
-
__all__ = ["DataVersionComponent", "JavaRawChunkComponent"]
|
|
9
|
-
|
|
10
|
-
class DataVersionComponent:
|
|
11
|
-
ComponentID: typing.ClassVar[str] = "Amulet::DataVersionComponent"
|
|
12
|
-
@property
|
|
13
|
-
def data_version(self) -> int: ...
|
|
14
|
-
|
|
15
|
-
class JavaRawChunkComponent:
|
|
16
|
-
ComponentID: typing.ClassVar[str] = "Amulet::JavaRawChunkComponent"
|
|
17
|
-
@property
|
|
18
|
-
def raw_data(self) -> collections.abc.MutableMapping[str, amulet_nbt.NamedTag]: ...
|
|
19
|
-
@raw_data.setter
|
|
20
|
-
def raw_data(
|
|
21
|
-
self, arg1: collections.abc.Mapping[str, amulet_nbt.NamedTag]
|
|
22
|
-
) -> None: ...
|
amulet/level/java/java_chunk.cpp
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
#include <string>
|
|
2
|
-
#include <optional>
|
|
3
|
-
#include <vector>
|
|
4
|
-
#include <unordered_map>
|
|
5
|
-
#include <cstdint>
|
|
6
|
-
|
|
7
|
-
#include <amulet/chunk.hpp>
|
|
8
|
-
#include <amulet/level/java/java_chunk.hpp>
|
|
9
|
-
#include <amulet/chunk_components/block_component.hpp>
|
|
10
|
-
|
|
11
|
-
namespace Amulet {
|
|
12
|
-
const std::string JavaChunkNA::ChunkID = "Amulet::JavaChunkNA";
|
|
13
|
-
const std::string JavaChunk0::ChunkID = "Amulet::JavaChunk0";
|
|
14
|
-
const std::string JavaChunk1444::ChunkID = "Amulet::JavaChunk1444";
|
|
15
|
-
const std::string JavaChunk1466::ChunkID = "Amulet::JavaChunk1466";
|
|
16
|
-
const std::string JavaChunk2203::ChunkID = "Amulet::JavaChunk2203";
|
|
17
|
-
|
|
18
|
-
std::string JavaChunkNA::get_chunk_id() const { return ChunkID; }
|
|
19
|
-
std::string JavaChunk0::get_chunk_id() const { return ChunkID; }
|
|
20
|
-
std::string JavaChunk1444::get_chunk_id() const { return ChunkID; }
|
|
21
|
-
std::string JavaChunk1466::get_chunk_id() const { return ChunkID; }
|
|
22
|
-
std::string JavaChunk2203::get_chunk_id() const { return ChunkID; }
|
|
23
|
-
|
|
24
|
-
JavaChunkNA::JavaChunkNA(
|
|
25
|
-
std::shared_ptr<BlockStack> default_block,
|
|
26
|
-
std::shared_ptr<Biome> default_biome
|
|
27
|
-
) : ChunkComponentHelper() {
|
|
28
|
-
auto version_number = std::make_shared<VersionNumber>(
|
|
29
|
-
std::initializer_list<std::int64_t>{ -1 }
|
|
30
|
-
);
|
|
31
|
-
auto version_range = std::make_shared<VersionRange>(
|
|
32
|
-
"java",
|
|
33
|
-
version_number,
|
|
34
|
-
version_number
|
|
35
|
-
);
|
|
36
|
-
JavaRawChunkComponent::init();
|
|
37
|
-
DataVersionComponent::init(-1);
|
|
38
|
-
BlockComponent::init(
|
|
39
|
-
version_range,
|
|
40
|
-
SectionShape(
|
|
41
|
-
static_cast<std::uint16_t>(16),
|
|
42
|
-
static_cast<std::uint16_t>(16),
|
|
43
|
-
static_cast<std::uint16_t>(16)
|
|
44
|
-
),
|
|
45
|
-
default_block
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
JavaChunk0::JavaChunk0(
|
|
50
|
-
std::int64_t data_version,
|
|
51
|
-
std::shared_ptr<BlockStack> default_block,
|
|
52
|
-
std::shared_ptr<Biome> default_biome
|
|
53
|
-
) : ChunkComponentHelper() {
|
|
54
|
-
if (data_version < 0 || 1443 < data_version) {
|
|
55
|
-
throw std::invalid_argument("data version must be between 0 and 1443");
|
|
56
|
-
}
|
|
57
|
-
auto version_number = std::make_shared<VersionNumber>(
|
|
58
|
-
std::initializer_list<std::int64_t>{ data_version }
|
|
59
|
-
);
|
|
60
|
-
auto version_range = std::make_shared<VersionRange>(
|
|
61
|
-
"java",
|
|
62
|
-
version_number,
|
|
63
|
-
version_number
|
|
64
|
-
);
|
|
65
|
-
JavaRawChunkComponent::init();
|
|
66
|
-
DataVersionComponent::init(data_version);
|
|
67
|
-
BlockComponent::init(
|
|
68
|
-
version_range,
|
|
69
|
-
SectionShape(
|
|
70
|
-
static_cast<std::uint16_t>(16),
|
|
71
|
-
static_cast<std::uint16_t>(16),
|
|
72
|
-
static_cast<std::uint16_t>(16)
|
|
73
|
-
),
|
|
74
|
-
default_block
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
JavaChunk1444::JavaChunk1444(
|
|
79
|
-
std::int64_t data_version,
|
|
80
|
-
std::shared_ptr<BlockStack> default_block,
|
|
81
|
-
std::shared_ptr<Biome> default_biome
|
|
82
|
-
) : ChunkComponentHelper() {
|
|
83
|
-
if (data_version < 1444 || 1465 < data_version) {
|
|
84
|
-
throw std::invalid_argument("data version must be between 1443 and 1465");
|
|
85
|
-
}
|
|
86
|
-
auto version_number = std::make_shared<VersionNumber>(
|
|
87
|
-
std::initializer_list<std::int64_t>{ data_version }
|
|
88
|
-
);
|
|
89
|
-
auto version_range = std::make_shared<VersionRange>(
|
|
90
|
-
"java",
|
|
91
|
-
version_number,
|
|
92
|
-
version_number
|
|
93
|
-
);
|
|
94
|
-
JavaRawChunkComponent::init();
|
|
95
|
-
DataVersionComponent::init(data_version);
|
|
96
|
-
BlockComponent::init(
|
|
97
|
-
version_range,
|
|
98
|
-
SectionShape(
|
|
99
|
-
static_cast<std::uint16_t>(16),
|
|
100
|
-
static_cast<std::uint16_t>(16),
|
|
101
|
-
static_cast<std::uint16_t>(16)
|
|
102
|
-
),
|
|
103
|
-
default_block
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
JavaChunk1466::JavaChunk1466(
|
|
108
|
-
std::int64_t data_version,
|
|
109
|
-
std::shared_ptr<BlockStack> default_block,
|
|
110
|
-
std::shared_ptr<Biome> default_biome
|
|
111
|
-
) : ChunkComponentHelper() {
|
|
112
|
-
if (data_version < 1466 || 2202 < data_version) {
|
|
113
|
-
throw std::invalid_argument("data version must be between 1466 and 2202");
|
|
114
|
-
}
|
|
115
|
-
auto version_number = std::make_shared<VersionNumber>(
|
|
116
|
-
std::initializer_list<std::int64_t>{ data_version }
|
|
117
|
-
);
|
|
118
|
-
auto version_range = std::make_shared<VersionRange>(
|
|
119
|
-
"java",
|
|
120
|
-
version_number,
|
|
121
|
-
version_number
|
|
122
|
-
);
|
|
123
|
-
JavaRawChunkComponent::init();
|
|
124
|
-
DataVersionComponent::init(data_version);
|
|
125
|
-
BlockComponent::init(
|
|
126
|
-
version_range,
|
|
127
|
-
SectionShape(
|
|
128
|
-
static_cast<std::uint16_t>(16),
|
|
129
|
-
static_cast<std::uint16_t>(16),
|
|
130
|
-
static_cast<std::uint16_t>(16)
|
|
131
|
-
),
|
|
132
|
-
default_block
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
JavaChunk2203::JavaChunk2203(
|
|
137
|
-
std::int64_t data_version,
|
|
138
|
-
std::shared_ptr<BlockStack> default_block,
|
|
139
|
-
std::shared_ptr<Biome> default_biome
|
|
140
|
-
) : ChunkComponentHelper() {
|
|
141
|
-
if (data_version < 2203) {
|
|
142
|
-
throw std::invalid_argument("data version must be at least 2203");
|
|
143
|
-
}
|
|
144
|
-
auto version_number = std::make_shared<VersionNumber>(
|
|
145
|
-
std::initializer_list<std::int64_t>{ data_version }
|
|
146
|
-
);
|
|
147
|
-
auto version_range = std::make_shared<VersionRange>(
|
|
148
|
-
"java",
|
|
149
|
-
version_number,
|
|
150
|
-
version_number
|
|
151
|
-
);
|
|
152
|
-
JavaRawChunkComponent::init();
|
|
153
|
-
DataVersionComponent::init(data_version);
|
|
154
|
-
BlockComponent::init(
|
|
155
|
-
version_range,
|
|
156
|
-
SectionShape(
|
|
157
|
-
static_cast<std::uint16_t>(16),
|
|
158
|
-
static_cast<std::uint16_t>(16),
|
|
159
|
-
static_cast<std::uint16_t>(16)
|
|
160
|
-
),
|
|
161
|
-
default_block
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
static const ChunkNullConstructor<JavaChunkNA> _jcna;
|
|
166
|
-
static const ChunkNullConstructor<JavaChunk0> _jc0;
|
|
167
|
-
static const ChunkNullConstructor<JavaChunk1444> _jc1444;
|
|
168
|
-
static const ChunkNullConstructor<JavaChunk1466> _jc1466;
|
|
169
|
-
static const ChunkNullConstructor<JavaChunk2203> _jc2203;
|
|
170
|
-
}
|
amulet/level/java/java_chunk.hpp
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <optional>
|
|
5
|
-
#include <stdexcept>
|
|
6
|
-
#include <vector>
|
|
7
|
-
#include <amulet/block.hpp>
|
|
8
|
-
#include <amulet/biome.hpp>
|
|
9
|
-
#include <amulet/chunk.hpp>
|
|
10
|
-
#include <amulet/chunk_components/block_component.hpp>
|
|
11
|
-
#include "chunk_components/java_raw_chunk_component.hpp"
|
|
12
|
-
#include "chunk_components/data_version_component.hpp"
|
|
13
|
-
|
|
14
|
-
namespace Amulet {
|
|
15
|
-
class JavaChunk : public Chunk {};
|
|
16
|
-
|
|
17
|
-
class JavaChunkNA : public ChunkComponentHelper<
|
|
18
|
-
JavaChunk,
|
|
19
|
-
JavaRawChunkComponent,
|
|
20
|
-
DataVersionComponent,
|
|
21
|
-
// LastUpdateComponent,
|
|
22
|
-
// JavaLegacyVersionComponent,
|
|
23
|
-
BlockComponent//,
|
|
24
|
-
// BlockEntityComponent,
|
|
25
|
-
// EntityComponent,
|
|
26
|
-
// Biome2DComponent,
|
|
27
|
-
// Height2DComponent,
|
|
28
|
-
> {
|
|
29
|
-
public:
|
|
30
|
-
static const std::string ChunkID;
|
|
31
|
-
|
|
32
|
-
std::string get_chunk_id() const override;
|
|
33
|
-
|
|
34
|
-
using ChunkComponentHelper::ChunkComponentHelper;
|
|
35
|
-
JavaChunkNA(
|
|
36
|
-
std::shared_ptr<BlockStack> default_block,
|
|
37
|
-
std::shared_ptr<Biome> default_biome
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
class JavaChunk0 : public ChunkComponentHelper<
|
|
42
|
-
JavaChunk,
|
|
43
|
-
JavaRawChunkComponent,
|
|
44
|
-
DataVersionComponent,
|
|
45
|
-
// LastUpdateComponent,
|
|
46
|
-
// TerrainPopulatedComponent,
|
|
47
|
-
// LightPopulatedComponent,
|
|
48
|
-
BlockComponent//,
|
|
49
|
-
// BlockEntityComponent,
|
|
50
|
-
// EntityComponent,
|
|
51
|
-
// Biome2DComponent,
|
|
52
|
-
// Height2DComponent,
|
|
53
|
-
> {
|
|
54
|
-
public:
|
|
55
|
-
static const std::string ChunkID;
|
|
56
|
-
|
|
57
|
-
std::string get_chunk_id() const override;
|
|
58
|
-
|
|
59
|
-
using ChunkComponentHelper::ChunkComponentHelper;
|
|
60
|
-
JavaChunk0(
|
|
61
|
-
std::int64_t data_version,
|
|
62
|
-
std::shared_ptr<BlockStack> default_block,
|
|
63
|
-
std::shared_ptr<Biome> default_biome
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
class JavaChunk1444 : public ChunkComponentHelper<
|
|
68
|
-
JavaChunk,
|
|
69
|
-
JavaRawChunkComponent,
|
|
70
|
-
DataVersionComponent,
|
|
71
|
-
// LastUpdateComponent,
|
|
72
|
-
// StatusStringComponent,
|
|
73
|
-
BlockComponent//,
|
|
74
|
-
// BlockEntityComponent,
|
|
75
|
-
// EntityComponent,
|
|
76
|
-
// Biome2DComponent,
|
|
77
|
-
// Height2DComponent,
|
|
78
|
-
> {
|
|
79
|
-
public:
|
|
80
|
-
static const std::string ChunkID;
|
|
81
|
-
|
|
82
|
-
std::string get_chunk_id() const override;
|
|
83
|
-
|
|
84
|
-
using ChunkComponentHelper::ChunkComponentHelper;
|
|
85
|
-
JavaChunk1444(
|
|
86
|
-
std::int64_t data_version,
|
|
87
|
-
std::shared_ptr<BlockStack> default_block,
|
|
88
|
-
std::shared_ptr<Biome> default_biome
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
class JavaChunk1466 : public ChunkComponentHelper<
|
|
93
|
-
JavaChunk,
|
|
94
|
-
JavaRawChunkComponent,
|
|
95
|
-
DataVersionComponent,
|
|
96
|
-
// LastUpdateComponent,
|
|
97
|
-
// StatusStringComponent,
|
|
98
|
-
BlockComponent//,
|
|
99
|
-
// BlockEntityComponent,
|
|
100
|
-
// EntityComponent,
|
|
101
|
-
// Biome2DComponent,
|
|
102
|
-
// NamedHeight2DComponent,
|
|
103
|
-
> {
|
|
104
|
-
public:
|
|
105
|
-
static const std::string ChunkID;
|
|
106
|
-
|
|
107
|
-
std::string get_chunk_id() const override;
|
|
108
|
-
|
|
109
|
-
using ChunkComponentHelper::ChunkComponentHelper;
|
|
110
|
-
JavaChunk1466(
|
|
111
|
-
std::int64_t data_version,
|
|
112
|
-
std::shared_ptr<BlockStack> default_block,
|
|
113
|
-
std::shared_ptr<Biome> default_biome
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
class JavaChunk2203 : public ChunkComponentHelper<
|
|
118
|
-
JavaChunk,
|
|
119
|
-
JavaRawChunkComponent,
|
|
120
|
-
DataVersionComponent,
|
|
121
|
-
// LastUpdateComponent,
|
|
122
|
-
// StatusStringComponent,
|
|
123
|
-
BlockComponent//,
|
|
124
|
-
// BlockEntityComponent,
|
|
125
|
-
// EntityComponent,
|
|
126
|
-
// Biome3DComponent,
|
|
127
|
-
// NamedHeight2DComponent,
|
|
128
|
-
> {
|
|
129
|
-
public:
|
|
130
|
-
static const std::string ChunkID;
|
|
131
|
-
|
|
132
|
-
std::string get_chunk_id() const override;
|
|
133
|
-
|
|
134
|
-
using ChunkComponentHelper::ChunkComponentHelper;
|
|
135
|
-
JavaChunk2203(
|
|
136
|
-
std::int64_t data_version,
|
|
137
|
-
std::shared_ptr<BlockStack> default_block,
|
|
138
|
-
std::shared_ptr<Biome> default_biome
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
}
|
amulet/level/java/long_array.hpp
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
#include <span>
|
|
3
|
-
#include <cstdint>
|
|
4
|
-
#include <stdexcept>
|
|
5
|
-
#include <string>
|
|
6
|
-
#include <cmath>
|
|
7
|
-
#include <algorithm>
|
|
8
|
-
#include <bit>
|
|
9
|
-
#include <type_traits>
|
|
10
|
-
|
|
11
|
-
namespace Amulet {
|
|
12
|
-
/*
|
|
13
|
-
Minecraft Java edition stores the block and height arrays in a compacted long array format.
|
|
14
|
-
The format stores one or more entries per long, using the fewest number of bits required to store the data.
|
|
15
|
-
There are two storage methods, the compact version was used prior to 1.16 and the less compact version in 1.16 and above.
|
|
16
|
-
Apparently the less compact version is quicker to pack and unpack.
|
|
17
|
-
The compact version effectively stores the values as a bit array spanning one or more values in the long array.
|
|
18
|
-
There may be some padding if the bit array does not fill all the long values. (The letter "P" signifies an unused padding bit)
|
|
19
|
-
HGGGGGGGGGFFFFFFFFFEEEEEEEEEDDDDDDDDDCCCCCCCCCBBBBBBBBBAAAAAAAAA PPNNNNNNNNNMMMMMMMMMLLLLLLLLLKKKKKKKKKJJJJJJJJJIIIIIIIIIHHHHHHHH
|
|
20
|
-
The less compact version does not allow entries to straddle long values. Instead, if required, there is padding within each long.
|
|
21
|
-
PGGGGGGGGGFFFFFFFFFEEEEEEEEEDDDDDDDDDCCCCCCCCCBBBBBBBBBAAAAAAAAA PNNNNNNNNNMMMMMMMMMLLLLLLLLLKKKKKKKKKJJJJJJJJJIIIIIIIIIHHHHHHHHH
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
template <typename decodedT>
|
|
25
|
-
void decode_long_array(
|
|
26
|
-
const std::span<std::uint64_t>& encoded, // The long array to decode
|
|
27
|
-
std::span<decodedT>& decoded, // The array to unpack values into
|
|
28
|
-
std::uint8_t bits_per_entry, // The number of bits per entry
|
|
29
|
-
bool dense = true
|
|
30
|
-
) {
|
|
31
|
-
static_assert(std::is_unsigned_v<decodedT>, "decodedT must be unsigned");
|
|
32
|
-
if (bits_per_entry < 1 || 64 < bits_per_entry) {
|
|
33
|
-
throw std::invalid_argument("bits_per_entry must be between 1 and 64 inclusive. Got " + std::to_string(bits_per_entry));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
size_t expected_len = std::ceil(
|
|
37
|
-
dense ? static_cast<float>(decoded.size()) * bits_per_entry / 64 : static_cast<float>(decoded.size()) / (64 / bits_per_entry)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
if (encoded.size() != expected_len) {
|
|
41
|
-
throw std::invalid_argument(
|
|
42
|
-
dense ? "Dense encoded long array with " : "Encoded long array with " +
|
|
43
|
-
std::to_string(bits_per_entry) +
|
|
44
|
-
" bits per entry should contain " +
|
|
45
|
-
std::to_string(expected_len) +
|
|
46
|
-
" longs but got " +
|
|
47
|
-
std::to_string(encoded.size()) +
|
|
48
|
-
"."
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const std::uint64_t mask = ~0ull >> (64 - bits_per_entry);
|
|
53
|
-
if (dense) {
|
|
54
|
-
for (size_t decoded_index = 0; decoded_index < decoded.size(); decoded_index++) {
|
|
55
|
-
size_t bit_start = decoded_index * bits_per_entry;
|
|
56
|
-
size_t bit_stop = (decoded_index + 1) * bits_per_entry;
|
|
57
|
-
size_t long_start = bit_start / 64;
|
|
58
|
-
decodedT& value = decoded[decoded_index];
|
|
59
|
-
value = (encoded[long_start] >> (bit_start % 64)) & mask;
|
|
60
|
-
if ((long_start + 1) * 64 < bit_stop) {
|
|
61
|
-
// Overflows into the next long
|
|
62
|
-
size_t overflow_bits = bit_stop - (long_start + 1) * 64;
|
|
63
|
-
size_t previous_bits = bits_per_entry - overflow_bits;
|
|
64
|
-
value |= (encoded[long_start + 1] & (mask >> previous_bits)) << previous_bits;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
size_t entries_per_long = 64 / bits_per_entry;
|
|
70
|
-
size_t decoded_index = 0;
|
|
71
|
-
for (const auto& encoded_value : encoded) {
|
|
72
|
-
for (
|
|
73
|
-
size_t offset = 0;
|
|
74
|
-
offset < entries_per_long && decoded_index < decoded.size();
|
|
75
|
-
offset++, decoded_index++
|
|
76
|
-
) {
|
|
77
|
-
decoded[decoded_index] = (encoded_value >> (bits_per_entry * offset)) & mask;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Get the number of longs required to store the encoded long array.
|
|
84
|
-
inline size_t encoded_long_array_size(
|
|
85
|
-
size_t decoded_size, // The number of elements to encode
|
|
86
|
-
std::uint8_t bits_per_entry, // The number of bits of each number to use
|
|
87
|
-
bool dense = true
|
|
88
|
-
) {
|
|
89
|
-
if (dense) {
|
|
90
|
-
return std::ceil(static_cast<float>(decoded_size * bits_per_entry) / 64);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
size_t entries_per_long = 64 / bits_per_entry;
|
|
94
|
-
return std::ceil(static_cast<float>(decoded_size) / entries_per_long);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Encode the array to a long array with the specified number of bits. Extra bits are ignored.
|
|
99
|
-
template <typename decodedT>
|
|
100
|
-
void encode_long_array(
|
|
101
|
-
const std::span<decodedT>& decoded, // The array to encode
|
|
102
|
-
std::span<std::uint64_t> encoded, // The array to encode into. This must be large enough.
|
|
103
|
-
std::uint8_t bits_per_entry, // The number of bits of each number to use
|
|
104
|
-
bool dense = true
|
|
105
|
-
) {
|
|
106
|
-
static_assert(std::is_unsigned_v<decodedT>, "decodedT must be unsigned");
|
|
107
|
-
if (bits_per_entry < 1 || 64 < bits_per_entry) {
|
|
108
|
-
throw std::invalid_argument("bits_per_entry must be between 1 and 64 inclusive. Got " + std::to_string(bits_per_entry));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Set all values to 0
|
|
112
|
-
std::fill(encoded.begin(), encoded.end(), 0);
|
|
113
|
-
const std::uint64_t mask = ~0ull >> (64 - bits_per_entry);
|
|
114
|
-
if (dense) {
|
|
115
|
-
for (size_t decoded_index = 0; decoded_index < decoded.size(); decoded_index++) {
|
|
116
|
-
// The bit in the array where the value starts
|
|
117
|
-
size_t bit_start = decoded_index * bits_per_entry;
|
|
118
|
-
// The bit in the array where the value stops
|
|
119
|
-
size_t bit_stop = bit_start + bits_per_entry;
|
|
120
|
-
// The long number that the value starts in
|
|
121
|
-
size_t long_start = bit_start / 64;
|
|
122
|
-
// The bit offset in the long where the value starts
|
|
123
|
-
size_t long_bit_offset = bit_start % 64;
|
|
124
|
-
// The bit in the array where the long stops
|
|
125
|
-
size_t long_bit_stop = (long_start + 1) * 64;
|
|
126
|
-
decodedT& value = decoded[decoded_index];
|
|
127
|
-
encoded[long_start] = (encoded[long_start] & ~(mask << long_bit_offset)) + ((value & mask) << long_bit_offset);
|
|
128
|
-
if (long_bit_stop < bit_stop) {
|
|
129
|
-
// Overflows into the next long
|
|
130
|
-
// The number of bits that overflow into the next long
|
|
131
|
-
size_t overflow_bits = bit_stop - long_bit_stop;
|
|
132
|
-
// The number of bits in the previous long
|
|
133
|
-
size_t previous_bits = bits_per_entry - overflow_bits;
|
|
134
|
-
encoded[long_start + 1] = (encoded[long_start + 1] & ~(mask >> previous_bits)) + ((value & mask) >> previous_bits);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
size_t entries_per_long = 64 / bits_per_entry;
|
|
140
|
-
size_t decoded_index = 0;
|
|
141
|
-
size_t long_count = std::ceil(static_cast<float>(decoded.size()) / entries_per_long);
|
|
142
|
-
for (size_t encoded_index = 0; encoded_index < long_count; encoded_index++) {
|
|
143
|
-
auto& encoded_value = encoded[encoded_index];
|
|
144
|
-
encoded_value = 0;
|
|
145
|
-
for (
|
|
146
|
-
size_t offset = 0;
|
|
147
|
-
offset < entries_per_long && decoded_index < decoded.size();
|
|
148
|
-
offset++, decoded_index++
|
|
149
|
-
) {
|
|
150
|
-
std::uint64_t value = decoded[decoded_index] & mask;
|
|
151
|
-
encoded_value += value << (bits_per_entry * offset);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Encode the array to a long aray with at least this number of bits. The number of required bits is computed before encoding.
|
|
158
|
-
template <typename decodedT>
|
|
159
|
-
void encode_long_array_min(
|
|
160
|
-
const std::span<decodedT>& decoded, // The array to encode
|
|
161
|
-
std::span<std::uint64_t> encoded, // The array to encode into
|
|
162
|
-
std::uint8_t min_bits_per_entry, // The minimum number of bits of each number to use
|
|
163
|
-
bool dense = true
|
|
164
|
-
) {
|
|
165
|
-
static_assert(std::is_unsigned_v<decodedT>, "decodedT must be unsigned");
|
|
166
|
-
if (min_bits_per_entry < 1 || 64 < min_bits_per_entry) {
|
|
167
|
-
throw std::invalid_argument("min_bits_per_entry must be between 1 and 64 inclusive. Got " + std::to_string(min_bits_per_entry));
|
|
168
|
-
}
|
|
169
|
-
std::uint8_t bits_per_entry = std::max(
|
|
170
|
-
min_bits_per_entry,
|
|
171
|
-
std::bit_width(*std::max_element(decoded.begin(), decoded.end()))
|
|
172
|
-
);
|
|
173
|
-
encode_long_array(decoded, encoded, bits_per_entry, dense);
|
|
174
|
-
}
|
|
175
|
-
}
|