Skip to content

Commit

Permalink
Merge pull request #3011 from b-r-a-n/master
Browse files Browse the repository at this point in the history
Adds a simple 'interactive mode' that can be used to yield rotation c…
  • Loading branch information
b-r-a-n authored Apr 30, 2023
2 parents bb18af7 + 9afd882 commit abf20e0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 7 deletions.
15 changes: 13 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,22 @@ release: wowsimwotlk wowsimwotlk-windows.exe
sim/core/proto/api.pb.go: proto/*.proto
protoc -I=./proto --go_out=./sim/core ./proto/*.proto

.PHONY: lib
lib:
# Only useful for building the lib on a host platform that matches the target platform
.PHONY: locallib
locallib:
protoc -I=./proto --go_out=./sim/core ./proto/*.proto
go build -buildmode=c-shared -o wowsimwotlk.so ./sim/lib/library.go

.PHONY: nixlib
nixlib:
protoc -I=./proto --go_out=./sim/core ./proto/*.proto
GOOS=linux GOARCH=amd64 GOAMD64=v2 go build -buildmode=c-shared -o wowsimwotlk-linux.so ./sim/lib/library.go

.PHONY: winlib
winlib:
protoc -I=./proto --go_out=./sim/core ./proto/*.proto
GOOS=windows GOARCH=amd64 GOAMD64=v2 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -buildmode=c-shared -o wowsimwotlk-windows.dll ./sim/lib/library.go

.PHONY: items
items: sim/core/items/all_items.go sim/core/proto/api.pb.go

Expand Down
1 change: 1 addition & 0 deletions proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ message SimOptions {
bool debug_first_iteration = 6;
bool is_test = 5; // Only used internally.
bool save_all_values = 7; // Only used internally.
bool interactive = 8; // Enables interactive mode.
}

// The aggregated results from all uses of a particular action.
Expand Down
12 changes: 9 additions & 3 deletions sim/core/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ func (aa *AutoAttacks) TrySwingMH(sim *Simulation, target *Unit) {
aa.MainhandSwingAt = sim.CurrentTime + aa.MainhandSwingSpeed()
aa.previousMHSwingAt = sim.CurrentTime
aa.PreviousSwingAt = sim.CurrentTime
aa.agent.OnAutoAttack(sim, attackSpell)
if !sim.Options.Interactive {
aa.agent.OnAutoAttack(sim, attackSpell)
}
}

// Optionally replaces the given swing spell with an Agent-specified MH Swing replacer.
Expand Down Expand Up @@ -549,7 +551,9 @@ func (aa *AutoAttacks) TrySwingOH(sim *Simulation, target *Unit) {
aa.OHAuto.Cast(sim, target)
aa.OffhandSwingAt = sim.CurrentTime + aa.OffhandSwingSpeed()
aa.PreviousSwingAt = sim.CurrentTime
aa.agent.OnAutoAttack(sim, aa.OHAuto)
if !sim.Options.Interactive {
aa.agent.OnAutoAttack(sim, aa.OHAuto)
}
}

// Performs an autoattack using the ranged weapon, if the ranged CD is ready.
Expand All @@ -561,7 +565,9 @@ func (aa *AutoAttacks) TrySwingRanged(sim *Simulation, target *Unit) {
aa.RangedAuto.Cast(sim, target)
aa.RangedSwingAt = sim.CurrentTime + aa.RangedSwingSpeed()
aa.PreviousSwingAt = sim.CurrentTime
aa.agent.OnAutoAttack(sim, aa.RangedAuto)
if !sim.Options.Interactive {
aa.agent.OnAutoAttack(sim, aa.RangedAuto)
}
}

func (aa *AutoAttacks) UpdateSwingTime(sim *Simulation) {
Expand Down
8 changes: 8 additions & 0 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ func (character *Character) initialize(agent Agent) {
return
}

if sim.Options.Interactive {
if character.GCD.IsReady(sim) {
sim.NeedsInput = true
character.doNothing = false
}
return
}

if character.Rotation != nil {
character.Rotation.DoNextAction(sim)
return
Expand Down
2 changes: 1 addition & 1 deletion sim/core/energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (unit *Unit) EnableEnergyBar(maxEnergy float64, onEnergyGain OnEnergyGain)
unit: unit,
maxEnergy: MaxFloat(100, maxEnergy),
onEnergyGain: func(sim *Simulation) {
if !unit.IsWaitingForEnergy() || unit.DoneWaitingForEnergy(sim) {
if !sim.Options.Interactive && (!unit.IsWaitingForEnergy() || unit.DoneWaitingForEnergy(sim)) {
onEnergyGain(sim)
}
},
Expand Down
4 changes: 3 additions & 1 deletion sim/core/rage.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ func (rb *rageBar) AddRage(sim *Simulation, amount float64, metrics *ResourceMet
}

rb.currentRage = newRage
rb.onRageGain(sim)
if !sim.Options.Interactive {
rb.onRageGain(sim)
}
}

func (rb *rageBar) SpendRage(sim *Simulation, amount float64, metrics *ResourceMetrics) {
Expand Down
1 change: 1 addition & 0 deletions sim/core/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Simulation struct {
pendingActions []*PendingAction
CurrentTime time.Duration // duration that has elapsed in the sim since starting
Duration time.Duration // Duration of current iteration
NeedsInput bool // Sim is in interactive mode and needs input

ProgressReport func(*proto.ProgressMetrics)

Expand Down
8 changes: 8 additions & 0 deletions sim/lib/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func trySpell(act int) bool {
if spell.CanCast(_active_sim, target) {
casted = spell.Cast(_active_sim, target)
}
if casted {
_active_sim.NeedsInput = false
}
return casted
}

Expand Down Expand Up @@ -221,6 +224,11 @@ func step() bool {
return _active_sim.Step(core.NeverExpires)
}

//export needsInput
func needsInput() bool {
return _active_sim.NeedsInput
}

//export cleanup
func cleanup() {
_active_sim.Cleanup()
Expand Down

0 comments on commit abf20e0

Please sign in to comment.