Slightly optimize model factory

This commit is contained in:
mcrcortex
2025-04-25 18:30:23 +10:00
parent bbe7cd2099
commit 7c27a4d8fd
3 changed files with 12 additions and 8 deletions

View File

@@ -2,21 +2,25 @@ package me.cortex.voxy.client.core.model;
import java.util.Arrays;
public record ColourDepthTextureData(int[] colour, int[] depth, int width, int height) {
public record ColourDepthTextureData(int[] colour, int[] depth, int width, int height, int hash) {
public ColourDepthTextureData(int[] colour, int[] depth, int width, int height) {
this(colour, depth, width, height, width * 312337173 * (Arrays.hashCode(colour) ^ Arrays.hashCode(depth)) ^ height);
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
var other = ((ColourDepthTextureData)obj);
return Arrays.equals(other.colour, this.colour) && Arrays.equals(other.depth, this.depth);
return this.hash == other.hash && Arrays.equals(other.colour, this.colour) && Arrays.equals(other.depth, this.depth);
}
@Override
public int hashCode() {
return (this.width * 312337173 * (Arrays.hashCode(this.colour) ^ Arrays.hashCode(this.depth))) ^ this.height;
return this.hash;
}
@Override
public ColourDepthTextureData clone() {
return new ColourDepthTextureData(Arrays.copyOf(this.colour, this.colour.length), Arrays.copyOf(this.depth, this.depth.length), this.width, this.height);
return new ColourDepthTextureData(Arrays.copyOf(this.colour, this.colour.length), Arrays.copyOf(this.depth, this.depth.length), this.width, this.height, this.hash);
}
}

View File

@@ -38,7 +38,7 @@ public class ModelBakerySubsystem {
public void tick() {
//There should be a method to access the frame time IIRC, if the user framecap is unlimited lock it to like 60 fps for computation
int BUDGET = 25;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1)
int BUDGET = 16;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1)
for (int i = 0; i < BUDGET && !this.blockIdQueue.isEmpty(); i++) {
int blockId = -1;

View File

@@ -59,9 +59,9 @@ public class ModelFactory {
//TODO: replace the fluid BlockState with a client model id integer of the fluidState, requires looking up
// the fluid state in the mipper
private record ModelEntry(List<ColourDepthTextureData> textures, int fluidBlockStateId) {
private ModelEntry(ColourDepthTextureData[] textures, int fluidBlockStateId) {
this(Stream.of(textures).map(ColourDepthTextureData::clone).toList(), fluidBlockStateId);
private record ModelEntry(ColourDepthTextureData down, ColourDepthTextureData up, ColourDepthTextureData north, ColourDepthTextureData south, ColourDepthTextureData west, ColourDepthTextureData east, int fluidBlockStateId) {
public ModelEntry(ColourDepthTextureData[] textures, int fluidBlockStateId) {
this(textures[0], textures[1], textures[2], textures[3], textures[4], textures[5], fluidBlockStateId);
}
}