Added typedef for chunk key type.
This commit is contained in:
parent
8bd8f8ba7a
commit
6419c5827b
@ -24,6 +24,8 @@ freely, subject to the following restrictions:
|
|||||||
#ifndef __PolyVox_Config_H__
|
#ifndef __PolyVox_Config_H__
|
||||||
#define __PolyVox_Config_H__
|
#define __PolyVox_Config_H__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
//#define POLYVOX_LOG_TRACE_ENABLED
|
//#define POLYVOX_LOG_TRACE_ENABLED
|
||||||
//#define POLYVOX_LOG_DEBUG_ENABLED
|
//#define POLYVOX_LOG_DEBUG_ENABLED
|
||||||
#define POLYVOX_LOG_INFO_ENABLED
|
#define POLYVOX_LOG_INFO_ENABLED
|
||||||
@ -34,4 +36,6 @@ freely, subject to the following restrictions:
|
|||||||
//#define POLYVOX_ASSERTS_ENABLED
|
//#define POLYVOX_ASSERTS_ENABLED
|
||||||
#define POLYVOX_THROW_ENABLED
|
#define POLYVOX_THROW_ENABLED
|
||||||
|
|
||||||
|
typedef int32_t PagedVolumeChunkKeyIntType;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -284,17 +284,17 @@ namespace PolyVox
|
|||||||
struct ChunkKey
|
struct ChunkKey
|
||||||
{
|
{
|
||||||
ChunkKey(int32_t x, int32_t y, int32_t z) : iZPos(z), iYPos(y), iXPos(x), iValid(~0) {}
|
ChunkKey(int32_t x, int32_t y, int32_t z) : iZPos(z), iYPos(y), iXPos(x), iValid(~0) {}
|
||||||
int32_t iZPos : 10;
|
PagedVolumeChunkKeyIntType iZPos : 10;
|
||||||
int32_t iYPos : 10;
|
PagedVolumeChunkKeyIntType iYPos : 10;
|
||||||
int32_t iXPos : 10;
|
PagedVolumeChunkKeyIntType iXPos : 10;
|
||||||
|
|
||||||
// Should only be true when the last access chunk pointer is valid,
|
// 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.
|
// so we don't need to have a seperate check for that before using it.
|
||||||
int32_t iValid : 2;
|
PagedVolumeChunkKeyIntType iValid : 2;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(ChunkKey) == sizeof(int32_t), "");
|
static_assert(sizeof(ChunkKey) == sizeof(PagedVolumeChunkKeyIntType), "");
|
||||||
|
|
||||||
int32_t posToChunkKey(int32_t iXPos, int32_t iYPos, int32_t iZPos) const
|
PagedVolumeChunkKeyIntType posToChunkKey(int32_t iXPos, int32_t iYPos, int32_t iZPos) const
|
||||||
{
|
{
|
||||||
iXPos = iXPos >> m_uChunkSideLengthPower;
|
iXPos = iXPos >> m_uChunkSideLengthPower;
|
||||||
iYPos = iYPos >> m_uChunkSideLengthPower;
|
iYPos = iYPos >> m_uChunkSideLengthPower;
|
||||||
@ -314,14 +314,14 @@ namespace PolyVox
|
|||||||
|
|
||||||
// If this kind of casting ever causes problems there are
|
// If this kind of casting ever causes problems there are
|
||||||
// other solutions here: http://stackoverflow.com/a/2468738
|
// other solutions here: http://stackoverflow.com/a/2468738
|
||||||
int32_t iKeyAsInt32 = force_cast<int32_t>(chunkKey);
|
PagedVolumeChunkKeyIntType iKeyAsInt32 = force_cast<PagedVolumeChunkKeyIntType>(chunkKey);
|
||||||
|
|
||||||
return iKeyAsInt32;
|
return iKeyAsInt32;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chunk* getChunk(int32_t iKeyAsInt32) const;
|
Chunk* getChunk(PagedVolumeChunkKeyIntType iKeyAsInt32) const;
|
||||||
|
|
||||||
mutable int32_t m_v3dLastAccessedChunkKey = 0;
|
mutable PagedVolumeChunkKeyIntType m_v3dLastAccessedChunkKey = 0;
|
||||||
mutable Chunk* m_pLastAccessedChunk = nullptr;
|
mutable Chunk* m_pLastAccessedChunk = nullptr;
|
||||||
|
|
||||||
mutable std::unordered_map<uint32_t, std::unique_ptr< Chunk > > m_mapChunks;
|
mutable std::unordered_map<uint32_t, std::unique_ptr< Chunk > > m_mapChunks;
|
||||||
|
@ -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 int32_t key = posToChunkKey(uXPos, uYPos, uZPos);
|
const PagedVolumeChunkKeyIntType 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 int32_t key = posToChunkKey(uXPos, uYPos, uZPos);
|
const PagedVolumeChunkKeyIntType 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 int32_t key = posToChunkKey(x, y, z);
|
const PagedVolumeChunkKeyIntType 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 int32_t key = posToChunkKey(x, y, z);
|
const PagedVolumeChunkKeyIntType 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(int32_t iKeyAsInt32) const
|
typename PagedVolume<VoxelType>::Chunk* PagedVolume<VoxelType>::getChunk(PagedVolumeChunkKeyIntType 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user