Skip to content

Commit

Permalink
[core] remove the effectively unused sim.init() hierarchy
Browse files Browse the repository at this point in the history
[core] expire aura for disabled pets (so they don't start with buffs lasting until the next advance())
[core] don't call into "user land" before the internal aura tracker state is consistent (for aura.Deactivate())
  • Loading branch information
vigo2 committed Oct 19, 2023
1 parent f5e24b3 commit 1efc63d
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 420 deletions.
59 changes: 31 additions & 28 deletions sim/core/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,6 @@ func (at *auraTracker) RegisterResetEffect(resetEffect ResetEffect) {
at.resetEffects = append(at.resetEffects, resetEffect)
}

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

func (at *auraTracker) reset(sim *Simulation) {
at.activeAuras = at.activeAuras[:0]
at.onCastCompleteAuras = at.onCastCompleteAuras[:0]
Expand Down Expand Up @@ -490,7 +486,7 @@ func (at *auraTracker) advance(sim *Simulation) time.Duration {
restart:
at.minExpires = NeverExpires
for _, aura := range at.activeAuras {
if aura.expires <= sim.CurrentTime && aura.expires != 0 {
if aura.expires <= sim.CurrentTime {
aura.Deactivate(sim)
goto restart // activeAuras have changed
}
Expand All @@ -499,25 +495,29 @@ restart:
return at.minExpires
}

func (at *auraTracker) expireAll(sim *Simulation) {
restart:
for _, aura := range at.activeAuras {
aura.Deactivate(sim)
goto restart
}
at.minExpires = NeverExpires
}

func (at *auraTracker) doneIteration(sim *Simulation) {
// Expire all the remaining auras. Need to keep looping because sometimes
// expiring auras can trigger other auras.
foundUnexpired := true
for foundUnexpired {
foundUnexpired = false
for _, aura := range at.auras {
if aura.IsActive() {
foundUnexpired = true
aura.Deactivate(sim)
}
// deactivate all auras, even permanent ones
restart:
for _, aura := range at.auras {
if aura.active {
aura.Deactivate(sim)
goto restart
}
}

for _, aura := range at.auras {
aura.doneIteration(sim)
}

// Add metrics for any auras that are still active.
for _, aura := range at.auras {
aura.metrics.doneIteration()
}
Expand Down Expand Up @@ -612,6 +612,7 @@ func (aura *Aura) Activate(sim *Simulation) {
aura.Unit.Log(sim, "Aura gained: %s", aura.ActionID)
}

// don't invoke possible callbacks until the internal state is consistent
if aura.OnGain != nil {
aura.OnGain(aura, sim)
}
Expand All @@ -624,18 +625,6 @@ func (aura *Aura) Deactivate(sim *Simulation) {
}
aura.active = false

if aura.stacks != 0 {
aura.SetStacks(sim, 0)
}

// Deactivate exclusive effects.
for _, ee := range aura.ExclusiveEffects {
ee.Deactivate(sim)
}
if aura.OnExpire != nil {
aura.OnExpire(aura, sim)
}

if !aura.ActionID.IsEmptyAction() {
if sim.CurrentTime > aura.expires {
aura.metrics.Uptime += aura.expires - max(aura.startTime, 0)
Expand Down Expand Up @@ -738,6 +727,20 @@ func (aura *Aura) Deactivate(sim *Simulation) {
}
aura.onPeriodicHealTakenIndex = Inactive
}

// don't invoke possible callbacks until the internal state is consistent
if aura.stacks != 0 {
aura.SetStacks(sim, 0)
}

// Deactivate exclusive effects.
for _, ee := range aura.ExclusiveEffects {
ee.Deactivate(sim)
}

if aura.OnExpire != nil {
aura.OnExpire(aura, sim)
}
}

// Constant-time removal from slice by swapping with the last element before removing.
Expand Down
3 changes: 0 additions & 3 deletions sim/core/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ type Environment struct {
Encounter Encounter
AllUnits []*Unit

characters []*Character // "cached" in init(), for advance()

BaseDuration time.Duration // base duration
DurationVariation time.Duration // variation per duration

Expand Down Expand Up @@ -194,7 +192,6 @@ func (env *Environment) finalize(raidProto *proto.Raid, _ *proto.Encounter, raid
sim := newSimWithEnv(env, &proto.SimOptions{
Iterations: 1,
})
sim.Init()
sim.reset()
sim.PrePull()
sim.Cleanup()
Expand Down
2 changes: 2 additions & 0 deletions sim/core/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func (pet *Pet) Disable(sim *Simulation) {
pet.OnPetDisable(sim)
}

pet.auraTracker.expireAll(sim)

sim.removeTracker(&pet.auraTracker)

if sim.Log != nil {
Expand Down
21 changes: 0 additions & 21 deletions sim/core/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,25 +257,6 @@ func (sim *Simulation) Reseed(seed int64) {
sim.reseedRands(seed)
}

func (sim *Simulation) Init() {
for _, target := range sim.Encounter.Targets {
target.init(sim)
}

for _, party := range sim.Raid.Parties {
for _, player := range party.Players {
character := player.GetCharacter()
character.init(sim)

for _, pet := range character.Pets {
pet.init(sim)
}

sim.characters = append(sim.characters, character)
}
}
}

// Run runs the simulation for the configured number of iterations, and
// collects all the metrics together.
func (sim *Simulation) run() *proto.RaidSimResult {
Expand All @@ -294,8 +275,6 @@ func (sim *Simulation) run() *proto.RaidSimResult {
// fmt.Printf(fmt.Sprintf("[%0.1f] "+message+"\n", append([]interface{}{sim.CurrentTime.Seconds()}, vals...)...))
// }

sim.Init()

sim.runOnce()
firstIterationDuration := sim.Duration
if sim.Encounter.EndFightAtHealth != 0 {
Expand Down
4 changes: 0 additions & 4 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@ func (unit *Unit) finalize() {
}
}

func (unit *Unit) init(sim *Simulation) {
unit.auraTracker.init(sim)
}

func (unit *Unit) reset(sim *Simulation, _ Agent) {
unit.enabled = true
unit.resetCDs(sim)
Expand Down
32 changes: 16 additions & 16 deletions sim/deathknight/dps/TestUnholy.results
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-AllItems-BlessedBattlegearofUndeadSlaying"
value: {
dps: 8922.12473
tps: 5752.63543
dps: 8922.1323
tps: 5752.64694
hps: 259.25488
}
}
Expand Down Expand Up @@ -454,8 +454,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-AllItems-HatefulGladiator'sSigilofStrife-42619"
value: {
dps: 11999.96041
tps: 7973.39438
dps: 11999.9702
tps: 7973.40926
hps: 354.70907
}
}
Expand Down Expand Up @@ -678,8 +678,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-AllItems-SavageGladiator'sSigilofStrife-42618"
value: {
dps: 11993.79722
tps: 7968.59879
dps: 11993.807
tps: 7968.61366
hps: 354.70907
}
}
Expand All @@ -694,8 +694,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-AllItems-ScourgebornePlate"
value: {
dps: 8762.55163
tps: 5593.55439
dps: 8762.55823
tps: 5593.56442
hps: 284.94914
}
}
Expand Down Expand Up @@ -894,8 +894,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-AllItems-Thassarian'sBattlegear"
value: {
dps: 10116.60471
tps: 6593.78774
dps: 10116.61902
tps: 6593.8095
hps: 285.90184
}
}
Expand Down Expand Up @@ -1022,8 +1022,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-Average-Default"
value: {
dps: 12079.79774
tps: 7959.30783
dps: 12079.79755
tps: 7959.30754
hps: 319.10091
}
}
Expand All @@ -1038,8 +1038,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-Settings-Human-p3_uh_dw-Basic--FullBuffs-LongSingleTarget"
value: {
dps: 11918.71627
tps: 7937.39165
dps: 11918.70505
tps: 7937.3746
hps: 320.44626
}
}
Expand Down Expand Up @@ -1222,8 +1222,8 @@ dps_results: {
dps_results: {
key: "TestUnholy-Settings-Orc-p3_uh_dw-Basic--FullBuffs-LongMultiTarget"
value: {
dps: 58800.10394
tps: 61393.11759
dps: 58799.838
tps: 61392.71336
hps: 321.42877
}
}
Expand Down
8 changes: 4 additions & 4 deletions sim/hunter/TestBM.results
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ dps_results: {
dps_results: {
key: "TestBM-AllItems-Gronnstalker'sArmor"
value: {
dps: 5010.01957
tps: 3329.43898
dps: 5009.99192
tps: 3329.41133
}
}
dps_results: {
Expand Down Expand Up @@ -883,8 +883,8 @@ dps_results: {
dps_results: {
key: "TestBM-Average-Default"
value: {
dps: 6433.20289
tps: 4349.46161
dps: 6433.20261
tps: 4349.46133
}
}
dps_results: {
Expand Down
8 changes: 4 additions & 4 deletions sim/hunter/TestMM.results
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ dps_results: {
dps_results: {
key: "TestMM-AllItems-BlackBowoftheBetrayer-32336"
value: {
dps: 6686.52738
tps: 5771.94376
dps: 6686.53191
tps: 5771.94829
}
}
dps_results: {
Expand Down Expand Up @@ -883,8 +883,8 @@ dps_results: {
dps_results: {
key: "TestMM-Average-Default"
value: {
dps: 7344.09626
tps: 6425.47971
dps: 7344.09621
tps: 6425.47967
}
}
dps_results: {
Expand Down
Loading

0 comments on commit 1efc63d

Please sign in to comment.