More tidying up.
This commit is contained in:
parent
bf9f5aee48
commit
29e2e14c3a
@ -510,10 +510,10 @@ int main(int argc, char *argv[])
|
|||||||
openGLWidget.show();
|
openGLWidget.show();
|
||||||
|
|
||||||
//Create an empty volume and then place a sphere in it
|
//Create an empty volume and then place a sphere in it
|
||||||
Volume<MaterialDensityPair44> volData(256, 256, 256);
|
Volume<MaterialDensityPair44> volData(2048, 2048, 256);
|
||||||
//createSphereInVolume(volData, 30);
|
//createSphereInVolume(volData, 30);
|
||||||
//createPerlinTerrain(volData);
|
createPerlinTerrain(volData);
|
||||||
createPerlinVolumeSlow(volData);
|
//createPerlinVolumeSlow(volData);
|
||||||
std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl;
|
std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl;
|
||||||
volData.setBlockCacheSize(8);
|
volData.setBlockCacheSize(8);
|
||||||
std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl;
|
std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl;
|
||||||
|
@ -172,10 +172,10 @@ namespace PolyVox
|
|||||||
|
|
||||||
m_vecCompressedData.push_back(entry);
|
m_vecCompressedData.push_back(entry);
|
||||||
|
|
||||||
//Shrink the vectors to their contents (seems slow?):
|
//Shrink the vectors to their contents (maybe slow?):
|
||||||
//http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector
|
//http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector
|
||||||
//C++0x may have a shrink_to_fit() function?
|
//C++0x may have a shrink_to_fit() function?
|
||||||
//std::vector<RunlengthEntry>(m_vecCompressedData).swap(m_vecCompressedData);
|
std::vector< RunlengthEntry<uint16_t> >(m_vecCompressedData).swap(m_vecCompressedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Flag the uncompressed data as no longer being used but don't delete it (we don't own it).
|
//Flag the uncompressed data as no longer being used but don't delete it (we don't own it).
|
||||||
|
@ -170,13 +170,24 @@ namespace PolyVox
|
|||||||
public:
|
public:
|
||||||
Block<VoxelType>* getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const;
|
Block<VoxelType>* getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const;
|
||||||
|
|
||||||
VoxelType* m_pUncompressedBorderData;
|
//The block data
|
||||||
|
|
||||||
mutable std::vector< Block<VoxelType> > m_pBlocks;
|
mutable std::vector< Block<VoxelType> > m_pBlocks;
|
||||||
mutable std::vector<uint32_t> m_pUncompressedTimestamps;
|
|
||||||
|
//The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather
|
||||||
|
//than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache
|
||||||
|
//of blocks. However, this could mean the same block data is uncompressed and modified in more than one
|
||||||
|
//location in memory... could be messy with threading.
|
||||||
mutable std::vector< UncompressedBlock > m_vecUncompressedBlockCache;
|
mutable std::vector< UncompressedBlock > m_vecUncompressedBlockCache;
|
||||||
uint16_t m_uMaxUncompressedBlockCacheSize;
|
mutable std::vector<uint32_t> m_pUncompressedTimestamps;
|
||||||
|
mutable uint32_t m_uTimestamper;
|
||||||
uint32_t m_ulastAccessedBlockIndex;
|
uint32_t m_ulastAccessedBlockIndex;
|
||||||
|
uint32_t m_uMaxUncompressedBlockCacheSize;
|
||||||
|
|
||||||
|
//We don't store an actual Block for the border, just the uncompressed data. This is partly because the border
|
||||||
|
//block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a
|
||||||
|
//good chance we'll often hit it anyway. It's a chunk of homogenous data (rather than a single value) so that
|
||||||
|
//the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume.
|
||||||
|
VoxelType* m_pUncompressedBorderData;
|
||||||
|
|
||||||
uint32_t m_uNoOfBlocksInVolume;
|
uint32_t m_uNoOfBlocksInVolume;
|
||||||
|
|
||||||
@ -194,10 +205,6 @@ namespace PolyVox
|
|||||||
uint16_t m_uLongestSideLength;
|
uint16_t m_uLongestSideLength;
|
||||||
uint16_t m_uShortestSideLength;
|
uint16_t m_uShortestSideLength;
|
||||||
float m_fDiagonalLength;
|
float m_fDiagonalLength;
|
||||||
mutable uint64_t m_uTimestamper;
|
|
||||||
|
|
||||||
mutable uint32_t m_uCompressions;
|
|
||||||
mutable uint32_t m_uUncompressions;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Some handy typedefs
|
//Some handy typedefs
|
||||||
|
@ -50,8 +50,6 @@ namespace PolyVox
|
|||||||
Volume<VoxelType>::Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength)
|
Volume<VoxelType>::Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength)
|
||||||
:m_uTimestamper(0)
|
:m_uTimestamper(0)
|
||||||
,m_uMaxUncompressedBlockCacheSize(256)
|
,m_uMaxUncompressedBlockCacheSize(256)
|
||||||
,m_uCompressions(0)
|
|
||||||
,m_uUncompressions(0)
|
|
||||||
,m_uBlockSideLength(uBlockSideLength)
|
,m_uBlockSideLength(uBlockSideLength)
|
||||||
,m_pUncompressedBorderData(0)
|
,m_pUncompressedBorderData(0)
|
||||||
,m_ulastAccessedBlockIndex((std::numeric_limits<uint32_t>::max)()) //An invalid index
|
,m_ulastAccessedBlockIndex((std::numeric_limits<uint32_t>::max)()) //An invalid index
|
||||||
@ -265,7 +263,6 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
m_pBlocks[m_vecUncompressedBlockCache[ct].uBlockIndex].compress();
|
m_pBlocks[m_vecUncompressedBlockCache[ct].uBlockIndex].compress();
|
||||||
delete[] m_vecUncompressedBlockCache[ct].data;
|
delete[] m_vecUncompressedBlockCache[ct].data;
|
||||||
m_uCompressions++;
|
|
||||||
}
|
}
|
||||||
m_vecUncompressedBlockCache.clear();
|
m_vecUncompressedBlockCache.clear();
|
||||||
}
|
}
|
||||||
@ -409,7 +406,6 @@ namespace PolyVox
|
|||||||
uUncompressedBlockIndex = leastRecentlyUsedBlockIndex;
|
uUncompressedBlockIndex = leastRecentlyUsedBlockIndex;
|
||||||
m_pBlocks[m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex].compress();
|
m_pBlocks[m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex].compress();
|
||||||
m_pBlocks[m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex].m_tUncompressedData = 0;
|
m_pBlocks[m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex].m_tUncompressedData = 0;
|
||||||
m_uCompressions++;
|
|
||||||
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex = uBlockIndex;
|
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex = uBlockIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -422,11 +418,7 @@ namespace PolyVox
|
|||||||
uUncompressedBlockIndex = m_vecUncompressedBlockCache.size() - 1;
|
uUncompressedBlockIndex = m_vecUncompressedBlockCache.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//VoxelType* pData = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength];
|
|
||||||
//VoxelType* pData = &(m_pUncompressedBlockData[uUncompressedBlockIndex][0]);
|
|
||||||
//VoxelType* pData = m_pUncompressedBlockData + (m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * uUncompressedBlockIndex);
|
|
||||||
block->uncompress(m_vecUncompressedBlockCache[uUncompressedBlockIndex].data);
|
block->uncompress(m_vecUncompressedBlockCache[uUncompressedBlockIndex].data);
|
||||||
m_uUncompressions++;
|
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user