Skip to content

Commit

Permalink
Fix UnknownEntitiesRequester clearing out of range actors
Browse files Browse the repository at this point in the history
Only clear actors that have a renderer associated with them. Fixes bug where requester would repeatedly request the same actors and erroneously remove them too early.
  • Loading branch information
ethanmoffat committed May 31, 2024
1 parent 6cc0eee commit 20001a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 9 additions & 3 deletions EndlessClient/HUD/Controls/HudControlsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using EOLib.Domain.Map;
using EOLib.Graphics;
using EOLib.Localization;
using EOLib.Net.Communication;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -72,6 +71,8 @@ public class HudControlsFactory : IHudControlsFactory
private readonly IClickDispatcherFactory _clickDispatcherFactory;
private readonly IMetadataProvider<WeaponMetadata> _weaponMetadataProvider;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly INPCRendererProvider _npcRendererProvider;
private IChatController _chatController;
private IMainButtonController _mainButtonController;

Expand Down Expand Up @@ -106,7 +107,9 @@ public HudControlsFactory(IHudButtonController hudButtonController,
IFixedTimeStepRepository fixedTimeStepRepository,
IClickDispatcherFactory clickDispatcherFactory,
IMetadataProvider<WeaponMetadata> weaponMetadataProvider,
ILocalizedStringFinder localizedStringFinder)
ILocalizedStringFinder localizedStringFinder,
ICharacterRendererProvider characterRendererProvider,
INPCRendererProvider npcRendererProvider)
{
_hudButtonController = hudButtonController;
_hudPanelFactory = hudPanelFactory;
Expand Down Expand Up @@ -140,6 +143,8 @@ public HudControlsFactory(IHudButtonController hudButtonController,
_clickDispatcherFactory = clickDispatcherFactory;
_weaponMetadataProvider = weaponMetadataProvider;
_localizedStringFinder = localizedStringFinder;
_characterRendererProvider = characterRendererProvider;
_npcRendererProvider = npcRendererProvider;
}

public void InjectChatController(IChatController chatController,
Expand Down Expand Up @@ -547,7 +552,8 @@ private PeriodicStatUpdaterComponent CreatePeriodicStatUpdater()

private UnknownEntitiesRequester CreateUnknownEntitiesRequester()
{
return new UnknownEntitiesRequester(_endlessGameProvider, _clientWindowSizeRepository, (ICharacterProvider)_characterRepository, _currentMapStateRepository, _unknownEntitiesRequestActions);
return new UnknownEntitiesRequester(_endlessGameProvider, _clientWindowSizeRepository, (ICharacterProvider)_characterRepository, _currentMapStateRepository,
_npcRendererProvider, _characterRendererProvider, _unknownEntitiesRequestActions);
}

private StatusBarLabel CreateStatusLabel()
Expand Down
12 changes: 10 additions & 2 deletions EndlessClient/Network/UnknownEntitiesRequester.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using EndlessClient.GameExecution;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.NPC;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.Domain.NPC;
Expand All @@ -21,6 +23,8 @@ public class UnknownEntitiesRequester : GameComponent
private readonly IClientWindowSizeProvider _clientWindowSizeProvider;
private readonly ICharacterProvider _characterProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly INPCRendererProvider _npcRendererProvider;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly IUnknownEntitiesRequestActions _unknownEntitiesRequestActions;

private DateTime _lastRequestTime;
Expand All @@ -30,12 +34,16 @@ public UnknownEntitiesRequester(IEndlessGameProvider gameProvider,
IClientWindowSizeProvider clientWindowSizeProvider,
ICharacterProvider characterProvider,
ICurrentMapStateRepository currentMapStateRepository,
INPCRendererProvider npcRendererProvider,
ICharacterRendererProvider characterRendererProvider,
IUnknownEntitiesRequestActions unknownEntitiesRequestActions)
: base((Game) gameProvider.Game)
{
_clientWindowSizeProvider = clientWindowSizeProvider;
_characterProvider = characterProvider;
_currentMapStateRepository = currentMapStateRepository;
_npcRendererProvider = npcRendererProvider;
_characterRendererProvider = characterRendererProvider;
_unknownEntitiesRequestActions = unknownEntitiesRequestActions;
_lastRequestTime = DateTime.Now;
}
Expand Down Expand Up @@ -93,9 +101,9 @@ private void ClearOutOfRangeActors()

foreach (var entity in entitiesToRemove)
{
if (entity is Character c)
if (entity is Character c && _characterRendererProvider.CharacterRenderers.ContainsKey(c.ID))
_currentMapStateRepository.Characters.Remove(c);
else if (entity is NPC n)
else if (entity is NPC n && _npcRendererProvider.NPCRenderers.ContainsKey(n.Index))
_currentMapStateRepository.NPCs.Remove(n);
else if (entity is MapItem i)
_currentMapStateRepository.MapItems.Remove(i);
Expand Down

0 comments on commit 20001a3

Please sign in to comment.