refactor(content): share EnvCell geometry identity
This commit is contained in:
parent
05a22dee99
commit
86fadf8661
3 changed files with 73 additions and 8 deletions
29
src/AcDream.Core/Rendering/Wb/EnvCellGeometryIdentity.cs
Normal file
29
src/AcDream.Core/Rendering/Wb/EnvCellGeometryIdentity.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue