예제 #1
0
파일: Level.cpp 프로젝트: McTwist/PixelMap
// Working thread for the pool
ThreadResult * ThreadPoolWork(ThreadOrder * order)
{
	ThreadString * next = (ThreadString *)order;
	ChunkPrefs prefs = next->prefs;
	Chunk * chunk = next->chunk;
	chunk->pref = prefs;
	// Alpha
	if (prefs.version == ALPHA)
	{
		chunk->Load(next->file);
	}
	// Beta
	else if (prefs.version == BETA)
	{
		chunk->Load((BYTE *)next->file.c_str(), next->file.size());
	}
	if (chunk->isValid())
	{
		chunk->CreateImage();
		return (ThreadResult *)1;
	}
	return (ThreadResult *)0;
}
예제 #2
0
void ChunkManager::CreateNewChunk(int x, int y, int z) {
	ChunkCoordKey key(x, y, z);
	//std::cout << "Create chunk: " << key.x << " " << key.y << " " << key.z << std::endl;

	Chunk* chunk = new Chunk(m_renderer, this);
	chunk->SetGrid(x, y, z);

	m_chunkMapMutex.lock();
	m_chunkMap[key] = chunk;
	m_chunkMapMutex.unlock();

	chunk->Load();
	chunk->SetNeedsRebuild(true, true);
	chunk->RebuildMesh();

	// UpdateChunkNeighbors(chunk, x, y, z);
}
예제 #3
0
파일: Level.cpp 프로젝트: McTwist/PixelMap
// Load singlethreaded
void Level::LoadSingle()
{
	// Go through all files
	Chunk * temp = 0;
	while (files.empty() == false && cancel == false)
	{
		if (prefs.version == ALPHA)
		{
			temp = new Chunk();
			// Load chunk
			temp->pref = prefs;
			temp->Load(files.top());
			files.pop();
			// Everything is fine
			if (temp->isValid())
			{
				temp->CreateImage();
				chunks.push_back(temp);
			}
			else
			{
				// Display correct total chunks
				--total;
				// Evade memory leak
				delete temp;
			}
			// Do some aftermath
			result = chunks.size();
			work = total - result;
			done = ((float)result/(float)total);
		}
		else if (prefs.version == BETA)
		{
			RegionReader region = RegionReader();
			region.Load(files.top());
			files.pop();
			// Reduce amount
			total -= 1024 - region.GetAmountChunks();
			// Go through region
			for (int i = 0; i < region.GetAmountChunks() && cancel == false; ++i)
			{
				temp = new Chunk();
				// Load chunk
				temp->pref = prefs;
				UINT size = 0;
				BYTE * data = region.GetChunk(i, size);
				temp->Load(data, size);
				// Everything is fine
				if (temp->isValid())
				{
					temp->CreateImage();
					chunks.push_back(temp);
				}
				else
				{
					// Display correct total chunks
					--total;
					// Evade memory leak
					delete temp;
				}
				// Do some aftermath
				result = chunks.size();
				work = total - result;
				done = ((float)result/(float)total);
			}
		}
	}
}