Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#1846 closed enhancement (fixed)

[PATCH] Sim interpolation optimization

Reported by: sbte Owned by: Jonathan Waller
Priority: Should Have Milestone: Alpha 13
Component: UI & Simulation Keywords:
Cc: Patch:

Description

I wrote a patch that make sure we don't reinterpolate if the position of a component does not change. This gives me a speedup for the sim interpolation of 6 ms/frame to 3.6 ms/frame. Thanks to quantumstate for the suggestion.

Attachments (3)

0001-Don-t-reinterpolate-if-the-position-of-a-component-d.patch (4.3 KB ) - added by sbte 11 years ago.
Sim interpolation speedup patch
0001-Don-t-reinterpolate-if-the-position-of-a-component-d.2.patch (4.2 KB ) - added by sbte 11 years ago.
Sim interpolation speedup patch v2
0001-Don-t-reinterpolate-if-the-position-of-a-component-d.3.patch (4.4 KB ) - added by sbte 11 years ago.
Sim interpolation speedup patch v3

Download all attachments as: .zip

Change History (18)

by sbte, 11 years ago

Sim interpolation speedup patch

comment:1 by leper, 11 years ago

Keywords: review added
Milestone: BacklogAlpha 13
Summary: Sim interpolation optimization[PATCH] Sim interpolation optimization

comment:2 by sbte, 11 years ago

There are a few issues with the above patch.

At least two trivial ones:

  • Buildings don't follow the mouse before they are placed
  • Buildings don't raise from the ground when they are built

And two harder ones:

  • When units move from a to b in a turn, they never actually reach b, but only a+(b-a)*lastFrameOffset
  • In Atlas, raising the ground level does not raise the objects that are on the ground.

I already have a working patch, but that one is a lot slower than the original one 5ms/frame vs 3.6 ms/frame. I will try to improve this.

by sbte, 11 years ago

Sim interpolation speedup patch v2

comment:3 by historic_bruno, 11 years ago

How does this affect stationary units that are animated?

in reply to:  3 comment:4 by sbte, 11 years ago

Replying to historic_bruno:

How does this affect stationary units that are animated?

This is handled by the call to m_Unit->UpdateModel(frameTime);

comment:5 by sbte, 11 years ago

By the way: the new patch handles all cases I mentioned previously and still has the 3.6 ms/frame speedup. The Atlas bug is fixed by only allowing skipping interpolation only after a turn has completed. This will not happen in Atlas (as far as I understand).

comment:6 by Jonathan Waller, 11 years ago

There is still and atlas bug. You can play the simulation in atlas (on the left panel there are buttons) so your detection stuff from there breaks. Your current approach doesn't seem very robust, perhaps there is a better solution? Doing special things for construction progress doesn't look pretty to me.

One idea is to store m_PrevX, m_PrevY and m_PrevZ. Then check if the current values match the stored in the GetReinterpolate() function. At the start of each turn update m_PrevX, m_PrevY and m_PrevZ.

Another option is to add something to the setters for m_X, m_Y... and again use a new turn event to clear the dirty flag. I think I prefer the other idea though.

in reply to:  6 comment:7 by sbte, 11 years ago

Replying to quantumstate:

There is still and atlas bug. You can play the simulation in atlas (on the left panel there are buttons) so your detection stuff from there breaks. Your current approach doesn't seem very robust, perhaps there is a better solution? Doing special things for construction progress doesn't look pretty to me.

Sorry, but I have not used Atlas before, so I did not notice this. Is there maybe a way to detect whether we are in Atlas and in that case disable this optimization?

Replying to quantumstate:

One idea is to store m_PrevX, m_PrevY and m_PrevZ. Then check if the current values match the stored in the GetReinterpolate() function. At the start of each turn update m_PrevX, m_PrevY and m_PrevZ.

This would break the JumpTo method, because this method sets m_PrevX and m_PrevZ to be equal to m_X and m_Z. Instead, we need the possibility to be notified from AdvertisePositionChanges, so that is what I do now.

Concerning the Y value: I tried this, but then lost 2 ms/frame again mostly because of the extra work that has to be done to compute the correct Y value (which, AFAIK, actually has to be done only in Atlas and when construction is in progress). I don't really see a way to speed this up even more.

Replying to quantumstate:

Another option is to add something to the setters for m_X, m_Y... and again use a new turn event to clear the dirty flag. I think I prefer the other idea though.

This would still mean it is a lot slower because of the extra Y computations.

So basically, disabling this optimization in Atlas would be ideal to avoid having extra computations for the Y value (and would hopefully fix all bugs). If you know a way to do this that would be great.

comment:8 by Jonathan Waller, 11 years ago

Ah yes I was forgetting about the terrain modification stuff. One things that could be messy is flattening the ground near buildings which is a proposed feature. I think it is probably ok to write a comment in that ticket though mentioning this (which I will do).

leper helpfully found if(!g_AtlasGameLoop->running) which should do what you want. I would still like it if you try and avoid as much special case stuff as possible, since it makes maintenance easier. Terrain height changes sound like a reasonable special case though.

comment:9 by sbte, 11 years ago

If anyone needs to actually force an update, they can call JumpTo or MoveTo using the same x and z position. An alternative to the special cases is that methods that actually change terrain height call some method that sets m_PositionChanged to true. Maybe that's a cleaner solution?

by sbte, 11 years ago

Sim interpolation speedup patch v3

comment:10 by sbte, 11 years ago

I again added a new version of the patch, which now disables the modifications I made in Atlas.

comment:11 by Jonathan Waller, 11 years ago

Owner: set to Jonathan Waller
Resolution: fixed
Status: newclosed

In 13223:

Only use interpolation for moving objects in VisualActor. Patch by sbte. Fixes #1846.

comment:12 by Jonathan Waller, 11 years ago

Keywords: patch review removed

Thanks for the patch.

comment:13 by Jonathan Waller, 11 years ago

In 13243:

Fix rotation interpolation. Refs #1846.

comment:14 by Jonathan Waller, 11 years ago

In 13244:

Better fix for the angle interolation issue. Thanks sbte for spotting it. Refs #1846.

comment:15 by ben, 11 years ago

In 13500:

Reverts interpolation changes from r13489, r13323, r13251, r13244, r13243, r13223. Refs #1846, #1858, #1865, #1906

Note: See TracTickets for help on using tickets.