moved spray timeout to config

This commit is contained in:
2021-11-09 18:59:00 +01:00
parent 0fdea7b327
commit 1d6396abfd
5 changed files with 42 additions and 36 deletions

View File

@@ -27,9 +27,10 @@ type Demo struct {
}
type DemoParser struct {
demoQueue chan *Demo
tempDir string
db *ent.Client
demoQueue chan *Demo
tempDir string
db *ent.Client
sprayTimeout int
}
type Encounter struct {
@@ -56,17 +57,15 @@ type DemoNotFoundError struct {
error
}
func (s *Sprays) Add(currentTime time.Duration, sprayPoint []float32, timeout int, maxLength int) {
func (s *Sprays) Add(currentTime time.Duration, sprayPoint []float32, timeout int) {
sprayFound := false
for _, sp := range s.Sprays {
if currentTime.Milliseconds()-sp.Time.Milliseconds() <= int64(timeout) {
sprayFound = true
if len(sp.Spray) < maxLength+1 {
sp.Spray = append(sp.Spray, []float32{
sprayPoint[0] - sp.Spray[0][0],
sprayPoint[1] - sp.Spray[0][1],
})
}
sp.Spray = append(sp.Spray, []float32{
sprayPoint[0] - sp.Spray[0][0],
sprayPoint[1] - sp.Spray[0][1],
})
}
}
if !sprayFound {
@@ -105,9 +104,10 @@ func (s *Sprays) Avg() (avg [][]float32) {
return
}
func (p *DemoParser) Setup(db *ent.Client, worker int) error {
func (p *DemoParser) Setup(db *ent.Client, worker int, sprayTimeout int) error {
p.demoQueue = make(chan *Demo, 1000)
p.db = db
p.sprayTimeout = sprayTimeout
for i := 0; i < worker; i++ {
go p.parseWorker()
}
@@ -267,7 +267,7 @@ func (p *DemoParser) parseWorker() {
for _, spray := range spays {
if e.Shooter.SteamID64 == spray.Sprayer && int(e.Weapon.Type) == spray.Weapon {
playerWeaponFound = true
spray.Add(demoParser.CurrentTime(), []float32{e.Shooter.ViewDirectionX(), e.Shooter.ViewDirectionY()}, 500, 10)
spray.Add(demoParser.CurrentTime(), []float32{e.Shooter.ViewDirectionX(), e.Shooter.ViewDirectionY()}, p.sprayTimeout)
}
}