Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: /triggers debug view doesn't show if a CPos trigger gets removed #20531

Open
Leo512bit opened this issue Dec 10, 2022 · 1 comment
Open
Labels

Comments

@Leo512bit
Copy link
Contributor

Leo512bit commented Dec 10, 2022

Issue Summary

/triggers debug view doesn't show if a CPos trigger gets removed

Reproduction

Have a script where a CPos trigger gets added then removed.

Expected behavior

The overlay should be removed once a CPos trigger gets removed.

Tested on:playtest-20221203

@Leo512bit Leo512bit added the Bug label Dec 10, 2022
@anvilvapre
Copy link
Contributor

anvilvapre commented Jun 2, 2023

Related source lines. It would suggest that trigger positions in actor map are not updated.

IEnumerable<IRenderable> IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr)
{
if (!enabled)
yield break;
var triggerPositions = wr.World.ActorMap.TriggerPositions().ToHashSet();
foreach (var uv in wr.Viewport.VisibleCellsInsideBounds.CandidateMapCoords)
{
if (self.World.ShroudObscures(uv))
continue;
var cell = uv.ToCPos(wr.World.Map);
if (!triggerPositions.Contains(cell))
continue;
var center = wr.World.Map.CenterOfCell(cell);
yield return new TextAnnotationRenderable(font, center, 1024, color, "T");
}
}

In ActorMap the cell triggers are maintained by key in a hash map. The entries are removed but the key is not removed from the cellTriggerInfluence dictionary.

public void RemoveCellTrigger(int id)
{
if (!cellTriggers.TryGetValue(id, out var trigger))
return;
foreach (var c in trigger.Footprint)
{
if (!cellTriggerInfluence.ContainsKey(c))
continue;
cellTriggerInfluence[c].RemoveAll(t => t == trigger);
}
}

One fix would be for the overlay to check if the position keys actually contain any cell triggers. I.e. if the dictionary value has any CellTriggers left in the list.

A better fix may be to remove the key from the cellTriggerInfluence dictionary in ActorMap.RemoveCellTrigger when the last Trigger is removed from the list.

Please propose the best solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants