Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
tickrate/panic fix for demos with broken headers (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-wa authored Jun 27, 2020
1 parent fdde457 commit 267f51b
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 250 deletions.
26 changes: 19 additions & 7 deletions csminify.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ func ToReplayWithConfig(r io.Reader, cfg ReplayConfig) (rep.Replay, error) {
// Make the parser accessible for the custom event handlers
cfg.EventCollector.parser = p

m := newMinifier(p, cfg.EventCollector)
m := newMinifier(p, cfg.EventCollector, cfg.SnapshotFrequency)

m.replay.Header.MapName = header.MapName
m.replay.Header.TickRate = header.FrameRate()
m.replay.Header.SnapshotRate = int(math.Round(m.replay.Header.TickRate / cfg.SnapshotFrequency))
m.tickRate(p.TickRate())

p.RegisterEventHandler(func(events.ConVarsUpdated) {
if tickRate := p.TickRate(); tickRate != 0 {
m.tickRate(tickRate)
}
})

// Register event handlers from collector
for _, h := range cfg.EventCollector.handlers {
Expand All @@ -108,18 +113,20 @@ func ToReplayWithConfig(r io.Reader, cfg ReplayConfig) (rep.Replay, error) {
}

type minifier struct {
parser dem.Parser
replay rep.Replay
eventCollector *EventCollector
parser dem.Parser
replay rep.Replay
eventCollector *EventCollector
snapshotFrequency float64

knownPlayerEntityIDs map[int]struct{}
}

func newMinifier(parser dem.Parser, eventCollector *EventCollector) minifier {
func newMinifier(parser dem.Parser, eventCollector *EventCollector, snapshotFrequency float64) minifier {
return minifier{
parser: parser,
eventCollector: eventCollector,
knownPlayerEntityIDs: make(map[int]struct{}),
snapshotFrequency: snapshotFrequency,
}
}

Expand Down Expand Up @@ -196,6 +203,11 @@ func (m *minifier) updateKnownPlayers() {
}
}

func (m *minifier) tickRate(rate float64) {
m.replay.Header.TickRate = rate
m.replay.Header.SnapshotRate = int(math.Round(rate / m.snapshotFrequency))
}

func r3VectorToPoint(v r3.Vector) rep.Point {
return rep.Point{X: int(v.X), Y: int(v.Y), Z: int(v.Z)}
}
Expand Down
Loading

0 comments on commit 267f51b

Please sign in to comment.