Skip to content

Commit

Permalink
woof
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Mar 21, 2024
1 parent be94324 commit a2a9ee7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
4 changes: 1 addition & 3 deletions pkg/worker/caged/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ type App interface {
SetAudioCb(func(Audio))
SetVideoCb(func(Video))
SetDataCb(func([]byte))
InputGamepad(port int, data []byte)
InputKeyboard(port int, data []byte)
InputMouse(port int, data []byte)
Input(port int, device byte, data []byte)
KbMouseSupport() bool
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/worker/caged/caged.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ type Manager struct {
log *logger.Logger
}

const (
RetroPad = libretro.RetroPad
Keyboard = libretro.Keyboard
Mouse = libretro.Mouse
)

type ModName string

const Libretro ModName = "libretro"
Expand Down
28 changes: 13 additions & 15 deletions pkg/worker/caged/libretro/caged.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,16 @@ func (c *Caged) EnableCloudStorage(uid string, storage cloud.Storage) {
}
}

func (c *Caged) AspectEnabled() bool { return c.base.nano.Aspect }
func (c *Caged) AspectRatio() float32 { return c.base.AspectRatio() }
func (c *Caged) PixFormat() uint32 { return c.Emulator.PixFormat() }
func (c *Caged) Rotation() uint { return c.Emulator.Rotation() }
func (c *Caged) AudioSampleRate() int { return c.Emulator.AudioSampleRate() }
func (c *Caged) ViewportSize() (int, int) { return c.base.ViewportSize() }
func (c *Caged) Scale() float64 { return c.Emulator.Scale() }
func (c *Caged) InputGamepad(port int, data []byte) { c.base.Input(port, RetroPad, data) }
func (c *Caged) InputKeyboard(port int, data []byte) { c.base.Input(port, Keyboard, data) }
func (c *Caged) InputMouse(port int, data []byte) { c.base.Input(port, Mouse, data) }
func (c *Caged) KbMouseSupport() bool { return c.base.KbMouseSupport() }
func (c *Caged) Start() { go c.Emulator.Start() }
func (c *Caged) SetSaveOnClose(v bool) { c.base.SaveOnClose = v }
func (c *Caged) SetSessionId(name string) { c.base.SetSessionId(name) }
func (c *Caged) Close() { c.Emulator.Close() }
func (c *Caged) AspectEnabled() bool { return c.base.nano.Aspect }
func (c *Caged) AspectRatio() float32 { return c.base.AspectRatio() }
func (c *Caged) PixFormat() uint32 { return c.Emulator.PixFormat() }
func (c *Caged) Rotation() uint { return c.Emulator.Rotation() }
func (c *Caged) AudioSampleRate() int { return c.Emulator.AudioSampleRate() }
func (c *Caged) ViewportSize() (int, int) { return c.base.ViewportSize() }
func (c *Caged) Scale() float64 { return c.Emulator.Scale() }
func (c *Caged) Input(p int, d byte, data []byte) { c.base.Input(p, d, data) }
func (c *Caged) KbMouseSupport() bool { return c.base.KbMouseSupport() }
func (c *Caged) Start() { go c.Emulator.Start() }
func (c *Caged) SetSaveOnClose(v bool) { c.base.SaveOnClose = v }
func (c *Caged) SetSessionId(name string) { c.base.SetSessionId(name) }
func (c *Caged) Close() { c.Emulator.Close() }
6 changes: 3 additions & 3 deletions pkg/worker/caged/libretro/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Emulator interface {
// Close will be called when the game is done
Close()
// Input passes input to the emulator
Input(player int, d Device, data []byte)
Input(player int, device byte, data []byte)
// Scale returns set video scale factor
Scale() float64
}
Expand Down Expand Up @@ -306,8 +306,8 @@ func (f *Frontend) Tick() { f.mu.Lock(); f.nano.Run(); f
func (f *Frontend) ViewportRecalculate() { f.mu.Lock(); f.vw, f.vh = f.ViewportCalc(); f.mu.Unlock() }
func (f *Frontend) ViewportSize() (int, int) { return f.vw, f.vh }

func (f *Frontend) Input(port int, d Device, data []byte) {
switch d {
func (f *Frontend) Input(port int, device byte, data []byte) {
switch Device(device) {
case RetroPad:
f.nano.InputRetropad(port, data)
case Keyboard:
Expand Down
6 changes: 3 additions & 3 deletions pkg/worker/coordinatorhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke
needsKbMouse := r.App().KbMouseSupport()

s := room.WithWebRTC(user.Session)
s.OnMessage = func(data []byte) { r.App().InputGamepad(user.Index, data) }
s.OnMessage = func(data []byte) { r.App().Input(user.Index, byte(caged.RetroPad), data) }
if needsKbMouse {
_ = s.AddChannel("keyboard", func(data []byte) { r.App().InputKeyboard(user.Index, data) })
_ = s.AddChannel("mouse", func(data []byte) { r.App().InputMouse(user.Index, data) })
_ = s.AddChannel("keyboard", func(data []byte) { r.App().Input(user.Index, byte(caged.Keyboard), data) })
_ = s.AddChannel("mouse", func(data []byte) { r.App().Input(user.Index, byte(caged.Mouse), data) })
}

c.RegisterRoom(r.Id())
Expand Down

0 comments on commit a2a9ee7

Please sign in to comment.