Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
EtheraelEspeon committed Dec 31, 2023
2 parents 37df486 + 74a799b commit e0c0a41
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
42 changes: 42 additions & 0 deletions Client/Rendering/Occlusion/ChunkOcclusionBitSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Runtime.CompilerServices;

namespace Voxel.Client.Rendering.Occlusion;

/**
* Determines which sides are visible from others in a chunk
* Ex: UpDown means there is a visible pathway from the up face to the down face.
*/
[Flags]
public enum ChunkOcclusionBitSet : ushort {
UpDown = 0b0000000000000001,
UpNorth = 0b0000000000000010,
UpSouth = 0b0000000000000100,
UpEast = 0b0000000000001000,
UpWest = 0b0000000000010000,
DownNorth = 0b0000000000100000,
DownSouth = 0b0000000001000000,
DownEast = 0b0000000010000000,
DownWest = 0b0000000100000000,
NorthSouth = 0b0000001000000000,
NorthEast = 0b0000010000000000,
NorthWest = 0b0000100000000000,
SouthEast = 0b0001000000000000,
SouthWest = 0b0010000000000000,
EastWest = 0b0100000000000000,

Up = 0b0000000000011111,
Down = 0b0000000111100001,
North = 0b0000111000100010,
South = 0b0011001001000100,
East = 0b0101010010001000,
West = 0b0110100100010000,

All = 0b0111111111111111,
}

public static class ChunkOcclusionBitSetExtension {
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool Test(this ChunkOcclusionBitSet set, ChunkOcclusionBitSet direction)
=> (set ^ direction) == 0;
}
8 changes: 4 additions & 4 deletions Client/Rendering/World/ChunkMeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ float calculateAO(float s1, float corner, float s2) {
AO = vec4.Zero;

//if (face <= 1) {
AO[0] = calculateAO(faceBlocks[1].Settings.GetSolidityFloat, faceBlocks[2].Settings.GetSolidityFloat, faceBlocks[3].Settings.GetSolidityFloat);
AO[1] = calculateAO(faceBlocks[3].Settings.GetSolidityFloat, faceBlocks[4].Settings.GetSolidityFloat, faceBlocks[5].Settings.GetSolidityFloat);
AO[2] = calculateAO(faceBlocks[5].Settings.GetSolidityFloat, faceBlocks[6].Settings.GetSolidityFloat, faceBlocks[7].Settings.GetSolidityFloat);
AO[3] = calculateAO(faceBlocks[7].Settings.GetSolidityFloat, faceBlocks[8].Settings.GetSolidityFloat, faceBlocks[1].Settings.GetSolidityFloat);
AO[0] = calculateAO(faceBlocks[1].Settings.Solidity, faceBlocks[2].Settings.Solidity, faceBlocks[3].Settings.Solidity);
AO[1] = calculateAO(faceBlocks[3].Settings.Solidity, faceBlocks[4].Settings.Solidity, faceBlocks[5].Settings.Solidity);
AO[2] = calculateAO(faceBlocks[5].Settings.Solidity, faceBlocks[6].Settings.Solidity, faceBlocks[7].Settings.Solidity);
AO[3] = calculateAO(faceBlocks[7].Settings.Solidity, faceBlocks[8].Settings.Solidity, faceBlocks[1].Settings.Solidity);
//}


Expand Down
3 changes: 2 additions & 1 deletion Client/World/ClientChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class ClientChunk : Chunk {
public bool isFilled;

public ClientChunk(ivec3 chunkPosition, VoxelWorld world, ChunkStorage? storage = null) : base(chunkPosition, world, storage) {

if (storage != null)
isFilled = true;
}

public override void SetStorage(ChunkStorage newStorage) {
Expand Down
3 changes: 2 additions & 1 deletion Common/Tile/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Block {

public readonly BlockSettings Settings;
public bool IsAir => Settings.IsAir;
public float Solidity => Settings.Solidity;

public Block(string name, BlockSettings settings) {
Name = name;
Expand All @@ -24,7 +25,7 @@ public class BlockSettings {
public static readonly BlockSettings Default = new Builder().Build();

public readonly bool IsAir;
public float GetSolidityFloat => IsAir ? 0 : 1;
public float Solidity => IsAir ? 0 : 1;

private BlockSettings(bool isAir) {
IsAir = isAir;
Expand Down
41 changes: 41 additions & 0 deletions Common/World/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,47 @@ public uint GetVersion()
public void IncrementVersion() {
Interlocked.Increment(ref _version);
}

// I don't know if this is the best place to put this..
public HashSet<ivec3> FloodFill(ivec3 root) {
var connected = new HashSet<ivec3>();

if (storage is SingleStorage singleStorage) {
if (singleStorage.Block.IsAir)
foreach (var pos in Iteration.Cubic(0, PositionExtensions.ChunkSize))
connected.Add(pos);
return connected;
}

var queue = new Stack<ivec3>();
queue.Push(root.Loop(PositionExtensions.ChunkSize));
while (queue.Count > 0) {
var node = queue.Pop();

if (!GetBlock(node).IsAir)
continue;

connected.Add(node);

for (int i = 0; i < 3; i++) {
if (node[i] > 0) {
var newNode = node;
newNode[i] -= 1;
if (!connected.Contains(newNode))
queue.Push(newNode);
}
if (node[i] < PositionExtensions.ChunkSize) {
var newNode = node;
newNode[i] += 1;
queue.Push(newNode);
if (!connected.Contains(newNode))
queue.Push(newNode);
}
}
}

return connected;
}

internal void IncrementViewCount() {
viewCount++;
Expand Down
2 changes: 1 addition & 1 deletion Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Run(int tps = 20, string windowTitle = "Game") {
var gdo = new GraphicsDeviceOptions {
PreferDepthRangeZeroToOne = true,
PreferStandardClipSpaceYDirection = true,
SyncToVerticalBlank = true,
SyncToVerticalBlank = false,
};

VeldridStartup.CreateWindowAndGraphicsDevice(wci, gdo, GraphicsBackend.Vulkan, out var nw, out var gd);
Expand Down

0 comments on commit e0c0a41

Please sign in to comment.