Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix APL oom detection #3922

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading