Skip to content

Commit

Permalink
increase bit width of stacked species texture hash
Browse files Browse the repository at this point in the history
  • Loading branch information
parzivail committed Jan 17, 2023
1 parent b699ae9 commit 572c75e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,27 @@ protected static Identifier getClothes(SwgSpecies species, PlayerEntity player)
);
}

private static int hashVariableValues(SwgSpecies species, SpeciesVariable... variables)
private static long longHashCode(String s)
{
var hash = 0;
var h = 0L;
for (byte v : s.getBytes())
h = 31 * h + (v & 0xff);
return h;
}

private static long hashVariableValues(SwgSpecies species, SpeciesVariable... variables)
{
var hash = 0L;
for (var variable : variables)
hash = 31 * hash + species.getVariable(variable).hashCode();
hash = 31 * hash + longHashCode(species.getVariable(variable));
return hash;
}

private static long hashVariableValues(Map<String, String> variables)
{
var hash = 0L;
for (var variable : variables.entrySet())
hash = 31 * hash + longHashCode(variable.getKey() + "=" + variable.getValue());
return hash;
}

Expand Down Expand Up @@ -273,9 +289,14 @@ public boolean equals(Object o)
@Override
public int hashCode()
{
var result = getSlug().hashCode();
return (int)longHashCode();
}

public long longHashCode()
{
var result = longHashCode(getSlug().toString());
result = 31 * result + gender.hashCode();
result = 31 * result + variables.hashCode();
result = 31 * result + hashVariableValues(variables);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private static void register(Identifier speciesSlug, Supplier<PlayerEntityModel<

public static Identifier getTexture(PlayerEntity player, SwgSpecies species)
{
var hashCode = species.hashCode();
return Client.stackedTextureProvider.getId(String.format("species/%08x", hashCode), () -> Client.TEX_TRANSPARENT, () -> species.getTextureStack(player));
var hashCode = species.longHashCode();
return Client.stackedTextureProvider.getId(String.format("species/%016x", hashCode), () -> Client.TEX_TRANSPARENT, () -> species.getTextureStack(player));
}

public static void animateTwilek(AbstractClientPlayerEntity entity, PlayerEntityModel<AbstractClientPlayerEntity> model, PlayerSpeciesModelRenderer renderer, float tickDelta)
Expand Down

0 comments on commit 572c75e

Please sign in to comment.