6211: Fix edge cases where demo tick seeking did not work r=Chairn a=Robyt3

Instead of using hardcoded tick offsets, use the current/previous/next tick values from the demo info.

This fixes seeking the next tick not working for demos where the difference between the current and the next tick was greater than 3.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2022-12-30 20:23:49 +00:00 committed by GitHub
commit 1ad36b2073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View file

@ -77,9 +77,9 @@ public:
enum ETickOffset
{
TICK_CURRENT = 1, // update the current tick again
TICK_PREVIOUS = 0, // go to the previous tick
TICK_NEXT = 3, // go to the next tick
TICK_CURRENT, // update the current tick again
TICK_PREVIOUS, // go to the previous tick
TICK_NEXT, // go to the next tick
};
~IDemoPlayer() {}

View file

@ -944,7 +944,27 @@ int CDemoPlayer::SeekTime(float Seconds)
int CDemoPlayer::SeekTick(ETickOffset TickOffset)
{
return SetPos(m_Info.m_Info.m_CurrentTick + (int)TickOffset);
int WantedTick;
switch(TickOffset)
{
case TICK_CURRENT:
WantedTick = m_Info.m_Info.m_CurrentTick;
break;
case TICK_PREVIOUS:
WantedTick = m_Info.m_PreviousTick;
break;
case TICK_NEXT:
WantedTick = m_Info.m_NextTick;
break;
default:
dbg_assert(false, "Invalid TickOffset");
WantedTick = -1;
break;
}
// +1 because SetPos will seek until the given tick is the next tick that
// will be played back, whereas we want the wanted tick to be played now.
return SetPos(WantedTick + 1);
}
int CDemoPlayer::SetPos(int WantedTick)