
/*
 * Copyright 2011-2022 Cuberite Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "Globals.h"
#include "RegionLoader.h"
#include "ChunkSource.h"
#include "Region.h"





volatile bool RegionLoader::m_IsShuttingDown = false;





RegionLoader::RegionLoader(int a_RegionX, int a_RegionZ, RegionPtr a_Region, ChunkSourcePtr a_ChunkSource) :
	m_RegionX(a_RegionX),
	m_RegionZ(a_RegionZ),
	m_Region(a_Region),
	m_ChunkSource(a_ChunkSource)
{
}





void RegionLoader::run()
{
	// Load all the chunks in this region:
	for (int z = 0; z < 32; z++)
	{
		for (int x = 0; x < 32; x++)
		{
			m_ChunkSource->getChunkBiomes(m_RegionX * 32 + x, m_RegionZ * 32 + z, m_Region->getRelChunk(x, z));
			if (m_IsShuttingDown)
			{
				return;
			}
		}
	}
	m_Region->m_IsValid = true;

	emit loaded(m_RegionX, m_RegionZ);
}




