Skip to content

Commit

Permalink
Reduce allocations in the renderer using a new feature
Browse files Browse the repository at this point in the history
You can pass an existing HashSet to `GetEntitiesIntersecting()` now
  • Loading branch information
wixoaGit committed Dec 22, 2023
1 parent cd8892f commit 6c6ec66
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ internal sealed class DreamViewOverlay : Overlay {

// Defined here so it isn't recreated every frame
private ViewAlgorithm.Tile?[,]? _tileInfo;
private readonly HashSet<EntityUid> _entities = new();

public DreamViewOverlay(TransformSystem transformSystem, EntityLookupSystem lookupSystem,
ClientAppearanceSystem appearanceSystem, ClientScreenOverlaySystem screenOverlaySystem, ClientImagesSystem clientImagesSystem) {
Expand Down Expand Up @@ -140,19 +141,18 @@ private void DrawAll(OverlayDrawArgs args, EntityUid eye, Vector2i viewportSize)

var worldHandle = args.WorldHandle;

HashSet<EntityUid> entities;
using (_prof.Group("lookup")) {
//TODO use a sprite tree.
//the scaling is to attempt to prevent pop-in, by rendering sprites that are *just* offscreen
entities = _lookupSystem.GetEntitiesIntersecting(args.MapId, args.WorldAABB.Scale(1.2f), MapLookupFlags);
_lookupSystem.GetEntitiesIntersecting(args.MapId, args.WorldAABB.Scale(1.2f), _entities, MapLookupFlags);
}

var eyeTile = grid.GetTileRef(eyeTransform.MapPosition);
var tiles = CalculateTileVisibility(grid, entities, eyeTile, seeVis);
var tiles = CalculateTileVisibility(grid, _entities, eyeTile, seeVis);

RefreshRenderTargets(args.WorldHandle, viewportSize);

CollectVisibleSprites(tiles, grid, eyeTile, entities, seeVis, sight, args.WorldAABB);
CollectVisibleSprites(tiles, grid, eyeTile, _entities, seeVis, sight, args.WorldAABB);
ClearPlanes();
ProcessSprites(worldHandle, viewportSize, args.WorldAABB);

Expand Down

0 comments on commit 6c6ec66

Please sign in to comment.