Skip to content

Commit

Permalink
Merge pull request #165 from oakmound/hotfix/event-caller-map
Browse files Browse the repository at this point in the history
event: add SetCallerMap to Bus and Handler
  • Loading branch information
200sc authored Oct 9, 2021
2 parents 1ea802a + f777b0d commit ec0ad66
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
1 change: 0 additions & 1 deletion collision/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package collision
const (
// NilLabel is used internally for spaces that are otherwise not
// given labels.
// TODO V3: why is this exported
NilLabel Label = -1
)

Expand Down
2 changes: 0 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ func ReaderConfig(r io.Reader) ConfigOption {
}

func (c Config) overwriteFrom(c2 Config) Config {
// TODO: is this the right place for these configuration pieces?
// TODO: is there other configuration that should go here?
if c2.Assets.AudioPath != "" {
c.Assets.AudioPath = c2.Assets.AudioPath
}
Expand Down
2 changes: 0 additions & 2 deletions dlog/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func NewLogger() Logger {
// containing the logged data separated by spaces,
// prepended with file and line information.
// It only includes logs which pass the current filters.
// Todo: use io.Multiwriter to simplify the writing to
// both logfiles and stdout
func (l *logger) dLog(level Level, in ...interface{}) {
//(pc uintptr, file string, line int, ok bool)
_, f, line, ok := runtime.Caller(2)
Expand Down
5 changes: 5 additions & 0 deletions event/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func NewBus(callerMap *CallerMap) *Bus {
}
}

// SetCallerMap updates a bus to use a specific set of callers.
func (b *Bus) SetCallerMap(cm *CallerMap) {
b.callerMap = cm
}

// An Event is an event name and an associated caller id
type Event struct {
Name string
Expand Down
7 changes: 5 additions & 2 deletions event/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ var (
// Handler represents the necessary exported functions from an event.Bus
// for use in oak internally, and thus the functions that need to be replaced
// by alternative event handlers.
// TODO V3: consider breaking down the bus into smaller components
// for easier composition for external handler implementations
type Handler interface {
WaitForEvent(name string) <-chan interface{}
// <Handler>
Expand All @@ -42,6 +40,11 @@ type Handler interface {
UnbindBindable(UnbindOption)
}

// A CallerMapper has an internal caller map that can be set.
type CallerMapper interface {
SetCallerMap(*CallerMap)
}

// UpdateLoop is expected to internally call Update()
// or do something equivalent at the given frameRate,
// sending signals to the sceneCh after each Update().
Expand Down
2 changes: 0 additions & 2 deletions mouse/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const (
ButtonNone = mouse.ButtonNone
)

//TODO V3: should event names be strings?

// GetEventName returns a string event name given some mobile/mouse information
func GetEventName(d mouse.Direction, b mouse.Button) string {
switch d {
Expand Down
3 changes: 3 additions & 0 deletions sceneLoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func (w *Window) sceneLoop(first string, trackingInputs bool) {
} else {
w.CallerMap = event.NewCallerMap()
}
if cmr, ok := w.eventHandler.(event.CallerMapper); ok {
cmr.SetCallerMap(w.CallerMap)
}
w.DrawStack.Clear()
w.DrawStack.PreDraw()

Expand Down
2 changes: 1 addition & 1 deletion viewport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func sleep() {
// TODO V3: test how far we can bring this down and get consistent results
// TODO: test how far we can bring this down and get consistent results
time.Sleep(300 * time.Millisecond)
}

Expand Down

0 comments on commit ec0ad66

Please sign in to comment.