mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-24 02:55:45 +00:00
Update NES emulator to follow correct order (#74)
This commit is contained in:
parent
f491861874
commit
dadd5ebad0
1 changed files with 22 additions and 12 deletions
|
|
@ -40,6 +40,19 @@ const (
|
|||
AppAudio = 1
|
||||
)
|
||||
|
||||
var bindNESKeys = map[int]int{
|
||||
0: nes.ButtonA,
|
||||
1: nes.ButtonB,
|
||||
2: -1,
|
||||
3: -1,
|
||||
4: nes.ButtonSelect,
|
||||
5: nes.ButtonStart,
|
||||
6: nes.ButtonUp,
|
||||
7: nes.ButtonDown,
|
||||
8: nes.ButtonLeft,
|
||||
9: nes.ButtonRight,
|
||||
}
|
||||
|
||||
type GameView struct {
|
||||
console *nes.Console
|
||||
title string
|
||||
|
|
@ -77,22 +90,19 @@ func NewGameView(console *nes.Console, title, saveFile string, imageChannel chan
|
|||
return gameview
|
||||
}
|
||||
|
||||
// ListenToInputChannel listen from input channel streamm, which is exposed to WebRTC session
|
||||
//func (view *GameView) UpdateInput(keysInBinary int) {
|
||||
//for i := 0; i < NumKeys*2; i++ {
|
||||
//b := ((keysInBinary & 1) == 1)
|
||||
//view.keyPressed[i] = (view.keyPressed[i] && b) || b
|
||||
//keysInBinary = keysInBinary >> 1
|
||||
//}
|
||||
//}
|
||||
|
||||
// ListenToInputChannel listen from input channel streamm, which is exposed to WebRTC session
|
||||
func (view *GameView) ListenToInputChannel() {
|
||||
for keysInBinary := range view.inputChannel {
|
||||
for i := 0; i < NumKeys*2; i++ {
|
||||
b := ((keysInBinary & 1) == 1)
|
||||
view.keyPressed[i] = (view.keyPressed[i] && b) || b
|
||||
for i := 0; i < NumKeys; i++ {
|
||||
|
||||
key, ok := bindNESKeys[i]
|
||||
isPressed := ((keysInBinary & 1) == 1)
|
||||
keysInBinary = keysInBinary >> 1
|
||||
if !ok || key == -1 {
|
||||
continue
|
||||
}
|
||||
view.keyPressed[key] = (view.keyPressed[key] && isPressed) || isPressed
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue