Skip to content

Commit 0518d83

Browse files
authored
Merge pull request #344 from Wieku/dev
0.9.1
2 parents 59350ce + 5407724 commit 0518d83

File tree

10 files changed

+261
-135
lines changed

10 files changed

+261
-135
lines changed

app/beatmap/beatmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (beatMap *BeatMap) Reset() {
8888

8989
func (beatMap *BeatMap) Clear() {
9090
beatMap.HitObjects = make([]objects.IHitObject, 0)
91-
beatMap.Timings = objects.NewTimings()
91+
beatMap.Timings.Clear()
9292
}
9393

9494
func (beatMap *BeatMap) Update(time float64) {

app/beatmap/objects/timing.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ func (tim *Timings) HasPoints() bool {
162162
return len(tim.points) > 0
163163
}
164164

165+
func (tim *Timings) Clear() {
166+
tim.originalPoints = tim.originalPoints[:0]
167+
tim.points = tim.points[:0]
168+
169+
tim.Current = tim.defaultTimingPoint
170+
}
171+
165172
func (tim *Timings) Reset() {
166173
tim.Current = tim.points[0]
167174
}

app/beatmap/parser.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package beatmap
22

33
import (
4+
"cmp"
45
"errors"
56
"github.com/wieku/danser-go/app/beatmap/objects"
67
"github.com/wieku/danser-go/app/settings"
@@ -10,7 +11,7 @@ import (
1011
"math"
1112
"os"
1213
"path/filepath"
13-
"sort"
14+
"slices"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -342,8 +343,8 @@ func ParseObjects(beatMap *BeatMap, diffCalcOnly, parseColors bool) {
342343
}
343344
}
344345

345-
sort.SliceStable(beatMap.HitObjects, func(i, j int) bool {
346-
return beatMap.HitObjects[i].GetStartTime() < beatMap.HitObjects[j].GetStartTime()
346+
slices.SortStableFunc(beatMap.HitObjects, func(a, b objects.IHitObject) int {
347+
return cmp.Compare(a.GetStartTime(), b.GetStartTime())
347348
})
348349

349350
if parseColors {

app/rulesets/osu/healthprocessor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ func (hp *HealthProcessor) CalculateRate() { //nolint:gocyclo
126126
break
127127
}
128128

129-
hp.Increase(-hp.PassiveDrain*(o.GetEndTime()-o.GetStartTime()), false)
129+
decr := hp.PassiveDrain * (o.GetEndTime() - o.GetStartTime())
130+
hpUnder := min(0, hp.Health-decr)
131+
132+
hp.Increase(-decr, false)
130133

131134
if s, ok := o.(*objects.Slider); ok {
132135
for j := 0; j < len(s.TickReverse)+1; j++ {
@@ -143,6 +146,14 @@ func (hp *HealthProcessor) CalculateRate() { //nolint:gocyclo
143146
}
144147
}
145148

149+
//noinspection GoBoolExpressions - false positive
150+
if hpUnder < 0 && hp.Health+hpUnder <= lowestHpEver {
151+
fail = true
152+
hp.PassiveDrain *= 0.96
153+
154+
break
155+
}
156+
146157
if i == len(hp.beatMap.HitObjects)-1 || hp.beatMap.HitObjects[i+1].IsNewCombo() {
147158
hp.AddResult(Hit300g)
148159

app/rulesets/osu/slider.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (slider *Slider) UpdatePostFor(player *difficultyPlayer, time int64, proces
292292
state := slider.state[player]
293293

294294
if time > int64(slider.hitSlider.GetStartTime())+player.diff.Hit50 && !state.isStartHit {
295-
if len(slider.players) == 1 {
295+
if len(slider.players) == 1 && !state.isHit { //don't fade if slider already ended (and armed the start)
296296
slider.hitSlider.ArmStart(false, float64(time))
297297
}
298298

@@ -313,12 +313,8 @@ func (slider *Slider) UpdatePostFor(player *difficultyPlayer, time int64, proces
313313
}
314314

315315
if (time >= int64(slider.hitSlider.GetEndTime()) || (processSliderEndsAhead && int64(slider.hitSlider.GetEndTime())-time == 1)) && !state.isHit {
316-
if !state.isStartHit {
317-
if len(slider.players) == 1 {
318-
slider.hitSlider.ArmStart(false, float64(time))
319-
}
320-
321-
state.isStartHit = true
316+
if len(slider.players) == 1 && !state.isStartHit {
317+
slider.hitSlider.ArmStart(false, float64(time))
322318
}
323319

324320
if state.startResult != Miss {

app/rulesets/osu/spinner.go

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type spinnerstate struct {
1414
rotationCount int64
1515
lastRotationCount int64
1616
scoringRotationCount int64
17-
rotationCountF float64
17+
rotationCountF float32
1818
rotationCountFD float64
1919
frameVariance float64
2020
theoreticalVelocity float64
@@ -80,6 +80,36 @@ func (spinner *Spinner) UpdateFor(player *difficultyPlayer, time int64, _ bool)
8080
numFinishedTotal++
8181

8282
if player.cursor.IsReplayFrame && time > int64(spinner.hitSpinner.GetStartTime()) && time < int64(spinner.hitSpinner.GetEndTime()) {
83+
maxAccelThisFrame := player.diff.GetModifiedTime(spinner.maxAcceleration * timeDiff)
84+
85+
if player.diff.CheckModActive(difficulty.SpunOut) || player.diff.CheckModActive(difficulty.Relax2) {
86+
state.currentVelocity = 0.03
87+
} else if state.theoreticalVelocity > state.currentVelocity {
88+
accel := maxAccelThisFrame
89+
if state.currentVelocity < 0 && player.diff.CheckModActive(difficulty.Relax) {
90+
accel /= 4
91+
}
92+
93+
state.currentVelocity += min(state.theoreticalVelocity-state.currentVelocity, accel)
94+
} else {
95+
accel := -maxAccelThisFrame
96+
if state.currentVelocity > 0 && player.diff.CheckModActive(difficulty.Relax) {
97+
accel /= 4
98+
}
99+
100+
state.currentVelocity += max(state.theoreticalVelocity-state.currentVelocity, accel)
101+
}
102+
103+
state.currentVelocity = max(-0.05, min(state.currentVelocity, 0.05))
104+
105+
if len(spinner.players) == 1 {
106+
if state.currentVelocity == 0 {
107+
spinner.hitSpinner.PauseSpinSample()
108+
} else {
109+
spinner.hitSpinner.StartSpinSample()
110+
}
111+
}
112+
83113
decay1 := math.Pow(0.9, timeDiff/FrameTime)
84114
state.rpm = state.rpm*decay1 + (1.0-decay1)*(math.Abs(state.currentVelocity)*1000)/(math.Pi*2)*60
85115

@@ -118,7 +148,11 @@ func (spinner *Spinner) UpdateFor(player *difficultyPlayer, time int64, _ bool)
118148

119149
if math.Abs(angleDiff) < math.Pi {
120150
if player.diff.GetModifiedTime(state.frameVariance) > FrameTime*1.04 {
121-
state.theoreticalVelocity = angleDiff / player.diff.GetModifiedTime(timeDiff)
151+
if timeDiff > 0 {
152+
state.theoreticalVelocity = angleDiff / player.diff.GetModifiedTime(timeDiff)
153+
} else {
154+
state.theoreticalVelocity = 0
155+
}
122156
} else {
123157
state.theoreticalVelocity = angleDiff / FrameTime
124158
}
@@ -129,45 +163,15 @@ func (spinner *Spinner) UpdateFor(player *difficultyPlayer, time int64, _ bool)
129163

130164
state.lastAngle = mouseAngle
131165

132-
maxAccelThisFrame := player.diff.GetModifiedTime(spinner.maxAcceleration * timeDiff)
133-
134-
if player.diff.CheckModActive(difficulty.SpunOut) || player.diff.CheckModActive(difficulty.Relax2) {
135-
state.currentVelocity = 0.03
136-
} else if state.theoreticalVelocity > state.currentVelocity {
137-
accel := maxAccelThisFrame
138-
if state.currentVelocity < 0 && player.diff.CheckModActive(difficulty.Relax) {
139-
accel /= 4
140-
}
141-
142-
state.currentVelocity += min(state.theoreticalVelocity-state.currentVelocity, accel)
143-
} else {
144-
accel := -maxAccelThisFrame
145-
if state.currentVelocity > 0 && player.diff.CheckModActive(difficulty.Relax) {
146-
accel /= 4
147-
}
148-
149-
state.currentVelocity += max(state.theoreticalVelocity-state.currentVelocity, accel)
150-
}
151-
152-
state.currentVelocity = max(-0.05, min(state.currentVelocity, 0.05))
153-
154-
if len(spinner.players) == 1 {
155-
if state.currentVelocity == 0 {
156-
spinner.hitSpinner.PauseSpinSample()
157-
} else {
158-
spinner.hitSpinner.StartSpinSample()
159-
}
160-
}
161-
162166
rotationAddition := state.currentVelocity * timeDiff
163167

164168
state.rotationCountFD += rotationAddition
165-
state.rotationCountF += math.Abs(rotationAddition / math.Pi)
169+
state.rotationCountF += float32(math.Abs(float64(float32(rotationAddition)) / math.Pi))
166170

167171
if len(spinner.players) == 1 {
168172
spinner.hitSpinner.SetRotation(player.diff.GetModifiedTime(state.rotationCountFD))
169173
spinner.hitSpinner.SetRPM(state.rpm)
170-
spinner.hitSpinner.UpdateCompletion(state.rotationCountF / float64(state.requirement))
174+
spinner.hitSpinner.UpdateCompletion(float64(state.rotationCountF) / float64(state.requirement))
171175
}
172176

173177
state.rotationCount = int64(state.rotationCountF)

0 commit comments

Comments
 (0)