Skip to content

Commit

Permalink
fix APL oom detection (#3922)
Browse files Browse the repository at this point in the history
  • Loading branch information
lime-green authored Oct 20, 2023
1 parent cd3c64f commit b332a54
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sim/core/apl.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func (apl *APLRotation) DoNextAction(sim *Simulation) {

i := 0
apl.inLoop = true
apl.unit.StartAPLLoop(sim)

for nextAction := apl.getNextAction(sim); nextAction != nil; i, nextAction = i+1, apl.getNextAction(sim) {
if i > 1000 {
panic(fmt.Sprintf("[USER_ERROR] Infinite loop detected, current action:\n%s", nextAction))
Expand All @@ -206,11 +208,14 @@ func (apl *APLRotation) DoNextAction(sim *Simulation) {
apl.unit.Log(sim, "No available actions!")
}

if apl.unit.GCD.IsReady(sim) {
gcdReady := apl.unit.GCD.IsReady(sim)
if gcdReady {
apl.unit.WaitUntil(sim, sim.CurrentTime+time.Millisecond*50)
} else {
apl.unit.DoNothing()
}

apl.unit.DoneAPLLoop(sim, gcdReady)
}

func (apl *APLRotation) getNextAction(sim *Simulation) *APLAction {
Expand Down
5 changes: 5 additions & 0 deletions sim/core/mana.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,14 @@ func (sim *Simulation) initManaTickAction() {
for _, player := range playersWithManaBars {
char := player.GetCharacter()
char.ManaTick(sim)

if char.OnManaTick != nil {
// Only execute APL actions after mana ticks once pre-pull has completed.
if char.IsUsingAPL && sim.CurrentTime > 0 {
if char.IsWaitingForMana() && !char.DoneWaitingForMana(sim) {
continue
}

char.Rotation.DoNextAction(sim)
} else {
char.OnManaTick(sim)
Expand Down
8 changes: 8 additions & 0 deletions sim/core/spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ func (spell *Spell) CanCast(sim *Simulation, target *Unit) bool {
//if sim.Log != nil {
// sim.Log("Cant cast because of resource cost")
//}
_, isManaCost := spell.Cost.(*ManaCost)
if isManaCost && spell.CurCast.Cost > 0 {
if spell.Unit.ManaRequired > 0 {
spell.Unit.ManaRequired = min(spell.Unit.ManaRequired, spell.CurCast.Cost)
} else {
spell.Unit.ManaRequired = spell.CurCast.Cost
}
}
return false
}
}
Expand Down
15 changes: 15 additions & 0 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ type Unit struct {

// The currently-channeled DOT spell, otherwise nil.
ChanneledDot *Dot

ManaRequired float64
}

// Units can be disabled for several reasons:
Expand Down Expand Up @@ -561,3 +563,16 @@ func (unit *Unit) GetMetadata() *proto.UnitMetadata {

return metadata
}

func (unit *Unit) StartAPLLoop(sim *Simulation) {
if unit.HasManaBar() {
unit.ManaRequired = 0
}
}

func (unit *Unit) DoneAPLLoop(sim *Simulation, usedGCD bool) {
if unit.HasManaBar() && !usedGCD && unit.ManaRequired > 0 {
unit.WaitForMana(sim, unit.ManaRequired)
unit.ManaRequired = 0
}
}

0 comments on commit b332a54

Please sign in to comment.