@@ -52,6 +52,7 @@ type Parser struct {
5252 userMessageHandler userMessageHandler
5353 eventDispatcher dp.Dispatcher
5454 currentFrame int // Demo-frame, not ingame-tick
55+ tickInterval float32 // Duration between ticks in seconds
5556 header * common.DemoHeader // Pointer so we can check for nil
5657 gameState * GameState
5758 demoInfoProvider demoInfoProvider // Provides demo infos to other packages that the core package depends on
@@ -122,14 +123,37 @@ func (p *Parser) CurrentFrame() int {
122123
123124// CurrentTime returns the time elapsed since the start of the demo
124125func (p * Parser ) CurrentTime () time.Duration {
125- return time .Duration (p .currentFrame ) * p .header .FrameTime ()
126+ return time .Duration (float32 (p .gameState .ingameTick ) * p .tickInterval * float32 (time .Second ))
127+ }
128+
129+ // TickRate returns the tick-rate the server ran on during the game.
130+ func (p * Parser ) TickRate () float64 {
131+ if p .tickInterval != 0 {
132+ return 1.0 / float64 (p .tickInterval )
133+ }
134+
135+ return p .header .TickRate ()
136+ }
137+
138+ // TickTime returns the time a single tick takes in seconds.
139+ func (p * Parser ) TickTime () time.Duration {
140+ if p .tickInterval != 0 {
141+ return time .Duration (float32 (time .Second ) * p .tickInterval )
142+ }
143+
144+ return p .header .TickTime ()
126145}
127146
128147// Progress returns the parsing progress from 0 to 1.
129148// Where 0 means nothing has been parsed yet and 1 means the demo has been parsed to the end.
130149//
131150// Might not be 100% correct since it's just based on the reported tick count of the header.
151+ // May always return 0 if the demo header is corrupt.
132152func (p * Parser ) Progress () float32 {
153+ if p .header == nil || p .header .PlaybackFrames == 0 {
154+ return 0
155+ }
156+
133157 return float32 (p .currentFrame ) / float32 (p .header .PlaybackFrames )
134158}
135159
@@ -255,6 +279,7 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) *Parser {
255279 p .msgDispatcher .RegisterHandler (p .handleUserMessage )
256280 p .msgDispatcher .RegisterHandler (p .handleSetConVar )
257281 p .msgDispatcher .RegisterHandler (p .handleFrameParsed )
282+ p .msgDispatcher .RegisterHandler (p .handleServerInfo )
258283 p .msgDispatcher .RegisterHandler (p .gameState .handleIngameTickNumber )
259284
260285 if config .MsgQueueBufferSize >= 0 {
@@ -280,8 +305,7 @@ func (p demoInfoProvider) IngameTick() int {
280305}
281306
282307func (p demoInfoProvider ) TickRate () float64 {
283- // TODO: read tickRate from CVARs as fallback
284- return p .parser .header .TickRate ()
308+ return p .parser .TickRate ()
285309}
286310
287311func (p demoInfoProvider ) FindPlayerByHandle (handle int ) * common.Player {
0 commit comments