示例#1
0
// World editing
void Player::DestroyBlock()
{
	if (m_blockSelection)
	{
		Chunk* pChunk = m_pChunkManager->GetChunkFromPosition(m_blockSelectionPos.x, m_blockSelectionPos.y, m_blockSelectionPos.z);

		if (pChunk != NULL)
		{
			int blockX, blockY, blockZ;
			vec3 blockPos;
			bool active = m_pChunkManager->GetBlockActiveFrom3DPosition(m_blockSelectionPos.x, m_blockSelectionPos.y, m_blockSelectionPos.z, &blockPos, &blockX, &blockY, &blockZ, &pChunk);
			if (active)
			{
				float r;
				float g;
				float b;
				float a;
				pChunk->GetColour(blockX, blockY, blockZ, &r, &g, &b, &a);

				pChunk->StartBatchUpdate();
				pChunk->SetColour(blockX, blockY, blockZ, 0);
				pChunk->StopBatchUpdate();

				m_pChunkManager->CreateBlockDestroyParticleEffect(r, g, b, a, m_blockSelectionPos);

				// Create the collectible block item
				BlockType blockType = pChunk->GetBlockType(blockX, blockY, blockZ);
				m_pChunkManager->CreateCollectibleBlock(blockType, m_blockSelectionPos);
			}
		}

		m_blockSelection = false;
	}
}
示例#2
0
// Importing into the world chunks
void ChunkManager::ImportQubicleBinaryMatrix(QubicleMatrix* pMatrix, vec3 position, QubicleImportDirection direction)
{
	bool mirrorX = false;
	bool mirrorY = false;
	bool mirrorZ = false;
	bool flipXZ = false;
	bool flipXY = false;
	bool flipYZ = false;

	switch (direction)
	{
	case QubicleImportDirection_Normal: {  } break;
	case QubicleImportDirection_MirrorX: { mirrorX = true; } break;
	case QubicleImportDirection_MirrorY: { mirrorY = true; } break;
	case QubicleImportDirection_MirrorZ: { mirrorZ = true; } break;
	case QubicleImportDirection_RotateY90: { mirrorX = true; flipXZ = true; } break;
	case QubicleImportDirection_RotateY180: { mirrorX = true; mirrorZ = true; } break;
	case QubicleImportDirection_RotateY270: { mirrorZ = true; flipXZ = true; } break;
	case QubicleImportDirection_RotateX90: { mirrorZ = true; flipYZ = true; } break;
	case QubicleImportDirection_RotateX180: { mirrorZ = true; mirrorY = true; } break;
	case QubicleImportDirection_RotateX270: { mirrorY = true; flipYZ = true; } break;
	case QubicleImportDirection_RotateZ90: { mirrorY = true; flipXY = true; } break;
	case QubicleImportDirection_RotateZ180: { mirrorX = true; mirrorY = true; } break;
	case QubicleImportDirection_RotateZ270: { mirrorX = true; flipXY = true; } break;
	}

	ChunkList vChunkBatchUpdateList;

	float r = 1.0f;
	float g = 1.0f;
	float b = 1.0f;
	float a = 1.0f;

	unsigned int xValueToUse = pMatrix->m_matrixSizeX;
	unsigned int yValueToUse = pMatrix->m_matrixSizeY;
	unsigned int zValueToUse = pMatrix->m_matrixSizeZ;
	if (flipXZ)
	{
		xValueToUse = pMatrix->m_matrixSizeZ;
		zValueToUse = pMatrix->m_matrixSizeX;
	}
	if (flipXY)
	{
		xValueToUse = pMatrix->m_matrixSizeY;
		yValueToUse = pMatrix->m_matrixSizeX;
	}
	if (flipYZ)
	{
		yValueToUse = pMatrix->m_matrixSizeZ;
		zValueToUse = pMatrix->m_matrixSizeY;
	}

	int xPosition = 0;
	if (mirrorX)
		xPosition = xValueToUse - 1;

	for (unsigned int x = 0; x < xValueToUse; x++)
	{
		int yPosition = 0;
		if (mirrorY)
			yPosition = yValueToUse - 1;

		for (unsigned int y = 0; y < yValueToUse; y++)
		{
			int zPosition = 0;
			if (mirrorZ)
				zPosition = zValueToUse - 1;

			for (unsigned int z = 0; z < zValueToUse; z++)
			{
				int xPosition_modified = xPosition;
				int yPosition_modified = yPosition;
				int zPosition_modified = zPosition;
				if (flipXZ)
				{
					xPosition_modified = zPosition;
					zPosition_modified = xPosition;
				}
				if (flipXY)
				{
					xPosition_modified = yPosition;
					yPosition_modified = xPosition;
				}
				if (flipYZ)
				{
					yPosition_modified = zPosition;
					zPosition_modified = yPosition;
				}

				if (pMatrix->GetActive(xPosition_modified, yPosition_modified, zPosition_modified) == false)
				{
					// Do nothing
				}
				else
				{
					unsigned int colour = pMatrix->GetColourCompact(xPosition_modified, yPosition_modified, zPosition_modified);

					vec3 blockPos = position - vec3((xValueToUse + 0.05f)*0.5f, 0.0f, (zValueToUse + 0.05f)*0.5f) + vec3(x*Chunk::BLOCK_RENDER_SIZE*2.0f, y*Chunk::BLOCK_RENDER_SIZE*2.0f, z*Chunk::BLOCK_RENDER_SIZE*2.0f);

					vec3 blockPosition;
					int blockX, blockY, blockZ;
					Chunk* pChunk = NULL;
					bool blockActive = GetBlockActiveFrom3DPosition(blockPos.x, blockPos.y, blockPos.z, &blockPosition, &blockX, &blockY, &blockZ, &pChunk);

					if (pChunk != NULL)
					{
						pChunk->SetColour(blockX, blockY, blockZ, colour);

						// Add to batch update list (no duplicates)
						bool found = false;
						for (int i = 0; i < (int)vChunkBatchUpdateList.size() && found == false; i++)
						{
							if (vChunkBatchUpdateList[i] == pChunk)
							{
								found = true;
							}
						}
						if (found == false)
						{
							vChunkBatchUpdateList.push_back(pChunk);
							pChunk->StartBatchUpdate();
						}
					}
					else
					{
						// Add to the chunk storage
						int gridX;
						int gridY;
						int gridZ;
						GetGridFromPosition(blockPos, &gridX, &gridY, &gridZ);
						ChunkStorageLoader* pStorage = GetChunkStorage(gridX, gridY, gridZ, true);

						if (pStorage != NULL)
						{
							GetBlockGridFrom3DPositionChunkStorage(blockPos.x, blockPos.y, blockPos.z, &blockX, &blockY, &blockZ, pStorage);

							pStorage->SetBlockColour(blockX, blockY, blockZ, colour);
						}
					}
				}

				if (mirrorZ)
					zPosition--;
				else
					zPosition++;
			}

			if (mirrorY)
				yPosition--;
			else
				yPosition++;
		}

		if (mirrorX)
			xPosition--;
		else
			xPosition++;
	}

	for (int i = 0; i < (int)vChunkBatchUpdateList.size(); i++)
	{
		vChunkBatchUpdateList[i]->StopBatchUpdate();
	}
	vChunkBatchUpdateList.clear();
}