Skip to content

Commit

Permalink
deps: Update libminecraft-file to remove XXHash class
Browse files Browse the repository at this point in the history
  • Loading branch information
kbinani committed Feb 6, 2024
1 parent 2de0246 commit bd54394
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 78 deletions.
10 changes: 2 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ endif()
CPMAddPackage(
NAME libminecraft-file
GITHUB_REPOSITORY kbinani/libminecraft-file
GIT_TAG a6b876941e2fa13dd4357ea82f328b8ffb5ab052)
GIT_TAG 6411a9810404d40daad4107b5478c554685934d6)

CPMAddPackage(
NAME defer
Expand Down Expand Up @@ -167,6 +167,7 @@ set(mcfile_header_files
${libminecraft-file_SOURCE_DIR}/include/mcfile/stream/output-stream.hpp
${libminecraft-file_SOURCE_DIR}/include/mcfile/string.hpp
${libminecraft-file_SOURCE_DIR}/include/mcfile/u8stream.hpp
${libminecraft-file_SOURCE_DIR}/include/mcfile/xxhash.hpp
${libminecraft-file_SOURCE_DIR}/include/minecraft-file.hpp
#end libminecraft-file source files
)
Expand Down Expand Up @@ -202,7 +203,6 @@ set(je2be_src_files
src/_version.hpp
src/_volume.hpp
src/_walk.hpp
src/_xxhash.hpp
src/bedrock-block-data.cpp
src/bedrock-block-entity.cpp
src/bedrock-chunk.cpp
Expand Down Expand Up @@ -475,11 +475,6 @@ if (nlohmann_json_ADDED)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}/include)
endif()

CPMAddPackage(
NAME xxhash
GIT_TAG c2866db364b6ea3a11933e62235ddc166ba18565
GIT_REPOSITORY https://github.com/stbrumme/xxhash.git)

CPMAddPackage(
NAME minizip
GITHUB_REPOSITORY zlib-ng/minizip-ng
Expand Down Expand Up @@ -527,7 +522,6 @@ target_include_directories(je2be PUBLIC
${leveldb_SOURCE_DIR}
${leveldb_SOURCE_DIR}/include
${minizip_SOURCE_DIR}
${xxhash_SOURCE_DIR}
${nlohmann_json_SOURCE_DIR}/include
${sparse_SOURCE_DIR}
${je2be_include_directories})
Expand Down
6 changes: 1 addition & 5 deletions src/_props.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <nlohmann/json.hpp>
#include <xxhash32.h>

#include <je2be/uuid.hpp>

Expand Down Expand Up @@ -290,10 +289,7 @@ static std::u8string GetTextComponent(std::u8string const &in) {

static inline i32 SquashI64ToI32(i64 v) {
if (v < (i64)std::numeric_limits<i32>::min() || (i64)std::numeric_limits<i32>::max() < v) {
XXHash32 x(0);
x.add(&v, sizeof(v));
u32 u = x.hash();
return *(i32 *)&u;
return mcfile::XXHash<i32>::Digest(&v, sizeof(v));
} else {
return static_cast<i32>(v);
}
Expand Down
35 changes: 0 additions & 35 deletions src/_xxhash.hpp

This file was deleted.

14 changes: 6 additions & 8 deletions src/bedrock-entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "enums/_villager-type.hpp"
#include "tile-entity/_loot-table.hpp"

#include <xxhash64.h>

namespace je2be::bedrock {

class Entity::Impl {
Expand Down Expand Up @@ -70,12 +68,12 @@ class Entity::Impl {
Pos3d position(pos.fX + 0.5 - direction.fX * thickness, pos.fY + 0.5 - direction.fY * thickness, pos.fZ + 0.5 - direction.fZ * thickness);
t[u8"Pos"] = position.toListTag();

XXHash64 h(0);
h.add(&d, sizeof(d));
h.add(&position.fX, sizeof(position.fX));
h.add(&position.fY, sizeof(position.fY));
h.add(&position.fZ, sizeof(position.fZ));
auto uuid = Uuid::GenWithU64Seed(h.hash());
mcfile::XXHash<u64> h(0);
h.update(&d, sizeof(d));
h.update(&position.fX, sizeof(position.fX));
h.update(&position.fY, sizeof(position.fY));
h.update(&position.fZ, sizeof(position.fZ));
auto uuid = Uuid::GenWithU64Seed(h.digest());
t[u8"UUID"] = uuid.toIntArrayTag();

auto itemB = blockEntityB.compoundTag(u8"Item");
Expand Down
6 changes: 2 additions & 4 deletions src/java-map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "item/_map-decoration.hpp"
#include "java/_java-edition-map.hpp"

#include <xxhash32.h>

#include <optional>
#include <tuple>

Expand All @@ -20,8 +18,8 @@ class Map::Impl {
public:
static i64 UUID(i32 javaMapId, u8 scale) {
u32 const seed = 0;
u32 hash = XXHash32::hash(&javaMapId, sizeof(javaMapId), seed);
u64 s = (u64)hash * 10 + (4 - scale);
u64 hash = mcfile::XXHash<u32>::Digest(&javaMapId, sizeof(javaMapId), seed);
u64 s = hash * 10 + (4 - scale);
return *(i64 *)&s;
}

Expand Down
15 changes: 7 additions & 8 deletions src/java-tile-entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "_nbt-ext.hpp"
#include "_optional.hpp"
#include "_props.hpp"
#include "_xxhash.hpp"
#include "color/_sign-color.hpp"
#include "command/_command.hpp"
#include "enums/_banner-color-code-bedrock.hpp"
Expand Down Expand Up @@ -661,11 +660,11 @@ class TileEntity::Impl {
// "rott"
// [-pi, pi] float, an angle of enchant table and player's position who placed the table.
// Java doesn't store such data in tile entity, so generate rott based on its xyz position.
XXHash32 xx(0);
xx.add(&pos.fX, sizeof(pos.fX));
xx.add(&pos.fY, sizeof(pos.fY));
xx.add(&pos.fZ, sizeof(pos.fZ));
u32 seed = xx.hash();
mcfile::XXHash<u32> xx(0);
xx.update(&pos.fX, sizeof(pos.fX));
xx.update(&pos.fY, sizeof(pos.fY));
xx.update(&pos.fZ, sizeof(pos.fZ));
u32 seed = xx.digest();
std::mt19937 gen(seed);
std::uniform_real_distribution<float> distribution(-std::numbers::pi, std::numbers::pi);
float rott = distribution(gen);
Expand Down Expand Up @@ -798,11 +797,11 @@ class TileEntity::Impl {
}

// UUIDs are not stored in EntityData, so create a unique id.
XXHash h;
mcfile::XXHash<u64> h;
h.update(&ctx.fWorldData.fDim, sizeof(ctx.fWorldData.fDim));
h.update(&pos.fX, sizeof(pos.fX));
h.update(&pos.fZ, sizeof(pos.fZ));
i64 hash = h.digest();
u64 hash = h.digest();
u32 lo = ((u32 *)&hash)[0];
u32 hi = ((u32 *)&hash)[1];
vector<i32> uuidSource = {*(i32 *)&lo, *(i32 *)&hi, pos.fY, index};
Expand Down
8 changes: 3 additions & 5 deletions src/java/_uuid-registrar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <je2be/uuid.hpp>

#include "_xxhash.hpp"

#include <mutex>

namespace je2be::java {
Expand Down Expand Up @@ -34,7 +32,7 @@ class UuidRegistrar {
if (found != sLut.end()) {
return found->second;
}
i64 candidate = XXHash::Digest(&id, sizeof(id));
i64 candidate = mcfile::XXHash<i64>::Digest(&id, sizeof(id));
i64 result = AvoidCollision(candidate);
sLut[id] = result;
return result;
Expand All @@ -50,14 +48,14 @@ class UuidRegistrar {
static std::unordered_set<i64> sUsed;

while (sUsed.count(h) > 0) {
h = XXHash::Digest(&h, sizeof(h));
h = mcfile::XXHash<i64>::Digest(&h, sizeof(h));
}
sUsed.insert(h);
return h;
}

static i64 FirstCandidate(Uuid const &uuid) {
XXHash h;
mcfile::XXHash<i64> h;
h.update(uuid.fData, sizeof(uuid.fData));
return h.digest();
}
Expand Down
3 changes: 1 addition & 2 deletions src/lce-entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "_namespace.hpp"
#include "_nbt-ext.hpp"
#include "_xxhash.hpp"
#include "entity/_painting.hpp"
#include "enums/_facing6.hpp"
#include "lce/_attribute.hpp"
Expand Down Expand Up @@ -104,7 +103,7 @@ class Entity::Impl {
if (auto u = MigrateEntityUuid(uuid); u) {
return *u;
}
i64 seed = XXHash::Digest(uuid.c_str(), uuid.size());
i64 seed = mcfile::XXHash<i64>::Digest(uuid.c_str(), uuid.size());
return Uuid::GenWithI64Seed(seed);
}

Expand Down
1 change: 0 additions & 1 deletion test/je2be-all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "color/_rgba.hpp"
#include "color/_lab.hpp"
#include "_size.hpp"
#include "_xxhash.hpp"
#include "_props.hpp"
#include "_future-support.hpp"
#include "_parallel.hpp"
Expand Down
4 changes: 2 additions & 2 deletions test/research.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ static void PistonArm() {
ostringstream ss;
mcfile::nbt::PrintAsJson(ss, *root, {.fTypeHint = true});
auto s = ss.str();
int64_t digest = XXHash::Digest(s.c_str(), s.size());
int64_t digest = XXHash<int64_t>::Digest(s.c_str(), s.size());
fs::path out = fs::path("1.19piston_arm_bedrock_" + to_string(digest) + ".json");
if (fs::exists(out)) {
cout << out << " already exists" << endl;
Expand Down Expand Up @@ -870,7 +870,7 @@ static void PistonArm() {
ostringstream ss;
mcfile::nbt::PrintAsJson(ss, *root, {.fTypeHint = true});
auto s = ss.str();
int64_t digest = XXHash::Digest(s.c_str(), s.size());
int64_t digest = XXHash<int64_t>::Digest(s.c_str(), s.size());
fs::path out = fs::path("1.19piston_arm_java_" + to_string(digest) + ".json");
if (fs::exists(out)) {
cout << out << " already exists" << endl;
Expand Down

0 comments on commit bd54394

Please sign in to comment.