Revert "New, safer method of packing which makes careful use of casting to avoid problems with e.g. signed integer sign extension."
This reverts commit fd451be2dd7b65671274791105e76bd6a31a0f79.
This commit is contained in:
parent
fd451be2dd
commit
f574563672
@ -285,36 +285,17 @@ namespace PolyVox
|
||||
|
||||
ChunkKey posToChunkKey(int32_t iXPos, int32_t iYPos, int32_t iZPos) const
|
||||
{
|
||||
int32_t iBlockX = iXPos >> m_uChunkSideLengthPower;
|
||||
int32_t iBlockY = iYPos >> m_uChunkSideLengthPower;
|
||||
int32_t iBlockZ = iZPos >> m_uChunkSideLengthPower;
|
||||
|
||||
int16_t iBlockXAsInt16 = static_cast<int16_t>(iBlockX);
|
||||
int16_t iBlockYAsInt16 = static_cast<int16_t>(iBlockY);
|
||||
int16_t iBlockZAsInt16 = static_cast<int16_t>(iBlockZ);
|
||||
|
||||
uint16_t uBlockXAsUint16 = reinterpret_cast<uint16_t&>(iBlockXAsInt16);
|
||||
uint16_t uBlockYAsUint16 = reinterpret_cast<uint16_t&>(iBlockYAsInt16);
|
||||
uint16_t uBlockZAsUint16 = reinterpret_cast<uint16_t&>(iBlockZAsInt16);
|
||||
|
||||
uint64_t uBlockXAsUint64 = static_cast<uint64_t>(uBlockXAsUint16);
|
||||
uint64_t uBlockYAsUint64 = static_cast<uint64_t>(uBlockYAsUint16);
|
||||
uint64_t uBlockZAsUint64 = static_cast<uint64_t>(uBlockZAsUint16);
|
||||
|
||||
uBlockXAsUint64 = uBlockXAsUint64 << 32;
|
||||
uBlockYAsUint64 = uBlockYAsUint64 << 16;
|
||||
|
||||
// Bit-shifting of signed integer values has various issues with undefined or implementation-defined behaviour.
|
||||
// Therefore we cast to unsigned to avoid these (we only care about the bit pattern anyway, not the actual value).
|
||||
/*const ChunkKey uXPos = static_cast<ChunkKey>(iXPos);
|
||||
const ChunkKey uXPos = static_cast<ChunkKey>(iXPos);
|
||||
const ChunkKey uYPos = static_cast<ChunkKey>(iYPos);
|
||||
const ChunkKey uZPos = static_cast<ChunkKey>(iZPos);
|
||||
|
||||
const ChunkKey xKey = ((uXPos >> m_uChunkSideLengthPower) & 0x3FF) << 20;
|
||||
const ChunkKey yKey = ((uYPos >> m_uChunkSideLengthPower) & 0x3FF) << 10;
|
||||
const ChunkKey zKey = ((uZPos >> m_uChunkSideLengthPower) & 0x3FF);*/
|
||||
const ChunkKey zKey = ((uZPos >> m_uChunkSideLengthPower) & 0x3FF);
|
||||
|
||||
const ChunkKey key = 0xFFFF000000000000 | uBlockXAsUint64 | uBlockYAsUint64 | uBlockZAsUint64;
|
||||
const ChunkKey key = 0x80000000 | xKey | yKey | zKey;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -293,33 +293,14 @@ namespace PolyVox
|
||||
// If we still haven't found the chunk then it's time to create a new one and page it in from disk.
|
||||
if (!pChunk)
|
||||
{
|
||||
uint64_t uBlockXAsUint64 = iKeyAsInt32;
|
||||
uint64_t uBlockYAsUint64 = iKeyAsInt32;
|
||||
uint64_t uBlockZAsUint64 = iKeyAsInt32;
|
||||
|
||||
uBlockXAsUint64 = uBlockXAsUint64 >> 32;
|
||||
uBlockYAsUint64 = uBlockYAsUint64 >> 16;
|
||||
|
||||
uBlockXAsUint64 = uBlockXAsUint64 & 0xFFFF;
|
||||
uBlockYAsUint64 = uBlockYAsUint64 & 0xFFFF;
|
||||
uBlockZAsUint64 = uBlockZAsUint64 & 0xFFFF;
|
||||
|
||||
uint16_t uBlockXAsUint16 = static_cast<uint16_t>(uBlockXAsUint64);
|
||||
uint16_t uBlockYAsUint16 = static_cast<uint16_t>(uBlockYAsUint64);
|
||||
uint16_t uBlockZAsUint16 = static_cast<uint16_t>(uBlockZAsUint64);
|
||||
|
||||
int16_t uBlockXAsInt16 = reinterpret_cast<int16_t&>(uBlockXAsUint16);
|
||||
int16_t uBlockYAsInt16 = reinterpret_cast<int16_t&>(uBlockYAsUint16);
|
||||
int16_t uBlockZAsInt16 = reinterpret_cast<int16_t&>(uBlockZAsUint16);
|
||||
|
||||
/*const int32_t uChunkX = (iKeyAsInt32 >> 20) & 0x3FF;
|
||||
const int32_t uChunkX = (iKeyAsInt32 >> 20) & 0x3FF;
|
||||
const int32_t uChunkY = (iKeyAsInt32 >> 10) & 0x3FF;
|
||||
const int32_t uChunkZ = (iKeyAsInt32) & 0x3FF;*/
|
||||
const int32_t uChunkZ = (iKeyAsInt32) & 0x3FF;
|
||||
// The chunk was not found so we will create a new one.
|
||||
/*ChunkKeyConverter converter;
|
||||
converter.i = key;*/
|
||||
//ChunkKey realKey = force_cast<ChunkKey>(iKeyAsInt32);
|
||||
Vector3DInt32 v3dChunkPos(uBlockXAsInt16, uBlockYAsInt16, uBlockZAsInt16);
|
||||
Vector3DInt32 v3dChunkPos(uChunkX, uChunkY, uChunkZ);
|
||||
pChunk = new PagedVolume<VoxelType>::Chunk(v3dChunkPos, m_uChunkSideLength, m_pPager);
|
||||
pChunk->m_uChunkLastAccessed = ++m_uTimestamper; // Important, as we may soon delete the oldest chunk
|
||||
m_mapChunks.insert(std::make_pair(iKeyAsInt32, std::unique_ptr<Chunk>(pChunk)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user