Fix segment repeating + cleanup speed calculation (#4557)

This commit is contained in:
NodudeWasTaken 2024-02-15 03:46:59 +01:00 committed by GitHub
parent dad4ab6a6f
commit 15aac68a14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 15 deletions

View File

@ -44,9 +44,7 @@ type Action struct {
// Pos is the place in percent to move to.
Pos int `json:"pos"`
Slope float64
Intensity int64
Speed float64
Speed float64
}
type GradientTable []struct {
@ -136,8 +134,7 @@ func (funscript *Script) UpdateIntensityAndSpeed() {
var t1, t2 int64
var p1, p2 int
var slope float64
var intensity int64
var intensity float64
for i := range funscript.Actions {
if i == 0 {
continue
@ -147,13 +144,10 @@ func (funscript *Script) UpdateIntensityAndSpeed() {
p1 = funscript.Actions[i].Pos
p2 = funscript.Actions[i-1].Pos
slope = math.Min(math.Max(1/(2*float64(t1-t2)/1000), 0), 20)
intensity = int64(slope * math.Abs((float64)(p1-p2)))
speed := math.Abs(float64(p1-p2)) / float64(t1-t2) * 1000
speed := math.Abs(float64(p1 - p2))
intensity = float64(speed/float64(t1-t2)) * 1000
funscript.Actions[i].Slope = slope
funscript.Actions[i].Intensity = intensity
funscript.Actions[i].Speed = speed
funscript.Actions[i].Speed = intensity
}
}
@ -294,7 +288,7 @@ func (funscript Script) getGradientTable(numSegments int, sceneDurationMilli int
}
segments[segment].at = a.At
segments[segment].count++
segments[segment].intensity += int(a.Intensity)
segments[segment].intensity += int(a.Speed)
segments[segment].yRange[0] = averageTop
segments[segment].yRange[1] = averageBottom
}
@ -303,7 +297,7 @@ func (funscript Script) getGradientTable(numSegments int, sceneDurationMilli int
// Fill in gaps in segments
for i := 0; i < numSegments; i++ {
segmentTS := int64(float64(i) / float64(numSegments))
segmentTS := (maxts / int64(numSegments)) * int64(i)
// Empty segment - fill it with the previous up to backfillThreshold ms
if segments[i].count == 0 {
@ -340,12 +334,12 @@ func getSegmentColor(intensity float64) colorful.Color {
colorBlack, _ := colorful.Hex("#0f001e")
colorBackground, _ := colorful.Hex("#30404d") // Same as GridCard bg
var stepSize = 60.0
var stepSize = 125.0
var f float64
var c colorful.Color
switch {
case intensity <= 0.001:
case intensity <= 25:
c = colorBackground
case intensity <= 1*stepSize:
f = (intensity - 0*stepSize) / stepSize