Skip to content

Fly, use rotating buffer over list to store last 5 positions.#20140

Merged
PunkPun merged 1 commit into
OpenRA:bleedfrom
anvilvapre:20220718_fly_history
Aug 2, 2023
Merged

Fly, use rotating buffer over list to store last 5 positions.#20140
PunkPun merged 1 commit into
OpenRA:bleedfrom
anvilvapre:20220718_fly_history

Conversation

@anvilvapre

@anvilvapre anvilvapre commented Jul 23, 2022

Copy link
Copy Markdown
Contributor

Fly stores the last the position over the lats 5 ticks to determine the distance travelled and whether flight is stuck.

  • Replace position buffer List with an rotating buffer. To avoid removing the head element from a list array each tick. Avoiding a ArrayCopy/Move each tick.
  • Avoid addition of one WVec/Pos to Zero WVev/Pos. Trivial.
  • Tickfacing, 50% change of one less subtraction. Trivial.
  • RotatingBuffer can be reused in new contrail implementation. Could potentially also be used in input tap detection. (only used function tested)

Future possible improvements: Map.DistanceAboveTerrain is looked up more often by all flight activites/functions - during the same tick. For rectangular maps the operation is not that expensive. Functions already take many arguments - did not want to add it.

Comment thread OpenRA.Game/Primitives/RotatingBuffer.cs Outdated
Comment thread OpenRA.Game/Primitives/RotatingBuffer.cs Outdated
Comment thread OpenRA.Game/Primitives/RotatingBuffer.cs
Comment thread OpenRA.Game/Primitives/RotatingBuffer.cs Outdated
Comment thread OpenRA.Game/Primitives/RotatingBuffer.cs Outdated
@anvilvapre
anvilvapre force-pushed the 20220718_fly_history branch 2 times, most recently from 8d53513 to 328f30f Compare October 9, 2022 12:25
@anvilvapre

Copy link
Copy Markdown
Contributor Author

Requested changes addressed.

@AspectInteractive2 AspectInteractive2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I am not sure how much of a difference these changes will make but they are reasonable changes.

Comment thread OpenRA.Game/Primitives/RingBuffer.cs Outdated

@PunkPun PunkPun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think buffer related changes should be separated into its own commit. This also needs a rebased as it conflicts with the current codestyle (I've suggested the fix).

Comment thread OpenRA.Game/Primitives/RingBuffer.cs Outdated
Comment thread OpenRA.Mods.Common/Activities/Air/Fly.cs Outdated
Comment thread OpenRA.Game/Primitives/RingBuffer.cs Outdated
Comment thread OpenRA.Mods.Common/Activities/Air/Fly.cs Outdated
Comment thread OpenRA.Game/Primitives/RingBuffer.cs Outdated
Comment thread OpenRA.Game/Primitives/RingBuffer.cs
Comment thread OpenRA.Game/Primitives/RingBuffer.cs
Comment thread OpenRA.Game/Primitives/RingBuffer.cs Outdated
Comment thread OpenRA.Game/Primitives/RingBuffer.cs Outdated
Comment thread OpenRA.Game/Primitives/RingBuffer.cs
set
{
if (pos >= Count)
throw new ArgumentException($"Index out of bounds: {pos}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't check this for get.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it seemed reasonable, to avoid the overhead.

@anvilvapre
anvilvapre force-pushed the 20220718_fly_history branch from 7445a8e to 415a6ed Compare May 14, 2023 22:20
@anvilvapre

Copy link
Copy Markdown
Contributor Author

ping. fixups were done, apart from the bounds check in the getter, which will be unlikely and obviously tracable by the resulting exception.

@anvilvapre

Copy link
Copy Markdown
Contributor Author

ping.

@PunkPun
PunkPun merged commit 1ce9161 into OpenRA:bleed Aug 2, 2023
@PunkPun

PunkPun commented Aug 2, 2023

Copy link
Copy Markdown
Member

Chnagelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants