Skip to content

Commit

Permalink
[core] change MajorCooldown.Priority from float64 to int32
Browse files Browse the repository at this point in the history
[everywhere] replaced core.MinDuration, core.MaxDuration, and core.MaxTristate by min/max as well
[everywhere] changed some min(min(...)) and similar constructs to use multi-value min(...) instead
  • Loading branch information
vigo2 committed Oct 2, 2023
1 parent 4919fd2 commit 907d922
Show file tree
Hide file tree
Showing 50 changed files with 214 additions and 254 deletions.
6 changes: 3 additions & 3 deletions sim/common/gcd_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (gs *GCDScheduler) ScheduleMCD(character *core.Character, mcdID core.Action
maxDuration := character.Env.GetMaxDuration()
i := 0
if len(timings) > 0 {
curTime = core.MaxDuration(curTime, timings[0])
curTime = max(curTime, timings[0])
}
for curTime <= maxDuration {
ability := mcdAction
Expand All @@ -256,12 +256,12 @@ func (gs *GCDScheduler) ScheduleMCD(character *core.Character, mcdID core.Action
curTime = actualCastAt + mcd.Spell.CD.Duration
i++
if len(timings) > i {
curTime = core.MaxDuration(curTime, timings[i])
curTime = max(curTime, timings[i])
}
}
}

func (gs *GCDScheduler) Reset(sim *core.Simulation, character *core.Character) {
func (gs *GCDScheduler) Reset(_ *core.Simulation, character *core.Character) {
gs.nextAbilityIndex = 0

for i, mcdID := range gs.managedMCDIDs {
Expand Down
4 changes: 2 additions & 2 deletions sim/core/apl_values_auto_attacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type APLValueAutoTimeToNext struct {
unit *Unit
}

func (rot *APLRotation) newValueAutoTimeToNext(config *proto.APLValueAutoTimeToNext) APLValue {
func (rot *APLRotation) newValueAutoTimeToNext(_ *proto.APLValueAutoTimeToNext) APLValue {
return &APLValueAutoTimeToNext{
unit: rot.unit,
}
Expand All @@ -20,7 +20,7 @@ func (value *APLValueAutoTimeToNext) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueAutoTimeToNext) GetDuration(sim *Simulation) time.Duration {
return MaxDuration(0, value.unit.AutoAttacks.NextAttackAt()-sim.CurrentTime)
return max(0, value.unit.AutoAttacks.NextAttackAt()-sim.CurrentTime)
}
func (value *APLValueAutoTimeToNext) String() string {
return "Auto Time To Next"
Expand Down
24 changes: 12 additions & 12 deletions sim/core/apl_values_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func (rot *APLRotation) newValueConst(config *proto.APLValueConst) APLValue {
func (value *APLValueConst) Type() proto.APLValueType {
return value.valType
}
func (value *APLValueConst) GetBool(sim *Simulation) bool {
func (value *APLValueConst) GetBool(_ *Simulation) bool {
return value.boolVal
}
func (value *APLValueConst) GetInt(sim *Simulation) int32 {
func (value *APLValueConst) GetInt(_ *Simulation) int32 {
return value.intVal
}
func (value *APLValueConst) GetFloat(sim *Simulation) float64 {
func (value *APLValueConst) GetFloat(_ *Simulation) float64 {
return value.floatVal
}
func (value *APLValueConst) GetDuration(sim *Simulation) time.Duration {
func (value *APLValueConst) GetDuration(_ *Simulation) time.Duration {
return value.durationVal
}
func (value *APLValueConst) GetString(sim *Simulation) string {
func (value *APLValueConst) GetString(_ *Simulation) string {
return value.stringVal
}
func (value *APLValueConst) String() string {
Expand Down Expand Up @@ -500,7 +500,7 @@ func (value *APLValueMax) GetFloat(sim *Simulation) float64 {
func (value *APLValueMax) GetDuration(sim *Simulation) time.Duration {
result := value.vals[0].GetDuration(sim)
for i := 1; i < len(value.vals); i++ {
result = MaxDuration(result, value.vals[i].GetDuration(sim))
result = max(result, value.vals[i].GetDuration(sim))
}
return result
}
Expand Down Expand Up @@ -536,22 +536,22 @@ func (value *APLValueMin) Type() proto.APLValueType {
}
func (value *APLValueMin) GetInt(sim *Simulation) int32 {
result := value.vals[0].GetInt(sim)
for i := 1; i < len(value.vals); i++ {
result = min(result, value.vals[i].GetInt(sim))
for _, v := range value.vals[1:] {
result = min(result, v.GetInt(sim))
}
return result
}
func (value *APLValueMin) GetFloat(sim *Simulation) float64 {
result := value.vals[0].GetFloat(sim)
for i := 1; i < len(value.vals); i++ {
result = min(result, value.vals[i].GetFloat(sim))
for _, v := range value.vals[1:] {
result = min(result, v.GetFloat(sim))
}
return result
}
func (value *APLValueMin) GetDuration(sim *Simulation) time.Duration {
result := value.vals[0].GetDuration(sim)
for i := 1; i < len(value.vals); i++ {
result = MinDuration(result, value.vals[i].GetDuration(sim))
for _, v := range value.vals[1:] {
result = min(result, v.GetDuration(sim))
}
return result
}
Expand Down
6 changes: 3 additions & 3 deletions sim/core/apl_values_runes.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (value *APLValueRuneCooldown) GetDuration(sim *Simulation) time.Duration {
case proto.APLValueRuneType_RuneUnholy:
returnValue = value.unit.UnholyRuneReadyAt(sim) - sim.CurrentTime
}
return MaxDuration(0, returnValue)
return max(0, returnValue)
}
func (value *APLValueRuneCooldown) String() string {
return fmt.Sprintf("Rune Cooldown(%s)", value.runeType)
Expand Down Expand Up @@ -199,7 +199,7 @@ func (value *APLValueNextRuneCooldown) GetDuration(sim *Simulation) time.Duratio
case proto.APLValueRuneType_RuneUnholy:
returnValue = value.unit.NextUnholyRuneReadyAt(sim) - sim.CurrentTime
}
return MaxDuration(0, returnValue)
return max(0, returnValue)
}
func (value *APLValueNextRuneCooldown) String() string {
return fmt.Sprintf("Next Rune Cooldown(%s)", value.runeType)
Expand All @@ -226,7 +226,7 @@ func (value *APLValueRuneSlotCooldown) Type() proto.APLValueType {
return proto.APLValueType_ValueTypeDuration
}
func (value *APLValueRuneSlotCooldown) GetDuration(sim *Simulation) time.Duration {
return MaxDuration(0, value.unit.RuneReadyAt(sim, value.runeSlot)-sim.CurrentTime)
return max(0, value.unit.RuneReadyAt(sim, value.runeSlot)-sim.CurrentTime)
}
func (value *APLValueRuneSlotCooldown) String() string {
return fmt.Sprintf("Rune Slot Cooldown(%d)", value.runeSlot)
Expand Down
2 changes: 1 addition & 1 deletion sim/core/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func (unit *Unit) applyParryHaste() {
return
}

parryHasteReduction := MinDuration(defaultReduction, remainingTime-minRemainingTime)
parryHasteReduction := min(defaultReduction, remainingTime-minRemainingTime)
newReadyAt := aura.Unit.AutoAttacks.MainhandSwingAt - parryHasteReduction
if sim.Log != nil {
aura.Unit.Log(sim, "MH Swing reduced by %s due to parry haste, will now occur at %s", parryHasteReduction, newReadyAt)
Expand Down
6 changes: 3 additions & 3 deletions sim/core/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (at *auraTracker) RegisterResetEffect(resetEffect ResetEffect) {
at.resetEffects = append(at.resetEffects, resetEffect)
}

func (at *auraTracker) init(sim *Simulation) {
func (at *auraTracker) init(_ *Simulation) {
// Auras are initialized later, on their first reset().
}

Expand Down Expand Up @@ -646,9 +646,9 @@ func (aura *Aura) Deactivate(sim *Simulation) {

if !aura.ActionID.IsEmptyAction() {
if sim.CurrentTime > aura.expires {
aura.metrics.Uptime += aura.expires - MaxDuration(aura.startTime, 0)
aura.metrics.Uptime += aura.expires - max(aura.startTime, 0)
} else {
aura.metrics.Uptime += sim.CurrentTime - MaxDuration(aura.startTime, 0)
aura.metrics.Uptime += sim.CurrentTime - max(aura.startTime, 0)
}
}

Expand Down
20 changes: 7 additions & 13 deletions sim/core/buffs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"cmp"
"math"
"slices"
"strconv"
Expand Down Expand Up @@ -29,7 +30,7 @@ func applyBuffEffects(agent Agent, raidBuffs *proto.RaidBuffs, partyBuffs *proto
}

if raidBuffs.DrumsOfTheWild {
raidBuffs.GiftOfTheWild = MaxTristate(raidBuffs.GiftOfTheWild, proto.TristateEffect_TristateEffectRegular)
raidBuffs.GiftOfTheWild = max(raidBuffs.GiftOfTheWild, proto.TristateEffect_TristateEffectRegular)
}
gotwAmount := GetTristateValueFloat(raidBuffs.GiftOfTheWild, 37, 51)
gotwArmorAmount := GetTristateValueFloat(raidBuffs.GiftOfTheWild, 750, 1050)
Expand Down Expand Up @@ -236,7 +237,7 @@ func applyBuffEffects(agent Agent, raidBuffs *proto.RaidBuffs, partyBuffs *proto
character.PseudoStats.CastSpeedMultiplier *= 1.05
}
if raidBuffs.StrengthOfEarthTotem > 0 || raidBuffs.HornOfWinter {
val := MaxTristate(proto.TristateEffect_TristateEffectRegular, raidBuffs.StrengthOfEarthTotem)
val := max(proto.TristateEffect_TristateEffectRegular, raidBuffs.StrengthOfEarthTotem)
bonus := GetTristateValueFloat(val, 155, 178)
character.AddStats(stats.Stats{
stats.Strength: bonus,
Expand All @@ -257,7 +258,7 @@ func applyBuffEffects(agent Agent, raidBuffs *proto.RaidBuffs, partyBuffs *proto

if individualBuffs.BlessingOfWisdom > 0 || raidBuffs.ManaSpringTotem > 0 {
character.AddStats(stats.Stats{
stats.MP5: GetTristateValueFloat(MaxTristate(individualBuffs.BlessingOfWisdom, raidBuffs.ManaSpringTotem), 91, 109),
stats.MP5: GetTristateValueFloat(max(individualBuffs.BlessingOfWisdom, raidBuffs.ManaSpringTotem), 91, 109),
})
}

Expand Down Expand Up @@ -484,7 +485,7 @@ func BlessingOfSanctuaryAura(character *Character) {
type externalConsecutiveCDApproximation struct {
ActionID ActionID
AuraTag string
CooldownPriority float64
CooldownPriority int32
Type CooldownType
AuraDuration time.Duration
AuraCD time.Duration
Expand Down Expand Up @@ -1161,7 +1162,7 @@ func registerManaTideTotemCD(agent Agent, numManaTideTotems int32) {
character := agent.GetCharacter()
character.Env.RegisterPostFinalizeEffect(func() {
// Use first MTT at 60s, or halfway through the fight, whichever comes first.
initialDelay = MinDuration(character.Env.BaseDuration/2, time.Second*60)
initialDelay = min(character.Env.BaseDuration/2, time.Second*60)
mttAura = ManaTideTotemAura(character, -1)
})

Expand Down Expand Up @@ -1308,14 +1309,7 @@ func (raid *Raid) ProcReplenishment(sim *Simulation, src ReplenishmentSource) {

eligible := append(raid.curReplenishmentUnits[src], raid.leftoverReplenishmentUnits...)
slices.SortFunc(eligible, func(v1, v2 *Unit) int {
v1Mana := v1.CurrentManaPercent()
v2Mana := v2.CurrentManaPercent()
if v1Mana > v2Mana {
return 1
} else if v2Mana > v1Mana {
return -1
}
return 0
return cmp.Compare(v1.CurrentManaPercent(), v2.CurrentManaPercent())
})
raid.curReplenishmentUnits[src] = eligible[:10]
raid.leftoverReplenishmentUnits = eligible[10:]
Expand Down
4 changes: 2 additions & 2 deletions sim/core/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func (cast *Cast) EffectiveTime() time.Duration {
gcd := cast.GCD
if cast.GCD != 0 {
// TODO: isn't this wrong for spells like shadowfury, that have a reduced GCD?
gcd = MaxDuration(GCDMin, gcd)
gcd = max(GCDMin, gcd)
}
fullCastTime := cast.CastTime + cast.ChannelTime + cast.AfterCastDelay
return MaxDuration(gcd, fullCastTime)
return max(gcd, fullCastTime)
}

type CastFunc func(*Simulation, *Unit)
Expand Down
4 changes: 2 additions & 2 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func NewCharacter(party *Party, partyIndex int, player *proto.Player) Character

StatDependencyManager: stats.NewStatDependencyManager(),

ReactionTime: MaxDuration(0, time.Duration(player.ReactionTimeMs)*time.Millisecond),
ChannelClipDelay: MaxDuration(0, time.Duration(player.ChannelClipDelayMs)*time.Millisecond),
ReactionTime: max(0, time.Duration(player.ReactionTimeMs)*time.Millisecond),
ChannelClipDelay: max(0, time.Duration(player.ChannelClipDelayMs)*time.Millisecond),
DistanceFromTarget: player.DistanceFromTarget,
IsUsingAPL: player.Rotation != nil && player.Rotation.Type == proto.APLRotation_TypeAPL,
},
Expand Down
8 changes: 4 additions & 4 deletions sim/core/consumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,15 @@ func registerExplosivesCD(agent Agent, consumes *proto.Consumes) {
character.AddMajorCooldown(MajorCooldown{
Spell: character.newThermalSapperSpell(sharedTimer),
Type: CooldownTypeDPS | CooldownTypeExplosive,
Priority: CooldownPriorityLow + 0.03,
Priority: CooldownPriorityLow + 30,
})
}

if consumes.ExplosiveDecoy {
character.AddMajorCooldown(MajorCooldown{
Spell: character.newExplosiveDecoySpell(sharedTimer),
Type: CooldownTypeDPS | CooldownTypeExplosive,
Priority: CooldownPriorityLow + 0.02,
Priority: CooldownPriorityLow + 20,
ShouldActivate: func(sim *Simulation, character *Character) bool {
// Decoy puts other explosives on 2m CD, so only use if there won't be enough
// time to use another explosive OR there is no filler explosive.
Expand All @@ -967,13 +967,13 @@ func registerExplosivesCD(agent Agent, consumes *proto.Consumes) {
character.AddMajorCooldown(MajorCooldown{
Spell: filler,
Type: CooldownTypeDPS | CooldownTypeExplosive,
Priority: CooldownPriorityLow + 0.01,
Priority: CooldownPriorityLow + 10,
})
}
}

// Creates a spell object for the common explosive case.
func (character *Character) newBasicExplosiveSpellConfig(sharedTimer *Timer, actionID ActionID, school SpellSchool, minDamage float64, maxDamage float64, cooldown Cooldown, minSelfDamage float64, maxSelfDamage float64) SpellConfig {
func (character *Character) newBasicExplosiveSpellConfig(sharedTimer *Timer, actionID ActionID, school SpellSchool, minDamage float64, maxDamage float64, cooldown Cooldown, _ float64, _ float64) SpellConfig {
dealSelfDamage := actionID.SameAction(ThermalSapperActionID)

return SpellConfig{
Expand Down
8 changes: 4 additions & 4 deletions sim/core/cooldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (unit *Unit) NewTimer() *Timer {
return newTimer
}

func (unit *Unit) resetCDs(sim *Simulation) {
func (unit *Unit) resetCDs(_ *Simulation) {
for _, timer := range unit.cdTimers {
timer.Reset()
}
Expand All @@ -46,7 +46,7 @@ func (timer *Timer) Reset() {
}

func (timer *Timer) TimeToReady(sim *Simulation) time.Duration {
return MaxDuration(0, time.Duration(*timer)-sim.CurrentTime)
return max(0, time.Duration(*timer)-sim.CurrentTime)
}

func (timer *Timer) IsReady(sim *Simulation) bool {
Expand All @@ -64,7 +64,7 @@ func BothTimersReadyAt(t1 *Timer, t2 *Timer) time.Duration {
readyAt = t1.ReadyAt()
}
if t2 != nil {
readyAt = MaxDuration(readyAt, t2.ReadyAt())
readyAt = max(readyAt, t2.ReadyAt())
}
return readyAt
}
Expand All @@ -79,7 +79,7 @@ func MaxTimeToReady(t1 *Timer, t2 *Timer, sim *Simulation) time.Duration {
remaining = t1.TimeToReady(sim)
}
if t2 != nil {
remaining = MaxDuration(remaining, t2.TimeToReady(sim))
remaining = max(remaining, t2.TimeToReady(sim))
}
return remaining
}
Expand Down
23 changes: 9 additions & 14 deletions sim/core/major_cooldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

const (
CooldownPriorityLow = -1.0
CooldownPriorityDefault = 0.0
CooldownPriorityDrums = 2.0
CooldownPriorityBloodlust = 1.0
CooldownPriorityLow = -1000
CooldownPriorityDefault = 0
CooldownPriorityDrums = 2000
CooldownPriorityBloodlust = 1000
)

type CooldownType byte
Expand Down Expand Up @@ -44,7 +44,7 @@ type MajorCooldown struct {
// Cooldowns with higher priority get used first. This is important when some
// cooldowns have a non-zero cast time. For example, Drums should be used
// before Bloodlust.
Priority float64
Priority int32

// Internal category, used for filtering. For example, mages want to disable
// all DPS cooldowns during their regen rotation.
Expand Down Expand Up @@ -83,7 +83,7 @@ func (mcd *MajorCooldown) TimeToReady(sim *Simulation) time.Duration {
func (mcd *MajorCooldown) TimeToNextCast(sim *Simulation) time.Duration {
timeToReady := mcd.TimeToReady(sim)
if mcd.numUsages < len(mcd.timings) {
timeToReady = MaxDuration(timeToReady, mcd.timings[mcd.numUsages]-sim.CurrentTime)
timeToReady = max(timeToReady, mcd.timings[mcd.numUsages]-sim.CurrentTime)
}
return timeToReady
}
Expand Down Expand Up @@ -507,15 +507,10 @@ func (mcdm *majorCooldownManager) UpdateMajorCooldowns() {

func (mcdm *majorCooldownManager) sort() {
slices.SortStableFunc(mcdm.majorCooldowns, func(m1, m2 *MajorCooldown) int {
m1r := m1.ReadyAt()
m2r := m2.ReadyAt()
if m1r != m2r {
return int(m1r - m2r)
if r1, r2 := m1.ReadyAt(), m2.ReadyAt(); r1 != r2 {
return int(r1 - r2)
}
if m1.Priority > m2.Priority {
return -1
}
return 1
return int(m2.Priority - m1.Priority)
})
}

Expand Down
2 changes: 1 addition & 1 deletion sim/core/mana.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (mc *ManaCost) LogCostFailure(sim *Simulation, spell *Spell) {
func (mc *ManaCost) SpendCost(sim *Simulation, spell *Spell) {
if spell.CurCast.Cost > 0 {
spell.Unit.SpendMana(sim, spell.CurCast.Cost, mc.ResourceMetrics)
spell.Unit.PseudoStats.FiveSecondRuleRefreshTime = MaxDuration(sim.CurrentTime+time.Second*5, spell.Unit.Hardcast.Expires)
spell.Unit.PseudoStats.FiveSecondRuleRefreshTime = max(sim.CurrentTime+time.Second*5, spell.Unit.Hardcast.Expires)
}
}
func (mc *ManaCost) IssueRefund(_ *Simulation, _ *Spell) {}
2 changes: 1 addition & 1 deletion sim/core/metrics_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (unitMetrics *UnitMetrics) doneIteration(unit *Unit, sim *Simulation) {
manaSpentPerSecond := (unitMetrics.ManaSpent - unitMetrics.ManaGained) / encounterDurationSeconds
remainingTTO := DurationFromSeconds(unit.CurrentMana() / manaSpentPerSecond)
timeToOOM = DurationFromSeconds(encounterDurationSeconds) + remainingTTO
timeToOOM = MinDuration(timeToOOM, time.Minute*60)
timeToOOM = min(timeToOOM, time.Minute*60)
}

if timeToOOM < 0 {
Expand Down
Loading

0 comments on commit 907d922

Please sign in to comment.