29 lines
1 KiB
C#
29 lines
1 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace AcDream.Core.Rendering.Wb;
|
|
|
|
/// <summary>
|
|
/// Computes WorldBuilder's content identity for an EnvCell shell.
|
|
/// Equal environment, cell-structure, and ordered surface tuples share one
|
|
/// prepared geometry payload even when they occur under different cell IDs.
|
|
/// </summary>
|
|
public static class EnvCellGeometryIdentity
|
|
{
|
|
/// <summary>
|
|
/// Source: WorldBuilder <c>EnvCellRenderManager.GetEnvCellGeomId</c>,
|
|
/// lines 94-103. Bit 33 separates content identities from per-cell IDs,
|
|
/// whose synthetic geometry requests use bit 32.
|
|
/// </summary>
|
|
public static ulong Compute(
|
|
uint environmentId,
|
|
ushort cellStructure,
|
|
IReadOnlyList<ushort> surfaces)
|
|
{
|
|
long hash = 17;
|
|
hash = unchecked(hash * 31 + environmentId);
|
|
hash = unchecked(hash * 31 + cellStructure);
|
|
for (int i = 0; i < surfaces.Count; i++)
|
|
hash = unchecked(hash * 31 + surfaces[i]);
|
|
return (ulong)hash | 0x2_0000_0000UL;
|
|
}
|
|
}
|