Revert "Added typedef for ChunkKey."
This reverts commit 905ec27f47a3e2dc1cba3a3a384b2c7532dab03d.
This commit is contained in:
parent
f574563672
commit
0c619ebec7
@ -281,31 +281,42 @@ namespace PolyVox
|
|||||||
PagedVolume& operator=(const PagedVolume& rhs);
|
PagedVolume& operator=(const PagedVolume& rhs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef uint64_t ChunkKey;
|
/*struct ChunkKey
|
||||||
|
{
|
||||||
|
ChunkKey(int32_t x, int32_t y, int32_t z) : iZPos(z), iYPos(y), iXPos(x), iValid(~0) {}
|
||||||
|
int64_t iZPos : 10;
|
||||||
|
int64_t iYPos : 10;
|
||||||
|
int64_t iXPos : 10;
|
||||||
|
|
||||||
ChunkKey posToChunkKey(int32_t iXPos, int32_t iYPos, int32_t iZPos) const
|
// Should only be true when the last access chunk pointer is valid,
|
||||||
|
// so we don't need to have a seperate check for that before using it.
|
||||||
|
int64_t iValid : 2;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(ChunkKey) == sizeof(int64_t), "");*/
|
||||||
|
|
||||||
|
uint64_t posToChunkKey(int32_t iXPos, int32_t iYPos, int32_t iZPos) const
|
||||||
{
|
{
|
||||||
// Bit-shifting of signed integer values has various issues with undefined or implementation-defined behaviour.
|
// 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).
|
// 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 uint64_t uXPos = static_cast<uint64_t>(iXPos);
|
||||||
const ChunkKey uYPos = static_cast<ChunkKey>(iYPos);
|
const uint64_t uYPos = static_cast<uint64_t>(iYPos);
|
||||||
const ChunkKey uZPos = static_cast<ChunkKey>(iZPos);
|
const uint64_t uZPos = static_cast<uint64_t>(iZPos);
|
||||||
|
|
||||||
const ChunkKey xKey = ((uXPos >> m_uChunkSideLengthPower) & 0x3FF) << 20;
|
const uint64_t xKey = ((uXPos >> m_uChunkSideLengthPower) & 0x3FF) << 20;
|
||||||
const ChunkKey yKey = ((uYPos >> m_uChunkSideLengthPower) & 0x3FF) << 10;
|
const uint64_t yKey = ((uYPos >> m_uChunkSideLengthPower) & 0x3FF) << 10;
|
||||||
const ChunkKey zKey = ((uZPos >> m_uChunkSideLengthPower) & 0x3FF);
|
const uint64_t zKey = ((uZPos >> m_uChunkSideLengthPower) & 0x3FF);
|
||||||
|
|
||||||
const ChunkKey key = 0x80000000 | xKey | yKey | zKey;
|
const uint64_t key = 0x80000000 | xKey | yKey | zKey;
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chunk* getChunk(ChunkKey iKeyAsInt32) const;
|
Chunk* getChunk(uint64_t iKeyAsInt32) const;
|
||||||
|
|
||||||
mutable ChunkKey m_v3dLastAccessedChunkKey = 0;
|
mutable uint64_t m_v3dLastAccessedChunkKey = 0;
|
||||||
mutable Chunk* m_pLastAccessedChunk = nullptr;
|
mutable Chunk* m_pLastAccessedChunk = nullptr;
|
||||||
|
|
||||||
mutable std::unordered_map<ChunkKey, std::unique_ptr< Chunk > > m_mapChunks;
|
mutable std::unordered_map<uint64_t, std::unique_ptr< Chunk > > m_mapChunks;
|
||||||
|
|
||||||
mutable uint32_t m_uTimestamper = 0;
|
mutable uint32_t m_uTimestamper = 0;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType PagedVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
VoxelType PagedVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||||
{
|
{
|
||||||
const ChunkKey key = posToChunkKey(uXPos, uYPos, uZPos);
|
const uint64_t key = posToChunkKey(uXPos, uYPos, uZPos);
|
||||||
|
|
||||||
// Only call get chunk if we can't reuse the chunk pointer from the last voxel access.
|
// Only call get chunk if we can't reuse the chunk pointer from the last voxel access.
|
||||||
auto pChunk = (key == m_v3dLastAccessedChunkKey) ? m_pLastAccessedChunk : getChunk(key);
|
auto pChunk = (key == m_v3dLastAccessedChunkKey) ? m_pLastAccessedChunk : getChunk(key);
|
||||||
@ -147,7 +147,7 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void PagedVolume<VoxelType>::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
void PagedVolume<VoxelType>::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
||||||
{
|
{
|
||||||
const ChunkKey key = posToChunkKey(uXPos, uYPos, uZPos);
|
const uint64_t key = posToChunkKey(uXPos, uYPos, uZPos);
|
||||||
|
|
||||||
// Only call get chunk if we can't reuse the chunk pointer from the last voxel access.
|
// Only call get chunk if we can't reuse the chunk pointer from the last voxel access.
|
||||||
auto pChunk = (key == m_v3dLastAccessedChunkKey) ? m_pLastAccessedChunk : getChunk(key);
|
auto pChunk = (key == m_v3dLastAccessedChunkKey) ? m_pLastAccessedChunk : getChunk(key);
|
||||||
@ -202,7 +202,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
|
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
|
||||||
{
|
{
|
||||||
const ChunkKey key = posToChunkKey(x, y, z);
|
const uint64_t key = posToChunkKey(x, y, z);
|
||||||
|
|
||||||
// Note that we don't check against the last chunk here. We're
|
// Note that we don't check against the last chunk here. We're
|
||||||
// not accessing the voxels, we just want to pull them into memory.
|
// not accessing the voxels, we just want to pull them into memory.
|
||||||
@ -256,7 +256,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
|
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
|
||||||
{
|
{
|
||||||
const ChunkKey key = posToChunkKey(x, y, z);
|
const uint64_t key = posToChunkKey(x, y, z);
|
||||||
m_mapChunks.erase(key);
|
m_mapChunks.erase(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
typename PagedVolume<VoxelType>::Chunk* PagedVolume<VoxelType>::getChunk(ChunkKey iKeyAsInt32) const
|
typename PagedVolume<VoxelType>::Chunk* PagedVolume<VoxelType>::getChunk(uint64_t iKeyAsInt32) const
|
||||||
{
|
{
|
||||||
// This function is relatively large and slow because it involves searching for a chunk and creating it if it is not found. A natural
|
// This function is relatively large and slow because it involves searching for a chunk and creating it if it is not found. A natural
|
||||||
// optimization is to only do this work if the chunk we are accessing is not the same as the last chunk we accessed (which it usually
|
// optimization is to only do this work if the chunk we are accessing is not the same as the last chunk we accessed (which it usually
|
||||||
|
@ -97,7 +97,7 @@ namespace PolyVox
|
|||||||
// Base version updates position and validity flags.
|
// Base version updates position and validity flags.
|
||||||
BaseVolume<VoxelType>::template Sampler< PagedVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
|
BaseVolume<VoxelType>::template Sampler< PagedVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
|
||||||
|
|
||||||
const ChunkKey key = this->mVolume->posToChunkKey(xPos, yPos, zPos);
|
const uint64_t key = this->mVolume->posToChunkKey(xPos, yPos, zPos);
|
||||||
|
|
||||||
// Then we update the voxel pointer.
|
// Then we update the voxel pointer.
|
||||||
auto pCurrentChunk = (key == this->mVolume->m_v3dLastAccessedChunkKey) ? this->mVolume->m_pLastAccessedChunk : this->mVolume->getChunk(key);
|
auto pCurrentChunk = (key == this->mVolume->m_v3dLastAccessedChunkKey) ? this->mVolume->m_pLastAccessedChunk : this->mVolume->getChunk(key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user