Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evmapy.py generates an incomplete mapping file #12927

Open
lulol opened this issue Nov 11, 2024 · 4 comments · May be fixed by #12928
Open

evmapy.py generates an incomplete mapping file #12927

lulol opened this issue Nov 11, 2024 · 4 comments · May be fixed by #12928

Comments

@lulol
Copy link

lulol commented Nov 11, 2024

Batocera build version

40 2024/08/03 05:52

Your architecture

Your Graphic Processor Unit(s) (GPU)

Issue description

Using the PAD TO KEYBOARD CONFIGURATION gui to map pad events to keyboard key presses creates a <rom>.keys with the configured mappings.
Then when launching the rom evmapy.py generates an incomplete event.json file for evmapy.

Detailed reproduction steps

  • Use the PAD TO KEYBOARD CONFIGURATION gui to map pad events (including the ABS Y axis) to keyboard key presses.
  • The <rom>.keys file looks fine.
  • The generated event.keys file is incomplete with ABS Y axis missing.

Details of any attempts to fix this yourself

Manually editing the corresponding event.json file and adding the missing ABS axis configuration and restarting evmpy with the corrected mapping while the game is still running confirms that the ABS vertical axis mapping works just fine.

Running evmapy in a tty console [Ctrl-Alt-F3] using the fixed mapping file also shows the translated key pressed fine.

The known_axes_codes and copy-paste bugs in v40 are also present in the current master.

if "ABSBASEX:min" in known_buttons_names:
if absbasey_positive:
mapping["down"] = "ABSBASEY:max"
mapping["up"] = "ABSBASEY:min"
else:
mapping["down"] = "ABSBASEY:min"
mapping["up"] = "ABSBASEY:max"

Not sure about absbasey_positive but all the 6 game pads and controllers I tested show (up, left).min = 0 and (down, right).max = 255 with the current logic the up/down axis is inverted.

Details of any modifications you have made to Batocera.

Bugfix PR #12928

Logs and data

No response

@lulol lulol linked a pull request Nov 11, 2024 that will close this issue
@nadenislamarre
Copy link
Collaborator

i don't reproduce the issue.
it is working correctly on my side.
it generates the file like this:

    {
        "trigger": "joystick1up",
        "type": "key",
        "target": "KEY_Q"
    },
    {
        "trigger": "joystick1down",
        "type": "key",
        "target": "KEY_A"
    },
    {
        "trigger": "joystick1left",
        "type": "key",
        "target": "KEY_O"
    },
    {
        "trigger": "joystick1right",
        "type": "key",
        "target": "KEY_P"
    },

@nadenislamarre
Copy link
Collaborator

can you explain your issue, and give a specific case, and show the file generated so that i undertand the issue.
i hardly understand what's wrong on your side because you're describing how to solve, but not what happen, and i can't reproduce on my side. Don't hesitate to come on discord and ask susan34, it will be maybe easier.

@lulol
Copy link
Author

lulol commented Nov 11, 2024

Sure, my issue is related to the processing of the ABSBASEY axis only. (But of course also can happen for ABSBASEX).

When the 'up' input.name is processed first this issue won't happen.

When 'down' is processes first then the known_axes_codes[input.code] flag is populated before the Y axis mapping is generated and according to the current code logic when later 'up' arrives any further processing will be skipped and the mapping for the Y axis ignored.

This condition can happen because json.load() objects may not keep the original order.

rom.keys file:

{
    "actions_player1": [
        {
            "trigger": "up",
            "type": "key",
            "target": "KEY_W"
        },
        {
            "trigger": "down",
            "type": "key",
            "target": "KEY_S"
        },
        {
            "trigger": "left",
            "type": "key",
            "target": "KEY_H"
        },
        {
            "trigger": "right",
            "type": "key",
            "target": "KEY_J"
        },
        {
            "trigger": "start",
            "type": "key",
            "target": "KEY_Y"
        },
        {
            "trigger": "a",
            "type": "key",
            "target": "KEY_V"
        },
        {
            "trigger": "b",
            "type": "key",
            "target": "KEY_1"
        },
        {
            "trigger": "x",
            "type": "key",
            "target": "KEY_3"
        },
        {
            "trigger": "y",
            "type": "key",
            "target": "KEY_2"
        },
        {
            "trigger": "pageup",
            "type": "key",
            "target": "KEY_L"
        },
        {
            "trigger": "pagedown",
            "type": "key",
            "target": "KEY_R"
        },
        {
            "trigger": "l2",
            "type": "key",
            "target": "KEY_M"
        },
        {
            "trigger": "r2",
            "type": "key",
            "target": "KEY_G"
        }
    ]
}

generated event.json file:

{
    "axes": [
        {
            "name": "ABSBASEX",
            "code": 0,
            "min": 63.75,
            "max": 191.25
        }
    ],
    "buttons": [
        {
            "name": "a",
            "code": 289
        },
        {
            "name": "b",
            "code": 290
        },
        {
            "name": "hotkey",
            "code": 296
        },
        {
            "name": "l2",
            "code": 294
        },
        {
            "name": "pagedown",
            "code": 293
        },
        {
            "name": "pageup",
            "code": 292
        },
        {
            "name": "r2",
            "code": 295
        },
        {
            "name": "start",
            "code": 297
        },
        {
            "name": "x",
            "code": 288
        },
        {
            "name": "y",
            "code": 291
        }
    ],
    "grab": false,
    "actions": [
        {
            "trigger": "ABSBASEX:min",
            "type": "key",
            "target": "KEY_H"
        },
        {
            "trigger": "ABSBASEX:max",
            "type": "key",
            "target": "KEY_J"
        },
        {
            "trigger": "start",
            "type": "key",
            "target": "KEY_Y"
        },
        {
            "trigger": "a",
            "type": "key",
            "target": "KEY_V"
        },
        {
            "trigger": "b",
            "type": "key",
            "target": "KEY_1"
        },
        {
            "trigger": "x",
            "type": "key",
            "target": "KEY_3"
        },
        {
            "trigger": "y",
            "type": "key",
            "target": "KEY_2"
        },
        {
            "trigger": "pageup",
            "type": "key",
            "target": "KEY_L"
        },
        {
            "trigger": "pagedown",
            "type": "key",
            "target": "KEY_R"
        },
        {
            "trigger": "l2",
            "type": "key",
            "target": "KEY_M"
        },
        {
            "trigger": "r2",
            "type": "key",
            "target": "KEY_G"
        }
    ]
}

This event.json is missing from the axes list:

--- event3.json 2024-11-11 23:43:12.903696886 +0100
+++ event3.json.fix     2024-11-11 23:40:05.516736069 +0100
@@ -5,6 +5,12 @@
             "code": 0,
             "min": 63.75,
             "max": 191.25
+        },
+        {
+            "name": "ABSBASEY",
+            "code": 1,
+            "min": 63.75,
+            "max": 191.25
         }
     ],
     "buttons": [
@@ -52,6 +58,16 @@
     "grab": false,
     "actions": [
         {
+            "trigger": "ABSBASEY:min",
+            "type": "key",
+            "target": "KEY_W"
+        },
+        {
+            "trigger": "ABSBASEY:max",
+            "type": "key",
+            "target": "KEY_S"
+        },
+        {
             "trigger": "ABSBASEX:min",
             "type": "key",
             "target": "KEY_H"

And about the later use of the absbasex_positive and absbasey_positive variables, the mapping assignations for the Y axis are being made checking existence of the X axis found in known_buttons_names, not the corresponding Y axis, probably a copy-paste typo, but I think that this is won't be an issue unless someone has a joystick with only a Y axis and no X axis.

evtest.log
evtest.log

@lulol
Copy link
Author

lulol commented Nov 21, 2024

@Tovarichtch Sorry, it seems there may be some confusion with the issue label. 😉

Just want to clarify that this issue and associated PR is not an enhancement but a bug report.

The current code logic is faulty and under certain conditions explained above it produces incorrect results.

All this may be overkill, but here is anyway. 😞

PoC

# Notes:
# 1. Needs file myplayersControllers.blob to load the playersControllers object.
# 2. Some events device need to be present, otherwise an exception will be raised.
# 3. Ignore "min" and "max" values mismatches if present in diff since are not relevant.

# generates an event0.json
python -m test.py

# Save buggy event0.json
cp /var/run/evmapy/event0.json /tmp/event0.json

# Apply patch
patch -p0 < PR#12928

# generate fixed event0.json
python -m test.py

# Revert patch
patch -R -p0 < PR#12928

# compare output
diff -Naur /var/run/evmapy/event0.json /tmp/event0.json

test.py

import pickle
with open("myplayersControllers.blob", "rb") as fd:
    playersControllers = pickle.load(fd)

from evmapy import evmapy
evmapy.start("zx81", "emulator", "effectiveCore", ".", playersControllers, "")

gunzip to get myplayersControllers.blob
myplayersControllers.blob.gz


Since I thought it might take a while for a new fixed version to be released, I only opened this issue to help other users find a workaround in the meantime. And to clarify an inconsistency, as the PR fix seemed quite basic to need any explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants