Ejemplo n.º 1
0
cWSSAnvil::cMCAFile * cWSSAnvil::LoadMCAFile(const cChunkCoords & a_Chunk)
{
    // ASSUME m_CS is locked
    ASSERT(m_CS.IsLocked());

    const int RegionX = FAST_FLOOR_DIV(a_Chunk.m_ChunkX, 32);
    const int RegionZ = FAST_FLOOR_DIV(a_Chunk.m_ChunkZ, 32);
    ASSERT(a_Chunk.m_ChunkX - RegionX * 32 >= 0);
    ASSERT(a_Chunk.m_ChunkZ - RegionZ * 32 >= 0);
    ASSERT(a_Chunk.m_ChunkX - RegionX * 32 < 32);
    ASSERT(a_Chunk.m_ChunkZ - RegionZ * 32 < 32);

    // Is it already cached?
    for (cMCAFiles::iterator itr = m_Files.begin(); itr != m_Files.end(); ++itr)
    {
        if (((*itr) != NULL) && ((*itr)->GetRegionX() == RegionX) && ((*itr)->GetRegionZ() == RegionZ))
        {
            // Move the file to front and return it:
            cMCAFile * f = *itr;
            if (itr != m_Files.begin())
            {
                m_Files.erase(itr);
                m_Files.push_front(f);
            }
            return f;
        }
    }

    // Load it anew:
    AString FileName;
    Printf(FileName, "%s/region", m_World->GetName().c_str());
    cFile::CreateFolder(FILE_IO_PREFIX + FileName);
    AppendPrintf(FileName, "/r.%d.%d.mca", RegionX, RegionZ);
    cMCAFile * f = new cMCAFile(FileName, RegionX, RegionZ);
    if (f == NULL)
    {
        return NULL;
    }
    m_Files.push_front(f);

    // If there are too many MCA files cached, delete the last one used:
    if (m_Files.size() > MAX_MCA_FILES)
    {
        delete m_Files.back();
        m_Files.pop_back();
    }
    return f;
}
Ejemplo n.º 2
0
cWSSCompact::cPAKFile * cWSSCompact::LoadPAKFile(const cChunkCoords & a_Chunk)
{
	// 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
	const int LayerX = FAST_FLOOR_DIV(a_Chunk.m_ChunkX, 32);
	const int LayerZ = FAST_FLOOR_DIV(a_Chunk.m_ChunkZ, 32);
	
	// Is it already cached?
	for (cPAKFiles::iterator itr = m_PAKFiles.begin(); itr != m_PAKFiles.end(); ++itr)
	{
		if (((*itr) != NULL) && ((*itr)->GetLayerX() == LayerX) && ((*itr)->GetLayerZ() == LayerZ))
		{
			// Move the file to front and return it:
			cPAKFile * f = *itr;
			if (itr != m_PAKFiles.begin())
			{
				m_PAKFiles.erase(itr);
				m_PAKFiles.push_front(f);
			}
			return f;
		}
	}
	
	// Load it anew:
	AString FileName;
	Printf(FileName, "%s/X%i_Z%i.pak", m_World->GetName().c_str(), LayerX, LayerZ );
	cPAKFile * f = new cPAKFile(FileName, LayerX, LayerZ, m_CompressionFactor);
	if (f == NULL)
	{
		return NULL;
	}
	m_PAKFiles.push_front(f);
	
	// If there are too many PAK files cached, delete the last one used:
	if (m_PAKFiles.size() > MAX_PAK_FILES)
	{
		delete m_PAKFiles.back();
		m_PAKFiles.pop_back();
	}
	return f;
}