Merge branch 'main' into dev

This commit is contained in:
MihailRis
2025-11-04 16:02:46 +03:00
12 changed files with 119 additions and 17 deletions
+3 -3
View File
@@ -62,7 +62,7 @@ void ContentGfxCache::refreshVariant(
}
}
}
models[def.rt.id] = std::move(model);
models[modelKey(def.rt.id, variantIndex)] = std::move(model);
}
}
@@ -94,8 +94,8 @@ void ContentGfxCache::refresh() {
ContentGfxCache::~ContentGfxCache() = default;
const model::Model& ContentGfxCache::getModel(blockid_t id) const {
const auto& found = models.find(id);
const model::Model& ContentGfxCache::getModel(blockid_t id, uint8_t variant) const {
const auto& found = models.find(modelKey(id, variant));
if (found == models.end()) {
throw std::runtime_error("model not found");
}
+6 -2
View File
@@ -27,7 +27,11 @@ class ContentGfxCache {
// array of block sides uv regions (6 per block)
std::unique_ptr<UVRegion[]> sideregions;
std::unordered_map<blockid_t, model::Model> models;
std::unordered_map<uint64_t, model::Model> models;
static inline uint64_t modelKey(blockid_t id, uint8_t variant) {
return (uint64_t(id) << 8) | uint64_t(variant & 0xFF);
}
void refreshVariant(
const Block& def,
@@ -53,7 +57,7 @@ public:
return sideregions[getRegionIndex(id, variant, side, !dense)];
}
const model::Model& getModel(blockid_t id) const;
const model::Model& getModel(blockid_t id, uint8_t variant) const;
void refresh(const Block& block, const Atlas& atlas);
+1 -1
View File
@@ -67,7 +67,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
glm::vec3 poff = glm::vec3(0.0f, 0.0f, 1.0f);
offset.y += (1.0f - hitbox).y * 0.5f;
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
const auto& model = cache.getModel(def.rt.id);
const auto& model = cache.getModel(def.rt.id, 0);
for (const auto& mesh : model.meshes) {
for (const auto& vertex : mesh.vertices) {
+1 -1
View File
@@ -308,7 +308,7 @@ void BlocksRenderer::blockCustomModel(
Z = orient.axes[2];
}
const auto& model = cache.getModel(block.rt.id);
const auto& model = cache.getModel(block.rt.id, block.getVariantIndex(states.userbits));
for (const auto& mesh : model.meshes) {
if (vertexCount + mesh.vertices.size() >= capacity) {
overflow = true;
+17 -7
View File
@@ -118,6 +118,11 @@ namespace util {
return x * x + y * y + z * z;
}
/// @return integer dot product of two vectors
inline int dot(const glm::ivec3& a, const glm::ivec3& b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
/// @brief Find nearest point on segment to given
/// @param a segment point A
/// @param b segment point B
@@ -144,12 +149,17 @@ namespace util {
inline glm::ivec3 closest_point_on_segment(
const glm::ivec3& a, const glm::ivec3& b, const glm::ivec3& point
) {
auto vec = b - a;
float da = distance2(point, a);
float db = distance2(point, b);
float len = length2(vec);
float t = (((da - db) / len) * 0.5f + 0.5f);
t = std::min(1.0f, std::max(0.0f, t));
return a + glm::ivec3(glm::vec3(vec) * t);
glm::ivec3 vec = b - a;
int len2 = length2(vec);
if (len2 == 0) return a;
glm::ivec3 ap = point - a;
int dot_product = dot(ap, vec);
float t = static_cast<float>(dot_product) / static_cast<float>(len2);
t = glm::clamp(t, 0.0f, 1.0f);
return a + glm::ivec3(glm::round(glm::vec3(vec) * t));
}
}
+3 -3
View File
@@ -547,13 +547,13 @@ void WorldGenerator::generateLine(
auto b = line.b;
int minX = std::max(0, std::min(a.x-radius-cgx, b.x-radius-cgx));
int maxX = std::min(CHUNK_W, std::max(a.x+radius-cgx, b.x+radius-cgx));
int maxX = std::min(CHUNK_W, std::max(a.x+radius-cgx, b.x+radius-cgx) + 1);
int minZ = std::max(0, std::min(a.z-radius-cgz, b.z-radius-cgz));
int maxZ = std::min(CHUNK_D, std::max(a.z+radius-cgz, b.z+radius-cgz));
int maxZ = std::min(CHUNK_D, std::max(a.z+radius-cgz, b.z+radius-cgz) + 1);
int minY = std::max(0, std::min(a.y-radius, b.y-radius));
int maxY = std::min(CHUNK_H, std::max(a.y+radius, b.y+radius));
int maxY = std::min(CHUNK_H, std::max(a.y+radius, b.y+radius) + 1);
for (int y = minY; y < maxY; y++) {
for (int z = minZ; z < maxZ; z++) {