UE网络-零散的积累

动态压缩Vector

根据FVector三个分量的最大值, 压缩Vector, 节省带宽. 这里还要注意一点, 当数值比较大时, 可能压缩后比压缩前占用的bit数量还要大, 即更占用带宽.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// FRepMovement.SerializeQuantizedVector 
bool SerializeQuantizedVector(FArchive& Ar, FVector& Vector, EVectorQuantization QuantizationLevel)
{
// Since FRepMovement used to use FVector_NetQuantize100, we're allowing enough bits per component
// regardless of the quantization level so that we can still support at least the same maximum magnitude
// (2^30 / 100, or ~10 million).
// This uses no inherent extra bandwidth since we're still using the same number of bits to store the
// bits-per-component value. Of course, larger magnitudes will still use more bandwidth,
// as has always been the case.
// 因为FrepMovement使用过FVector_NetQuantize100, 允许每个分量有足够多的bit来忽略量化登记, 所以仍然支持至少同等量级.
// 他不会使用额外带宽, 因为我们已经使用同等数量的bit来存储每个分量的bit值. 当然, 更大量级将会使用更多带宽.
switch(QuantizationLevel)
{
case EVectorQuantization::RoundTwoDecimals:
{ // 保留两位小数
return SerializePackedVector<100, 30>(Vector, Ar);
}

case EVectorQuantization::RoundOneDecimal:
{ // 保留一位小数
return SerializePackedVector<10, 27>(Vector, Ar);
}

default:
{ // 默认不保留小数
return SerializePackedVector<1, 24>(Vector, Ar);
}
}
}

详细解析WritePackedVector函数.