saul / demofile-net

Blazing fast cross-platform demo parser library for Counter-Strike 2 and Valve's Deadlock, written in C#.
MIT License
111 stars 10 forks source link

Seeking support #47

Closed in0finite closed 9 months ago

in0finite commented 9 months ago

There should be seeking support in the library.

It seems that demos already have enough data for this to be possible, eg. snapshots on every 60 sec, round-start ticks, etc...

Backward seeking through time should also be possible.

For best usability, I think library should have an API like this:

DemoParser.SaveToSnapshot(Snapshot s);
DemoParser.RestoreFromSnapshot(Snapshot s);

class Snapshot
{
    List<Entity> entities;
    List<StringTable> stringTables;
    int tick;
    long streamPosition;
    CDemoFileHeader header;

    ...
}
saul commented 9 months ago

This is definitely do-able, I have some changes on a branch that I need to test that implement seeking to arbitrary ticks.

saul commented 9 months ago

WIP PR here: https://github.com/saul/demofile-net/pull/49

saul commented 9 months ago

The PR should now be in a state for you to test.

I've tested it locally jumping 77 seconds every 77 seconds, and jumping back 16 seconds every 33 seconds. It seems to read the demo fine.

You just need to call SeekToTickAsync before or after MoveNextAsync (i.e., don't try to seek when you're in the middle of e.g. a game event callback).

Can you try it out and let me know how you get on?

saul commented 9 months ago

This is now available as v0.12.1