mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-20 16:54:25 +00:00
Fix bug, add more game port
This commit is contained in:
parent
e52ba36759
commit
4d97ad1f34
2 changed files with 11 additions and 25 deletions
|
|
@ -58,8 +58,8 @@ type naEmulator struct {
|
|||
gameName string
|
||||
isSavingLoading bool
|
||||
|
||||
keys []bool
|
||||
done chan struct{}
|
||||
keysMap map[string][]int
|
||||
done chan struct{}
|
||||
|
||||
// lock to lock uninteruptable operation
|
||||
lock *sync.Mutex
|
||||
|
|
@ -74,6 +74,8 @@ type InputEvent struct {
|
|||
var NAEmulator *naEmulator
|
||||
var outputImg *image.RGBA
|
||||
|
||||
const maxPort = 8
|
||||
|
||||
// NAEmulator implements CloudEmulator interface based on NanoArch(golang RetroArch)
|
||||
func NewNAEmulator(etype string, roomID string, inputChannel <-chan InputEvent) (*naEmulator, chan *image.RGBA, chan []int16) {
|
||||
meta := config.EmulatorConfig[etype]
|
||||
|
|
@ -85,15 +87,13 @@ func NewNAEmulator(etype string, roomID string, inputChannel <-chan InputEvent)
|
|||
imageChannel: imageChannel,
|
||||
audioChannel: audioChannel,
|
||||
inputChannel: inputChannel,
|
||||
keys: make([]bool, joypadNumKeys*4),
|
||||
keysMap: map[string][]int{},
|
||||
roomID: roomID,
|
||||
done: make(chan struct{}, 1),
|
||||
lock: &sync.Mutex{},
|
||||
}, imageChannel, audioChannel
|
||||
}
|
||||
|
||||
var keysMap = map[string][]int{}
|
||||
|
||||
// Init initialize new RetroArch cloud emulator
|
||||
func Init(etype string, roomID string, inputChannel <-chan InputEvent) (*naEmulator, chan *image.RGBA, chan []int16) {
|
||||
emulator, imageChannel, audioChannel := NewNAEmulator(etype, roomID, inputChannel)
|
||||
|
|
@ -112,15 +112,15 @@ func (na *naEmulator) listenInput() {
|
|||
|
||||
if inpBitmap == -1 {
|
||||
// terminated
|
||||
delete(keysMap, inpEvent.ConnID)
|
||||
delete(na.keysMap, inpEvent.ConnID)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := keysMap[inpEvent.ConnID]; !ok {
|
||||
keysMap[inpEvent.ConnID] = make([]int, 4)
|
||||
if _, ok := na.keysMap[inpEvent.ConnID]; !ok {
|
||||
na.keysMap[inpEvent.ConnID] = make([]int, maxPort)
|
||||
}
|
||||
|
||||
keysMap[inpEvent.ConnID][inpEvent.PlayerIdx] = inpBitmap
|
||||
na.keysMap[inpEvent.ConnID][inpEvent.PlayerIdx] = inpBitmap
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,25 +64,11 @@ var video struct {
|
|||
}
|
||||
|
||||
const bufSize = 1024 * 4
|
||||
|
||||
const joypadNumKeys = int(C.RETRO_DEVICE_ID_JOYPAD_R3 + 1)
|
||||
|
||||
var joy [joypadNumKeys]bool
|
||||
var ewidth, eheight int
|
||||
|
||||
var bindRetroKeys = map[int]int{
|
||||
0: C.RETRO_DEVICE_ID_JOYPAD_A,
|
||||
1: C.RETRO_DEVICE_ID_JOYPAD_B,
|
||||
2: C.RETRO_DEVICE_ID_JOYPAD_X,
|
||||
3: C.RETRO_DEVICE_ID_JOYPAD_Y,
|
||||
4: C.RETRO_DEVICE_ID_JOYPAD_SELECT,
|
||||
5: C.RETRO_DEVICE_ID_JOYPAD_START,
|
||||
6: C.RETRO_DEVICE_ID_JOYPAD_UP,
|
||||
7: C.RETRO_DEVICE_ID_JOYPAD_DOWN,
|
||||
8: C.RETRO_DEVICE_ID_JOYPAD_LEFT,
|
||||
9: C.RETRO_DEVICE_ID_JOYPAD_RIGHT,
|
||||
}
|
||||
|
||||
var bindKeysMap = map[int]int{
|
||||
C.RETRO_DEVICE_ID_JOYPAD_A: 0,
|
||||
C.RETRO_DEVICE_ID_JOYPAD_B: 1,
|
||||
|
|
@ -142,8 +128,8 @@ func coreInputState(port C.unsigned, device C.unsigned, index C.unsigned, id C.u
|
|||
}
|
||||
|
||||
// check if any player is pressing that key
|
||||
for k := range keysMap {
|
||||
if ((keysMap[k][port] >> uint(key)) & 1) == 1 {
|
||||
for k := range NAEmulator.keysMap {
|
||||
if ((NAEmulator.keysMap[k][port] >> uint(key)) & 1) == 1 {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue