This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
Drew DeVault 362c852f51 Many improvements to server stability+performance
Sorry for the vague commit message. There were a lot of changes. Here's
a list of most of them:

- Lighting updates are timeboxed each frame
- The next environment frame is queued sooner if the current one took
  longer (as soon as immediately)
- Issues with the physics engines and mobs using it were (mostly) fixed,
  mobs no longer freak out and get stuck on physics objects
- Mob AI/pathfinding is done more intelligently
- The player can no longer spawn in an ocean or a desert biome
- Some deadlocks in Region were fixed (more remain to be fixed)

The current performance bottlenecks are lighting (still) and propegating
initial chunk loads to blocks that need to schedule things (such as
grass blocks). I think the main culprit in the latter case is grass
blocks and water blocks. The former can be improved by adding a block
cache to World, but that'll take some custom work. This step is just
gonna be slow no matter what, we might have to split it across several
frames but it's never going to be great.

There still seems to be a deadlock somewhere in all of this mess, in the
world code. I'll find it later.
2017-05-22 19:51:23 -04:00

95 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrueCraft.API.World;
using TrueCraft.API;
using TrueCraft.Core.TerrainGen.Noise;
namespace TrueCraft.Core.World
{
public class BiomeMap : IBiomeMap
{
public IList<BiomeCell> BiomeCells { get; private set; }
Perlin TempNoise = new Perlin();
Perlin RainNoise = new Perlin();
public BiomeMap(int seed)
{
BiomeCells = new List<BiomeCell>();
TempNoise.Persistance = 1.45;
TempNoise.Frequency = 0.015;
TempNoise.Amplitude = 5;
TempNoise.Octaves = 2;
TempNoise.Lacunarity = 1.3;
RainNoise.Frequency = 0.03;
RainNoise.Octaves = 3;
RainNoise.Amplitude = 5;
RainNoise.Lacunarity = 1.7;
TempNoise.Seed = seed;
RainNoise.Seed = seed;
}
public void AddCell(BiomeCell cell)
{
BiomeCells.Add(cell);
}
public byte GetBiome(Coordinates2D location)
{
byte BiomeID = (ClosestCell(location) != null) ? ClosestCell(location).BiomeID : (byte)Biome.Plains;
return BiomeID;
}
public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location, bool spawn)
{
double temp = Math.Abs(TempNoise.Value2D(location.X, location.Z));
double rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
byte ID = biomes.GetBiome(temp, rainfall, spawn).ID;
return ID;
}
/*
* The closest biome cell to the specified location(uses the Chebyshev distance function).
*/
public BiomeCell ClosestCell(Coordinates2D location)
{
BiomeCell cell = null;
var distance = double.MaxValue;
foreach (BiomeCell C in BiomeCells)
{
var _distance = Distance(location, C.CellPoint);
if (_distance < distance)
{
distance = _distance;
cell = C;
}
}
return cell;
}
/*
* The distance to the closest biome cell point to the specified location(uses the Chebyshev distance function).
*/
public double ClosestCellPoint(Coordinates2D location)
{
var distance = double.MaxValue;
foreach (BiomeCell C in BiomeCells)
{
var _distance = Distance(location, C.CellPoint);
if (_distance < distance)
{
distance = _distance;
}
}
return distance;
}
public double Distance(Coordinates2D a, Coordinates2D b)
{
Coordinates2D diff = a - b;
return Math.Max(Math.Abs(diff.X), Math.Abs(diff.Z));
}
}
}