Dynamic space world generation and debris. (#15120)
* World generation (squash) * Test fixes. * command * o * Access cleanup. * Documentation touchups. * Use a prototype serializer for BiomeSelectionComponent * Struct enumerator in SimpleFloorPlanPopulatorSystem * Safety margins around PoissonDiskSampler, cookie acquisition methodologies * Struct enumerating PoissonDiskSampler; internal side * Struct enumerating PoissonDiskSampler: Finish it * Update WorldgenConfigSystem.cs awa --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: 20kdc <asdd2808@gmail.com>
This commit is contained in:
71
Content.Server/Worldgen/WorldGen.cs
Normal file
71
Content.Server/Worldgen/WorldGen.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Content.Server.Worldgen;
|
||||
|
||||
/// <summary>
|
||||
/// Contains a few world-generation related constants and static functions.
|
||||
/// </summary>
|
||||
public static class WorldGen
|
||||
{
|
||||
/// <summary>
|
||||
/// The size of each chunk (isn't that self-explanatory.)
|
||||
/// Be careful about how small you make this.
|
||||
/// </summary>
|
||||
public const int ChunkSize = 128;
|
||||
|
||||
/// <summary>
|
||||
/// Converts world coordinates to chunk coordinates.
|
||||
/// </summary>
|
||||
/// <param name="inp">World coordinates</param>
|
||||
/// <returns>Chunk coordinates</returns>
|
||||
[Pure]
|
||||
public static Vector2i WorldToChunkCoords(Vector2i inp)
|
||||
{
|
||||
return ((Vector2) inp * (1.0f / ChunkSize, 1.0f / ChunkSize)).Floored();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts world coordinates to chunk coordinates.
|
||||
/// </summary>
|
||||
/// <param name="inp">World coordinates</param>
|
||||
/// <returns>Chunk coordinates</returns>
|
||||
[Pure]
|
||||
public static Vector2 WorldToChunkCoords(Vector2 inp)
|
||||
{
|
||||
return inp * (1.0f / ChunkSize, 1.0f / ChunkSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts chunk coordinates to world coordinates.
|
||||
/// </summary>
|
||||
/// <param name="inp">Chunk coordinates</param>
|
||||
/// <returns>World coordinates</returns>
|
||||
[Pure]
|
||||
public static Vector2 ChunkToWorldCoords(Vector2i inp)
|
||||
{
|
||||
return inp * ChunkSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts chunk coordinates to world coordinates.
|
||||
/// </summary>
|
||||
/// <param name="inp">Chunk coordinates</param>
|
||||
/// <returns>World coordinates</returns>
|
||||
[Pure]
|
||||
public static Vector2 ChunkToWorldCoords(Vector2 inp)
|
||||
{
|
||||
return inp * ChunkSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts chunk coordinates to world coordinates, getting the center of the chunk.
|
||||
/// </summary>
|
||||
/// <param name="inp">Chunk coordinates</param>
|
||||
/// <returns>World coordinates</returns>
|
||||
[Pure]
|
||||
public static Vector2 ChunkToWorldCoordsCentered(Vector2i inp)
|
||||
{
|
||||
return inp * ChunkSize + Vector2i.One * (ChunkSize / 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user