Made FAST_FLOOR_DIV work correctly, replaced all floorf() divisions with it.
Still not perfect - chunk and region calculations can be made into a single CPU instruction - SAR - but not all compilers are known to support that (">>" operator on signed datatypes needs to perform arithmetic shift, C/C++ standard makes it implementation-specific; MSVC and GCC do what we need, LLVM unknown) git-svn-id: http://mc-server.googlecode.com/svn/trunk@1224 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
24d3d5dac4
commit
71cd0199fd
@ -87,8 +87,8 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayer(int a_LayerX, int a_LayerZ)
|
|||||||
|
|
||||||
cChunkMap::cChunkLayer * cChunkMap::FindLayerForChunk(int a_ChunkX, int a_ChunkZ)
|
cChunkMap::cChunkLayer * cChunkMap::FindLayerForChunk(int a_ChunkX, int a_ChunkZ)
|
||||||
{
|
{
|
||||||
const int LayerX = (int)(floorf((float)a_ChunkX / (float)(LAYER_SIZE)));
|
const int LayerX = FAST_FLOOR_DIV(a_ChunkX, LAYER_SIZE);
|
||||||
const int LayerZ = (int)(floorf((float)a_ChunkZ / (float)(LAYER_SIZE)));
|
const int LayerZ = FAST_FLOOR_DIV(a_ChunkZ, LAYER_SIZE);
|
||||||
return FindLayer(LayerX, LayerZ);
|
return FindLayer(LayerX, LayerZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +118,9 @@ cChunkMap::cChunkLayer * cChunkMap::FindLayer(int a_LayerX, int a_LayerZ)
|
|||||||
|
|
||||||
cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ)
|
cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ)
|
||||||
{
|
{
|
||||||
const int LayerX = (int)(floorf((float)a_ChunkX / (float)(LAYER_SIZE)));
|
const int LayerX = FAST_FLOOR_DIV(a_ChunkX, LAYER_SIZE);
|
||||||
const int LayerZ = (int)(floorf((float)a_ChunkZ / (float)(LAYER_SIZE)));
|
const int LayerZ = FAST_FLOOR_DIV(a_ChunkX, LAYER_SIZE);
|
||||||
return GetLayer( LayerX, LayerZ );
|
return GetLayer(LayerX, LayerZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,8 +276,8 @@ void cClientHandle::StreamChunks(void)
|
|||||||
|
|
||||||
ASSERT(m_Player != NULL);
|
ASSERT(m_Player != NULL);
|
||||||
|
|
||||||
int ChunkPosX = FAST_FLOOR_DIV(m_Player->GetPosX(), cChunkDef::Width);
|
int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width);
|
||||||
int ChunkPosZ = FAST_FLOOR_DIV(m_Player->GetPosZ(), cChunkDef::Width);
|
int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width);
|
||||||
if ((ChunkPosX == m_LastStreamedChunkX) && (ChunkPosZ == m_LastStreamedChunkZ))
|
if ((ChunkPosX == m_LastStreamedChunkX) && (ChunkPosZ == m_LastStreamedChunkZ))
|
||||||
{
|
{
|
||||||
// Already streamed for this position
|
// Already streamed for this position
|
||||||
|
@ -189,9 +189,10 @@ typedef unsigned short UInt16;
|
|||||||
|
|
||||||
/// Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it, "(32 KiB)" )
|
/// Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it, "(32 KiB)" )
|
||||||
#define KiB * 1024
|
#define KiB * 1024
|
||||||
|
#define MiB * 1024 * 1024
|
||||||
|
|
||||||
/// Faster than (int)floorf((float)x / (float)div)
|
/// Faster than (int)floorf((float)x / (float)div)
|
||||||
#define FAST_FLOOR_DIV( x, div ) ( (x) < 0 ? (((int)x / div) - 1) : ((int)x / div) )
|
#define FAST_FLOOR_DIV( x, div ) (((x) - (((x) < 0) ? ((div) - 1) : 0)) / (div))
|
||||||
|
|
||||||
// Own version of assert() that writes failed assertions to the log for review
|
// Own version of assert() that writes failed assertions to the log for review
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -388,9 +388,10 @@ bool cWSSAnvil::SetChunkData(const cChunkCoords & a_Chunk, const AString & a_Dat
|
|||||||
cWSSAnvil::cMCAFile * cWSSAnvil::LoadMCAFile(const cChunkCoords & a_Chunk)
|
cWSSAnvil::cMCAFile * cWSSAnvil::LoadMCAFile(const cChunkCoords & a_Chunk)
|
||||||
{
|
{
|
||||||
// ASSUME m_CS is locked
|
// ASSUME m_CS is locked
|
||||||
|
ASSERT(m_CS.IsLocked());
|
||||||
|
|
||||||
const int RegionX = (int)(floorf((float)a_Chunk.m_ChunkX / 32.0f));
|
const int RegionX = FAST_FLOOR_DIV(a_Chunk.m_ChunkX, 32);
|
||||||
const int RegionZ = (int)(floorf((float)a_Chunk.m_ChunkZ / 32.0f));
|
const int RegionZ = FAST_FLOOR_DIV(a_Chunk.m_ChunkZ, 32);
|
||||||
|
|
||||||
// Is it already cached?
|
// Is it already cached?
|
||||||
for (cMCAFiles::iterator itr = m_Files.begin(); itr != m_Files.end(); ++itr)
|
for (cMCAFiles::iterator itr = m_Files.begin(); itr != m_Files.end(); ++itr)
|
||||||
|
@ -171,8 +171,8 @@ cWSSCompact::cPAKFile * cWSSCompact::LoadPAKFile(const cChunkCoords & a_Chunk)
|
|||||||
// ASSUMES that m_CS has been locked
|
// ASSUMES that m_CS has been locked
|
||||||
|
|
||||||
// We need to retain this weird conversion code, because some edge chunks are in the wrong PAK file
|
// We need to retain this weird conversion code, because some edge chunks are in the wrong PAK file
|
||||||
const int LayerX = (int)(floorf((float)a_Chunk.m_ChunkX / 32.0f));
|
const int LayerX = FAST_FLOOR_DIV(a_Chunk.m_ChunkX, 32);
|
||||||
const int LayerZ = (int)(floorf((float)a_Chunk.m_ChunkZ / 32.0f));
|
const int LayerZ = FAST_FLOOR_DIV(a_Chunk.m_ChunkZ, 32);
|
||||||
|
|
||||||
// Is it already cached?
|
// Is it already cached?
|
||||||
for (cPAKFiles::iterator itr = m_PAKFiles.begin(); itr != m_PAKFiles.end(); ++itr)
|
for (cPAKFiles::iterator itr = m_PAKFiles.begin(); itr != m_PAKFiles.end(); ++itr)
|
||||||
|
Loading…
Reference in New Issue
Block a user