Skip to content

Commit

Permalink
- removed debug
Browse files Browse the repository at this point in the history
- updated tests
- slight cleanups
  • Loading branch information
vigo2 committed Oct 13, 2023
1 parent f60f940 commit faa8f44
Show file tree
Hide file tree
Showing 14 changed files with 1,617 additions and 1,716 deletions.
7 changes: 2 additions & 5 deletions sim/core/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,14 @@ func (at *auraTracker) advance(sim *Simulation) time.Duration {
}

restart:
minExpires := NeverExpires
at.minExpires = NeverExpires
for _, aura := range at.activeAuras {
if aura.expires <= sim.CurrentTime && aura.expires != 0 {
aura.Deactivate(sim)
goto restart // activeAuras have changed
}
if aura.expires < minExpires {
minExpires = aura.expires
}
at.minExpires = min(at.minExpires, aura.expires)
}
at.minExpires = minExpires
return at.minExpires
}

Expand Down
17 changes: 0 additions & 17 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,6 @@ func (character *Character) FillPlayerStats(playerStats *proto.PlayerStats) {
}
}

func (character *Character) init(sim *Simulation) {
character.Unit.init(sim)
}

func (character *Character) reset(sim *Simulation, agent Agent) {
character.Unit.reset(sim, agent)
character.majorCooldownManager.reset(sim)
Expand All @@ -512,19 +508,6 @@ func (character *Character) reset(sim *Simulation, agent Agent) {
}
}

// Advance moves time forward counting down auras, CDs, mana regen, etc
func (character *Character) advance(sim *Simulation) time.Duration {
minExpires := character.Unit.advance(sim)

for _, pet := range character.Pets {
if pet.enabled {
minExpires = min(minExpires, pet.Unit.advance(sim))
}
}

return minExpires
}

func (character *Character) HasProfession(prof proto.Profession) bool {
return prof == character.professions[0] || prof == character.professions[1]
}
Expand Down
5 changes: 1 addition & 4 deletions sim/core/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,7 @@ func (pet *Pet) Disable(sim *Simulation) {

if sim.Log != nil {
pet.Log(sim, "Pet dismissed")

if sim.Log != nil {
pet.Log(sim, pet.GetStats().String())
}
pet.Log(sim, pet.GetStats().String())
}
}

Expand Down
84 changes: 4 additions & 80 deletions sim/core/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ func (sim *Simulation) rescheduleTracker(trackerTime time.Duration) {
}

func (sim *Simulation) addTracker(tracker *auraTracker) {
if idx := slices.Index(sim.trackers, tracker); idx != -1 {
log.Panic("addTracker() adding duplicate tracker")
}
sim.trackers = append(sim.trackers, tracker)
sim.minTrackerTime = min(sim.minTrackerTime, tracker.minExpires)
sim.rescheduleTracker(tracker.minExpires)
}

func (sim *Simulation) removeTracker(tracker *auraTracker) {
Expand Down Expand Up @@ -527,83 +524,10 @@ func (sim *Simulation) advance(nextTime time.Duration) {
}
}

/*
minTrackerTimeShould := NeverExpires
trackersShould := make([]*auraTracker, 0, len(sim.trackers))
for _, character := range sim.characters {
minTrackerTimeShould = min(minTrackerTimeShould, character.minExpires)
trackersShould = append(trackersShould, &character.auraTracker)
for _, pet := range character.Pets {
if pet.enabled {
minTrackerTimeShould = min(minTrackerTimeShould, pet.minExpires)
trackersShould = append(trackersShould, &pet.auraTracker)
}
}
}
for _, target := range sim.Encounter.Targets {
minTrackerTimeShould = min(minTrackerTimeShould, target.minExpires)
trackersShould = append(trackersShould, &target.auraTracker)
}
// DEBUG minTrackerTime
if sim.minTrackerTime > minTrackerTimeShould {
log.Printf("%.3f - minTrackerTime %s > should %s", sim.CurrentTime.Seconds(), sim.minTrackerTime, minTrackerTimeShould)
for i, character := range sim.characters {
log.Printf("character[%d] - %s", i, character.minExpires)
for j, pet := range character.Pets {
if pet.enabled {
log.Printf("character[%d].pet[%d] - %s", i, j, pet.minExpires)
}
}
}
for i, target := range sim.Encounter.Targets {
log.Printf("target[%d] - %s", i, target.minExpires)
}
log.Fatalf("%.3f - minTrackerTime %s > should %s", sim.CurrentTime.Seconds(), sim.minTrackerTime, minTrackerTimeShould)
}
// DEBUG trackers
if len(sim.trackers) != len(trackersShould) {
log.Printf("%.3f - trackers %d, should %d", sim.CurrentTime.Seconds(), len(sim.trackers), len(trackersShould))
for i, character := range sim.characters {
log.Printf("character[%d] - added = %t", i, slices.Contains(sim.trackers, &character.auraTracker))
for j, pet := range character.Pets {
if pet.enabled {
log.Printf("character[%d].pet[%d] - added = %t", i, j, slices.Contains(sim.trackers, &pet.auraTracker))
}
}
}
for i, target := range sim.Encounter.Targets {
log.Printf("target[%d] - added = %t", i, slices.Contains(sim.trackers, &target.auraTracker))
}
log.Fatalf("%.3f - trackers %d, should %d", sim.CurrentTime.Seconds(), len(sim.trackers), len(trackersShould))
}
*/

if sim.CurrentTime >= sim.minTrackerTime {
if true {
for _, at := range sim.trackers {
sim.minTrackerTime = min(sim.minTrackerTime, at.advance(sim))
}
} else {
sim.minTrackerTime = NeverExpires
for _, character := range sim.characters {
sim.minTrackerTime = min(sim.minTrackerTime, character.advance(sim))
}

for _, target := range sim.Encounter.Targets {
sim.minTrackerTime = min(sim.minTrackerTime, target.advance(sim))
}
sim.minTrackerTime = sim.trackers[0].advance(sim)
for _, at := range sim.trackers[1:] {
sim.minTrackerTime = min(sim.minTrackerTime, at.advance(sim))
}
}
}
Expand Down
Loading

0 comments on commit faa8f44

Please sign in to comment.