Skip to content

Commit

Permalink
Use core task impl for char/enemy tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
shizukayuki committed Nov 28, 2024
1 parent 1930932 commit f31064d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 49 deletions.
8 changes: 4 additions & 4 deletions pkg/core/player/character/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/genshinsim/gcsim/pkg/core/task"
"github.com/genshinsim/gcsim/pkg/model"
"github.com/genshinsim/gcsim/pkg/modifier"
"github.com/genshinsim/gcsim/pkg/queue"
)

type Character interface {
Expand Down Expand Up @@ -130,7 +129,7 @@ type CharWrapper struct {
// hitlag stuff
timePassed int // how many frames have passed since start of sim
frozenFrames int // how many frames are we still frozen for
queue []queue.Task
queue *task.Handler
}

func New(
Expand All @@ -139,7 +138,7 @@ func New(
debug bool, // are we running in debug mode
log glog.Logger, // logging, can be nil
events event.Eventter, // event emitter
task task.Tasker,
tasker task.Tasker,
) (*CharWrapper, error) {
c := &CharWrapper{
Base: p.Base,
Expand All @@ -148,12 +147,13 @@ func New(
ParticleDelay: 100, // default particle delay
log: log,
events: events,
tasks: task,
tasks: tasker,
Tags: make(map[string]int),
mods: make([]modifier.Mod, 0, 20),
f: f,
debug: debug,
}
c.queue = task.New(&c.timePassed)
s := (*[attributes.EndStatType]float64)(p.Stats)
c.BaseStats = *s
c.Equip.Sets = make(map[keys.Set]info.Set)
Expand Down
9 changes: 6 additions & 3 deletions pkg/core/player/character/hitlag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"math"

"github.com/genshinsim/gcsim/pkg/core/glog"
"github.com/genshinsim/gcsim/pkg/queue"
)

func (c *CharWrapper) QueueCharTask(f func(), delay int) {
queue.Add(&c.queue, f, c.timePassed+delay)
if delay == 0 {
f()
return
}
c.queue.Add(f, delay)
}

func (c *CharWrapper) Tick() {
Expand All @@ -28,7 +31,7 @@ func (c *CharWrapper) Tick() {
c.timePassed += left

// check char queue for any executable actions
queue.Run(&c.queue, c.timePassed)
c.queue.Run()
}

func (c *CharWrapper) FramePausedOnHitlag() bool {
Expand Down
8 changes: 8 additions & 0 deletions pkg/core/task/task.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package task

// TODO: the behavior of delay<=0 is inconsistent
// TODO: consider merging all tasks into a single handler
// Currently tasks are executed in the following order: (enemy1, enemy2, ...), (char1, char2, ...), (core tasks)
// In order to replace, the core task queue must support the ability to update the position of a task in the queue.
// Also will need to consider order. Currently everything that is queued via QueueCharTask/QueueEnemyTask will
// always happen before all entries in the core task queue. If any implementations depend on this order,
// this will cause additional problems.

import "container/heap"

type minHeap []task
Expand Down
5 changes: 3 additions & 2 deletions pkg/enemy/enemy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/genshinsim/gcsim/pkg/core/glog"
"github.com/genshinsim/gcsim/pkg/core/info"
"github.com/genshinsim/gcsim/pkg/core/targets"
"github.com/genshinsim/gcsim/pkg/core/task"
"github.com/genshinsim/gcsim/pkg/modifier"
"github.com/genshinsim/gcsim/pkg/queue"
"github.com/genshinsim/gcsim/pkg/reactable"
"github.com/genshinsim/gcsim/pkg/target"
)
Expand All @@ -34,11 +34,12 @@ type Enemy struct {
// hitlag stuff
timePassed int
frozenFrames int
queue []queue.Task
queue *task.Handler
}

func New(core *core.Core, p info.EnemyProfile) *Enemy {
e := &Enemy{}
e.queue = task.New(&e.timePassed)
e.Level = p.Level
//TODO: do we need to clone this map isntead?
e.resists = p.Resist
Expand Down
9 changes: 6 additions & 3 deletions pkg/enemy/hitlag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math"

"github.com/genshinsim/gcsim/pkg/core/glog"
"github.com/genshinsim/gcsim/pkg/queue"
)

func (e *Enemy) ApplyHitlag(factor, dur float64) {
Expand Down Expand Up @@ -42,7 +41,11 @@ func (e *Enemy) ApplyHitlag(factor, dur float64) {
}

func (e *Enemy) QueueEnemyTask(f func(), delay int) {
queue.Add(&e.queue, f, e.timePassed+delay)
if delay == 0 {
f()
return
}
e.queue.Add(f, delay)
}

func (e *Enemy) Tick() {
Expand All @@ -67,6 +70,6 @@ func (e *Enemy) Tick() {
}
e.timePassed += left

queue.Run(&e.queue, e.timePassed)
e.queue.Run()
e.Reactable.Tick()
}
37 changes: 0 additions & 37 deletions pkg/queue/tasks.go

This file was deleted.

0 comments on commit f31064d

Please sign in to comment.