public void SetVoxelContent(byte content, ref Vector3I voxelCoordInCell)
{
content = MyVoxelContentCellContent.QuantizedValue(content);
if (this.CellType == MyVoxelCellType.FULL)
{
if (content == MyVoxelConstants.VOXEL_CONTENT_FULL)
{
// Nothing is changing
return;
}
else
{
this._voxelContentSum -= (MyVoxelConstants.VOXEL_CONTENT_FULL - content);
this.CheckCellType();
// If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
if (this.CellType == MyVoxelCellType.MIXED)
{
this._cellContent = new MyVoxelContentCellContent(); // MyVoxelContentCellContents.Allocate();
if (this._cellContent != null)
{
this._cellContent.Reset(MyVoxelConstants.VOXEL_CONTENT_FULL);
this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
}
}
}
}
else if (this.CellType == MyVoxelCellType.EMPTY)
{
if (content == MyVoxelConstants.VOXEL_CONTENT_EMPTY)
{
// Nothing is changing
return;
}
else
{
this._voxelContentSum += content;
this.CheckCellType();
// If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
if (this.CellType == MyVoxelCellType.MIXED)
{
this._cellContent = new MyVoxelContentCellContent(); //MyVoxelContentCellContents.Allocate();
if (this._cellContent != null)
{
this._cellContent.Reset(MyVoxelConstants.VOXEL_CONTENT_EMPTY);
this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
}
}
}
}
else if (this.CellType == MyVoxelCellType.MIXED)
{
if (this._cellContent == null)
{
return;
}
// Check for previous content value not only for optimisation, but because we need to know how much it changed
// for calculating whole cell content summary.
var previousContent = this._cellContent.GetVoxelContent(ref voxelCoordInCell);
if (previousContent == content)
{
// New value is same as current, so nothing needs to be changed
return;
}
this._voxelContentSum -= previousContent - content;
this.CheckCellType();
// If this cell is still mixed, we change voxel's value in the cell content array
if (this.CellType == MyVoxelCellType.MIXED)
{
this._cellContent.SetVoxelContent(content, ref voxelCoordInCell);
}
}
else
{
throw new NotImplementedException();
}
}