a few more changes on terrain

This commit is contained in:
UbitUmarov
2025-03-29 23:29:42 +00:00
parent 207a318f86
commit 9a02b55bf2
7 changed files with 79 additions and 54 deletions

View File

@@ -31,8 +31,6 @@ using System.IO;
using System.IO.Compression;
using System.Reflection;
using OpenMetaverse;
using log4net;
namespace OpenSim.Framework
@@ -361,30 +359,35 @@ namespace OpenSim.Framework
public unsafe void GetPatchMinMax(int px, int py, out float zmin, out float zmax)
{
zmax = float.MinValue;
zmin = float.MaxValue;
int mpy = Constants.TerrainPatchSize * py;
float min, max;
fixed (float* map = m_heightmap)
{
float* p = map + px * m_mapPatchsStride;
float* pend = p + m_mapPatchsStride;
while (p < pend)
float* p = map + px * m_mapPatchsStride + Constants.TerrainPatchSize * py;
float* endp = p + m_mapPatchsStride;
min = max = *p;
float* y = p;
int j = Constants.TerrainPatchSize - 1;
do
{
float* yt = p + mpy;
float* ytend = yt + 16;
while(yt < ytend)
do
{
float val = *yt;
if (val > zmax)
zmax = val;
if (val < zmin)
zmin = val;
yt++;
float val = *y++;
if (val > max)
max = val;
else if (val < min)
min = val;
}
while(--j > 0);
p += m_mapStride;
y = p;
j = Constants.TerrainPatchSize;
}
while (p < endp);
}
zmin = min;
zmax = max;
}
public unsafe void GetPatchBlock(float* block, int px, int py, float sub, float premult)

View File

@@ -26,6 +26,8 @@
*/
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Framework;
namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
{
@@ -36,10 +38,27 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength,
int startX, int endX, int startY, int endY)
{
if(height < 0)
height = 0;
else if(height > Constants.MaxTerrainHeightmap)
height = Constants.MaxTerrainHeightmap;
strength *= 0.04f;
if(strength > 1.0f)
strength = 1.0f;
if(strength >= .999f)
{
for (int x = startX; x <= endX; x++)
{
for (int y = startY; y <= endY; y++)
{
if (fillArea[x, y])
map[x, y] = height;
}
}
return;
}
if(strength < 1e-3)
return;
for (int x = startX; x <= endX; x++)
{

View File

@@ -36,10 +36,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength,
int startX, int endX, int startY, int endY)
{
int x,y;
for (x = startX; x <= endX; ++x)
for (int x = startX; x <= endX; ++x)
{
for (y = startY; y <= endY; ++y)
for (int y = startY; y <= endY; ++y)
{
if (fillArea[x, y])
{

View File

@@ -39,16 +39,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
int startX, int endX, int startY, int endY)
{
strength *= 0.08f;
int x, y;
for (x = startX; x <= endX; x++)
if(strength < 1e-4f)
return;
for (int x = startX; x <= endX; x++)
{
for (y = startY; y <= endY; y++)
for (int y = startY; y <= endY; y++)
{
if (fillArea[x, y])
{
float noise = (float)TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0);
map[x, y] += noise * strength;
if(map[x, y] < 0)
map[x, y] = 0;
}
}
}

View File

@@ -36,10 +36,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength,
int startX, int endX, int startY, int endY)
{
int x,y;
for (x = startX; x <= endX; x++)
for (int x = startX; x <= endX; x++)
{
for (y = startY; y <= endY; y++)
for (int y = startY; y <= endY; y++)
{
if (fillArea[x, y])
{

View File

@@ -45,22 +45,37 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
/// </summary>
/// <param name="map">the current heightmap</param>
/// <param name="fillArea">array indicating which sections of the map are to be reverted</param>
/// <param name="strength">unused</param>
/// <param name="strength"></param>
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength,
int startX, int endX, int startY, int endY)
{
int x, y;
strength *= 2f;
if (strength > 1.0f)
strength = 1.0f;
for (x = startX; x <= endX; x++)
if (strength >= .999f)
{
for (y = startY; y <= endY; y++)
for (int x = startX; x <= endX; x++)
{
for (int y = startY; y <= endY; y++)
{
if (fillArea[x, y])
{
map[x, y] = m_revertmap[x, y];
}
}
}
return;
}
if(strength < 1e-4f)
return;
float OneMinusstrength = 1.0f - strength;
for (int x = startX; x <= endX; x++)
{
for (int y = startY; y <= endY; y++)
{
if (fillArea[x, y])
{
map[x, y] = map[x, y] * (1.0f - strength) + m_revertmap[x, y] * strength;
map[x, y] = map[x, y] * OneMinusstrength + m_revertmap[x, y] * strength;
}
}
}

View File

@@ -45,11 +45,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
sy = 4;
strength *= 0.002f;
if(strength < 1e-4f)
return;
if(strength > 1.0f)
strength = 1.0f;
float[,] tweak = new float[endX - startX + 1, endY - startY + 1];
float OneMinusstrength = 1.0f - strength;
for (int x = startX, i = 0; x <= endX; x++, i++)
{
for (int y = startY, j = 0; y <= endY; y++, j++)
@@ -74,20 +75,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
}
}
}
tweak[i, j] = average / avgsteps;
}
}
for (int x = startX, i = 0; x <= endX; x++, i++)
{
for (int y = startY, j = 0; y <= endY; y++, j++)
{
float ty = tweak[i, j];
if (ty == 0.0)
continue;
map[x, y] = (1.0f - strength) * map[x, y] + strength * ty;
map[x, y] = OneMinusstrength * map[x, y] + strength * average / avgsteps;
}
}
}