make main terrain taints also a bitarray

This commit is contained in:
UbitUmarov
2020-09-09 15:24:51 +01:00
parent 8b885a4c7f
commit 719e0d1c61
2 changed files with 158 additions and 57 deletions

View File

@@ -26,7 +26,7 @@
*/
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Reflection;
@@ -73,12 +73,15 @@ namespace OpenSim.Framework
private float[,] m_heightmap;
// Remember subregions of the heightmap that has changed.
private bool[,] m_taint;
private BitArray m_taint;
private int m_taintSizeX;
private int m_taintStrideForY; // stride when Y is in meters
private int m_taintSizeY;
// legacy CompressionFactor
public float CompressionFactor { get; private set; }
// Terrain always is a square
public int SizeX { get; protected set; }
public int SizeY { get; protected set; }
public int SizeZ { get; protected set; }
@@ -104,7 +107,7 @@ namespace OpenSim.Framework
if (m_heightmap[x, y] != value)
{
m_heightmap[x, y] = value;
m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true;
m_taint[x / Constants.TerrainPatchSize + y * m_taintStrideForY] = true;
}
}
}
@@ -117,19 +120,17 @@ namespace OpenSim.Framework
public void ClearTaint()
{
SetAllTaint(false);
m_taint.SetAll(false);
}
public void TaintAllTerrain()
{
SetAllTaint(true);
m_taint.SetAll(true);
}
private void SetAllTaint(bool setting)
{
for (int ii = 0; ii < m_taint.GetLength(0); ii++)
for (int jj = 0; jj < m_taint.GetLength(1); jj++)
m_taint[ii, jj] = setting;
m_taint.SetAll(setting);
}
public void ClearLand()
@@ -147,24 +148,63 @@ namespace OpenSim.Framework
// Return 'true' of the patch that contains these region coordinates has been modified.
// Note that checking the taint clears it.
// There is existing code that relies on this feature.
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAt(int xx, int yy, bool clearOnTest)
{
int tx = xx / Constants.TerrainPatchSize;
int ty = yy / Constants.TerrainPatchSize;
bool ret = m_taint[tx, ty];
int indx = xx / Constants.TerrainPatchSize + yy * m_taintStrideForY;
bool ret = m_taint[indx];
if (ret && clearOnTest)
m_taint[tx, ty] = false;
m_taint[indx] = false;
return ret;
}
// Old form that clears the taint flag when we check it.
// ubit: this dangerus naming should be only check without clear
// keeping for old modules outthere
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAt(int xx, int yy)
{
return IsTaintedAt(xx, yy, true /* clearOnTest */);
return m_taint[xx / Constants.TerrainPatchSize + yy * m_taintStrideForY];
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAtPatch(int xx, int yy, bool clearOnTest)
{
int indx = xx + yy * m_taintSizeX;
bool ret = m_taint[indx];
if (ret && clearOnTest)
m_taint[indx] = false;
return ret;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAtPatch(int xx, int yy)
{
return m_taint[xx + yy * m_taintSizeX];
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAtPatch(int indx, bool clearOnTest)
{
bool ret = m_taint[indx];
if (ret && clearOnTest)
m_taint[indx] = false;
return ret;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAtPatchWithClear(int indx)
{
if(m_taint[indx])
{
m_taint[indx] = false;
return true;
}
return false;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsTaintedAtPatch(int indx)
{
return m_taint[indx];
}
// TerrainData.GetDatabaseBlob
// The user wants something to store in the database.
public bool GetDatabaseBlob(out int DBRevisionCode, out Array blob)
@@ -306,6 +346,10 @@ namespace OpenSim.Framework
{
SizeX = pTerrain.GetLength(0);
SizeY = pTerrain.GetLength(1);
m_taintSizeX = SizeX / Constants.TerrainPatchSize;
m_taintStrideForY = m_taintSizeX / Constants.TerrainPatchSize;
m_taintSizeY = SizeY / Constants.TerrainPatchSize;
SizeZ = (int)Constants.RegionHeight;
CompressionFactor = 100.0f;
@@ -320,8 +364,7 @@ namespace OpenSim.Framework
}
// m_log.DebugFormat("{0} new by doubles. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
ClearTaint();
m_taint = new BitArray(m_taintSizeX * m_taintSizeY, false);
}
// Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that
@@ -330,11 +373,14 @@ namespace OpenSim.Framework
SizeX = pX;
SizeY = pY;
SizeZ = pZ;
m_taintSizeX = SizeX / Constants.TerrainPatchSize;
m_taintStrideForY = m_taintSizeX / Constants.TerrainPatchSize;
m_taintSizeY = SizeY / Constants.TerrainPatchSize;
CompressionFactor = 100.0f;
m_heightmap = new float[SizeX, SizeY];
m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
m_taint = new BitArray(m_taintSizeX * m_taintSizeY, false);
// m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
ClearTaint();
ClearLand(0f);
}