Skip to content

Commit

Permalink
Don't request blocks that are already requested
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Dec 21, 2023
1 parent 6640bc9 commit e5d6d6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Client/CentrEDClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class CentrEDClient : BaseCentrED, IDisposable
public ushort X { get; private set; }
public ushort Y { get; private set; }
internal Stack<Packet> UndoStack = new();
internal List<BlockCoords> RequestedBlocks = new();
public List<String> Clients { get; } = new();
public bool Running;
private string? _status;
Expand Down Expand Up @@ -129,10 +130,11 @@ public void InitLandscape(ushort width, ushort height)
public void LoadBlocks(List<BlockCoords> blockCoords)
{
var filteredBlockCoords = blockCoords.FindAll
(b => !Landscape.BlockCache.Contains(Block.Id(b.X, b.Y)) && isValidX(b.X) && isValidY(b.Y));
(b => !Landscape.BlockCache.Contains(Block.Id(b.X, b.Y)) && !RequestedBlocks.Contains(b) && isValidX(b.X) && isValidY(b.Y));

Check warning on line 133 in Client/CentrEDClient.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, CentrED)

Dereference of a possibly null reference.

Check warning on line 133 in Client/CentrEDClient.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, CentrED)

Dereference of a possibly null reference.

Check warning on line 133 in Client/CentrEDClient.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, CentrED)

Dereference of a possibly null reference.
if (filteredBlockCoords.Count <= 0)
return;
Send(new RequestBlocksPacket(filteredBlockCoords));
RequestedBlocks.AddRange(filteredBlockCoords);
}

public bool isValidX(int x)
Expand Down
1 change: 1 addition & 0 deletions Client/Map/ClientLandscapePacketHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private void OnBlockPacket(BinaryReader reader, NetState<CentrEDClient> ns)
var block = new Block(landBlock, staticBlock);
if(BlockCache.Add(Block.Id(block), block))
ns.Parent.OnBlockLoaded(block);
ns.Parent.RequestedBlocks.Remove(coords);
}
}

Expand Down

0 comments on commit e5d6d6e

Please sign in to comment.