From 8e41b18f42e3e10b8d1ca26bd1eef375c3307290 Mon Sep 17 00:00:00 2001 From: Patrick Stephen Date: Sat, 18 Sep 2021 19:21:23 -0500 Subject: [PATCH 1/3] event: add SetCallerMap to Bus and Handler --- event/bus.go | 5 +++++ event/handler.go | 4 ++-- sceneLoop.go | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/event/bus.go b/event/bus.go index 2d27284c..fd40d082 100644 --- a/event/bus.go +++ b/event/bus.go @@ -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 diff --git a/event/handler.go b/event/handler.go index 70c31be3..8c650edb 100644 --- a/event/handler.go +++ b/event/handler.go @@ -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{} // @@ -40,6 +38,8 @@ type Handler interface { UnbindAll(Event) UnbindAllAndRebind(Event, []Bindable, CID, []string) UnbindBindable(UnbindOption) + + SetCallerMap(*CallerMap) } // UpdateLoop is expected to internally call Update() diff --git a/sceneLoop.go b/sceneLoop.go index 42b3d9e1..15f62a34 100644 --- a/sceneLoop.go +++ b/sceneLoop.go @@ -130,6 +130,7 @@ func (w *Window) sceneLoop(first string, trackingInputs bool) { } else { w.CallerMap = event.NewCallerMap() } + w.eventHandler.SetCallerMap(w.CallerMap) w.DrawStack.Clear() w.DrawStack.PreDraw() From 7139cc7e33da1f819bd26c1c04dc0c0796f47a01 Mon Sep 17 00:00:00 2001 From: Patrick Stephen Date: Sun, 19 Sep 2021 21:03:51 -0500 Subject: [PATCH 2/3] oak: remove resolved TODOs --- collision/label.go | 1 - config.go | 2 -- dlog/default.go | 2 -- mouse/mouse.go | 2 -- viewport_test.go | 2 +- 5 files changed, 1 insertion(+), 8 deletions(-) diff --git a/collision/label.go b/collision/label.go index 44061986..633d41b3 100644 --- a/collision/label.go +++ b/collision/label.go @@ -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 ) diff --git a/config.go b/config.go index a6fb14fa..7233308f 100644 --- a/config.go +++ b/config.go @@ -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 } diff --git a/dlog/default.go b/dlog/default.go index b7d58c3d..84511614 100644 --- a/dlog/default.go +++ b/dlog/default.go @@ -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) diff --git a/mouse/mouse.go b/mouse/mouse.go index da12e54f..7fcd47c1 100644 --- a/mouse/mouse.go +++ b/mouse/mouse.go @@ -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 { diff --git a/viewport_test.go b/viewport_test.go index 3bf26b4c..96a3d113 100644 --- a/viewport_test.go +++ b/viewport_test.go @@ -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) } From f777b0dd05e6af4e72be202456f6c017ac0475db Mon Sep 17 00:00:00 2001 From: Patrick Stephen Date: Sat, 9 Oct 2021 11:03:24 -0500 Subject: [PATCH 3/3] event: split SetCallerMap into its own interface for backwards compatibility --- event/handler.go | 3 +++ sceneLoop.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/event/handler.go b/event/handler.go index 8c650edb..89624e7e 100644 --- a/event/handler.go +++ b/event/handler.go @@ -38,7 +38,10 @@ type Handler interface { UnbindAll(Event) UnbindAllAndRebind(Event, []Bindable, CID, []string) UnbindBindable(UnbindOption) +} +// A CallerMapper has an internal caller map that can be set. +type CallerMapper interface { SetCallerMap(*CallerMap) } diff --git a/sceneLoop.go b/sceneLoop.go index 15f62a34..e4a31e8c 100644 --- a/sceneLoop.go +++ b/sceneLoop.go @@ -130,7 +130,9 @@ func (w *Window) sceneLoop(first string, trackingInputs bool) { } else { w.CallerMap = event.NewCallerMap() } - w.eventHandler.SetCallerMap(w.CallerMap) + if cmr, ok := w.eventHandler.(event.CallerMapper); ok { + cmr.SetCallerMap(w.CallerMap) + } w.DrawStack.Clear() w.DrawStack.PreDraw()