Skip to content

Commit

Permalink
Add events bus
Browse files Browse the repository at this point in the history
  • Loading branch information
WinPooh32 committed Dec 4, 2021
1 parent 356bc39 commit eb071e7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions addon/event_bus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package addon

import "github.com/WinPooh32/suslik"

type EventsBus struct {
suslik.Game

cur []interface{}
new []interface{}
}

func NewEventsBus() *EventsBus {
return &EventsBus{
cur: make([]interface{}, 0, 128),
new: make([]interface{}, 0, 128),
}
}

func (bus *EventsBus) Send(event interface{}) {
bus.new = append(bus.new, event)
}

func (bus *EventsBus) Events() []interface{} {
return bus.cur
}

func (bus *EventsBus) EventsImmediate() []interface{} {
return bus.new
}

func (bus *EventsBus) Reset() {
bus.cur = bus.cur[:0]
bus.new = bus.new[:0]
}

func (bus *EventsBus) Update(dt float32) {
bus.next()
}

func (bus *EventsBus) next() {
bus.cur, bus.new = bus.new, bus.cur[:0]
}

0 comments on commit eb071e7

Please sign in to comment.