NagyD / SDLPoP

An open-source port of Prince of Persia, based on the disassembly of the DOS version.
GNU General Public License v3.0
1.1k stars 141 forks source link

Joypad (joystick) upper-left doesn't do anything #205

Closed javierdlr closed 4 years ago

javierdlr commented 4 years ago

I have a normal/cheap USB gamepad (like ps2 ones). When ussing in the game pad the "joystick-analog" it works well, except upper-left jum it doesn't work. upper-right makes player jump to the right without problem, but upper-left doesn't do anything.

BTW in seg009.c line 3247: // Disregard SDL_JOYAXISMOTION events within joystick 'dead zone' int joy_x = joy_axis[SDL_CONTROLLER_AXIS_LEFTX]; int joy_y = joy_axis[SDL_CONTROLLER_AXIS_LEFTX];

is it correct? shouldn't joy_y "use" ....._AXIS_LEFTY];?

NagyD commented 4 years ago

@Falcury, can you help me with this?

is it correct? shouldn't joy_y "use" ....._AXIS_LEFTY];?

I think you're right. I fixed it now: fbb73f6c8e303bef16e7acf481908eb2478e7c6d Although that value is only used for checking if the input mode should be set to joystick. So that probably was not the cause of your problem.

Falcury commented 4 years ago

@Falcury, can you help me with this?

is it correct? shouldn't joy_y "use" ....._AXIS_LEFTY];?

I think you're right. I fixed it now: fbb73f6 Although that value is only used for checking if the input mode should be set to joystick. So that probably was not the cause of your problem.

Yes I think you're right. Unfortunately I also cannot reproduce the issue. I only have an Xbox 360 controller to test this with, maybe it is something specific to the gamepad being used?

@javierdlr, can you check if the code change does anything to resolve the issue for you, and if not, maybe you could give some details on the exact type of gamepad you are using? Also, I assume you are playing with the 'horizontal joystick movement only' option disabled?

javierdlr commented 4 years ago

The changre/fix didn't resolve the upper-left-with-stick-not-working. My gamepad is this one: Ewent EW3170 (this is the replacement/updated https://www.ewent-online.com/pl3330-suitable-for-use-with-your-pclaptop.html) another guy (with a different gamepad) has the same issue. Dunnot why happens only when trying to jump-left (stick move to diagonal upper left) jump-right works fine.

Yes is with "horiz, joystick movment" disabled.

Is there a place where to "see" movement of joystick in sources?

kees commented 4 years ago

Is there a place where to "see" movement of joystick in sources?

Would something like this work for you?

diff --git a/src/seg009.c b/src/seg009.c
index 3714587..2c1af3e 100644
--- a/src/seg009.c
+++ b/src/seg009.c
@@ -3236,7 +3236,9 @@ void process_events() {
                                if (!using_sdl_joystick_interface) {
                                        break;
                                }
+                               fprintf(stderr, "event.type: %d\n", event.type);
                                if (event.type == SDL_JOYAXISMOTION) {
+                                       fprintf(stderr, "event.jaxis.axis: %d\n", event.jaxis.axis);
                                        if (event.jaxis.axis == SDL_JOYSTICK_X_AXIS) {
                                                joy_axis[SDL_CONTROLLER_AXIS_LEFTX] = event.jaxis.value;
                                        }
@@ -3247,6 +3249,7 @@ void process_events() {
                                        int joy_x = joy_axis[SDL_CONTROLLER_AXIS_LEFTX];
                                        int joy_y = joy_axis[SDL_CONTROLLER_AXIS_LEFTY];
                                        if ((dword)(joy_x*joy_x) + (dword)(joy_y*joy_y) < (dword)(joystick_threshold*joystick_threshold)) {
+                                               fprintf(stderr, "deadzone\n");
                                                break;
                                        }
                                }
javierdlr commented 4 years ago

Hola Kees

El 20-06-2020, escribiste:

Is there a place where to "see" movement of joystick in sources?

Would something like this work for you?


diff --git a/src/seg009.c b/src/seg009.c
index 3714587..2c1af3e 100644
--- a/src/seg009.c
+++ b/src/seg009.c
@@ -3236,7 +3236,9 @@ void process_events() {
                                if (!using_sdl_joystick_interface) {
                                        break;
                                }
+                               fprintf(stderr, "event.type: %d\n",
                                event.type); if (event.type ==
                                SDL_JOYAXISMOTION) { +
[...]

Didn't get any "debug", but a few lines up... ... case SDL_CONTROLLERAXISMOTION: printf("SDL_CONTROLLERAXISMOTION %d\n",event.caxis.axis); if (event.caxis.axis < 6) { joy_axis[event.caxis.axis] = event.caxis.value;

ifdef USE_AUTO_INPUT_MODE

                if (!is_joyst_mode && (event.caxis.value >= joystick_threshold || event.caxis.value <= -joystick_threshold)) {
                    is_joyst_mode = 1;
                    is_keyboard_mode = 0;
                }

endif

            }
            break;

...

When using the stick I get "debug", what does value "6" mean?, I only get 0 or 1: ... SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0 SDL_CONTROLLERAXISMOTION 1 SDL_CONTROLLERAXISMOTION 0

Just it's strange 'cos using up-right player jumps, but not when using up-left.

Saludos -- AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

NagyD commented 4 years ago

Didn't get any "debug", but a few lines up... printf("SDL_CONTROLLERAXISMOTION %d\n",event.caxis.axis);

I think you should print out the value of event.caxis.value as well.

When using the stick I get "debug", what does value "6" mean?,

Do you mean in if (event.caxis.axis < 6)? It's the number of elements in the joy_axis array, which in turn comes from the number of axes in SDL_GameControllerAxis.

I only get 0 or 1:

0 and 1 are the X and Y axes of the left analog stick; 2 and 3 are the axes of the right analog stick; and 4 and 5 are the two triggers.

Is there a place where to "see" movement of joystick in sources?

The current position of the joystick is interpreted in the get_joystick_state() function: https://github.com/NagyD/SDLPoP/blob/master/src/seg000.c#L1219 You could uncomment the printf which outputs the angle, since most ifs check the value of this variable.

Also, there are some tweaks in there which depend on what the prince is currently doing. One of them could be related to this bug, but I don't know for sure.

javierdlr commented 4 years ago

Hola Dávid

El 27-06-2020, escribiste:

Didn't get any "debug", but a few lines up... printf("SDL_CONTROLLERAXISMOTION %d\n",event.caxis.axis);

I think you should print out the value of event.caxis.value as well.

When using the stick I get "debug", what does value "6" mean?,

Do you mean in if (event.caxis.axis < 6)? It's the number of elements in the joy_axis array, which in turn comes from the number of axes in SDL_GameControllerAxis. [...]

ok, I get this values when moving stick to upper-left: [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0

I should get -135 if not mistaken, but I don't get any angle ¿:-/ maybe is a AmigaOS4/system joystick driver issue? Or just a missing if/else in calculating angle?

And those "others" values are when moving rest of directions (not sure if I copy&pasted all of them): ... [get_joystick_state]raw_x=0 raw_y=32767 axix_state[2]=0 [get_joystick_state]Joystick angle is 90.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=32767 axix_state[2]=0 [get_joystick_state]Joystick angle is 90.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=32767 axix_state[2]=0 [get_joystick_state]Joystick angle is 90.000000 degrees ... SDL_CONTROLLERAXISMOTION 1 (val=-32768) [get_joystick_state]raw_x=0 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -90.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -90.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=0 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -90.000000 degrees ... SDL_CONTROLLERAXISMOTION 0 (val=32767) [get_joystick_state]raw_x=32767 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 0.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=32767 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 0.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=32767 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 0.000000 degrees ... SDL_CONTROLLERAXISMOTION 1 (val=-32768) [get_joystick_state]raw_x=32767 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -45.000874 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=32767 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -45.000874 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=32767 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -45.000874 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=32767 raw_y=-32768 axix_state[2]=0 [get_joystick_state]Joystick angle is -45.000874 degrees ... SDL_CONTROLLERAXISMOTION 0 (val=-32768) [get_joystick_state]raw_x=-32768 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 180.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 180.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 180.000000 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=0 axix_state[2]=0 [get_joystick_state]Joystick angle is 180.000000 degrees ... [get_joystick_state]raw_x=-32768 raw_y=32767 axix_state[2]=-16777024 [get_joystick_state]Joystick angle is 135.000874 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0 [get_joystick_state]raw_x=-32768 raw_y=32767 axix_state[2]=-16777024 [get_joystick_state]Joystick angle is 135.000874 degrees [get_joystick_state]raw_x=0 raw_y=0 axix_state[2]=0

Saludos -- AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

NagyD commented 4 years ago

[get_joystick_state]raw_x=-32768 raw_y=-32768 axix_state[2]=0 I should get -135 if not mistaken, but I don't get any angle ¿:-/

Thank you, this helps a lot!

The problem is here: https://github.com/NagyD/SDLPoP/blob/master/src/seg000.c#L1224 With the coordinates you wrote, dist_squared = raw_x*raw_x + raw_y*raw_y is calculated as -32768 -32768 + -32768 -32768 = 2147483648. But dist_squared is a 32-bit signed integer variable, and this number cannot be stored in that data type, so it overflows to -2147483648. In the if in the next line, the condition becomes true, and so the code thinks that the joystick is within the dead zone.

One possible solution is to cast both sides of the comparison to an unsigned type, like this:

    if ((dword)dist_squared < (dword)(joystick_threshold*joystick_threshold)) {

(Something similar is done here: https://github.com/NagyD/SDLPoP/blob/master/src/seg009.c#L3249 )

Please change the line with the if to this, and tell me if this fixes your problem. If it does then I will add this change to the code.

javierdlr commented 4 years ago

confirmed casting to DWORD solves the issue!!!

GREAT!!! THXaLOT

NagyD commented 4 years ago

Thank you for verifying the fix! I have committed the fix into the repo. Closing this issue.

javierdlr commented 4 years ago

Hola Dávid

El 8-07-2020, escribiste:

Closed #205.

BTW I'm planning to upload the SDLPoP AmigaOS4 version to www.os4depot.net.

Can I uopload with sources? Or better send't em to you to create a new branch "SDLPoP_amigaos4" and then upload there.

I'm a noob about github clone/branch/pull/... so if I should create such branch, could you enlight me where to find an easy tutorial?

TiA

Saludos -- AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

NagyD commented 4 years ago

BTW I'm planning to upload the SDLPoP AmigaOS4 version to www.os4depot.net. Can I uopload with sources? Or better send't em to you to create a new branch "SDLPoP_amigaos4" and then upload there. I'm a noob about github clone/branch/pull/... so if I should create such branch, could you enlight me where to find an easy tutorial?

You can find some Git tutorials here:

Exactly what would you like to upload?

  1. Did you have to change the source to make SDLPoP compile on AmigaOS4, and do you want to upload those changes?
    • In this case I'd like to know: Did you clone my repo with Git, or did you download the source in some other way (in a ZIP file, etc.)?
  2. And/or, do you want to upload the SDLPoP binaries compiled for AmigaOS4?
javierdlr commented 4 years ago

Hola Dávid

El 19-07-2020, escribiste:

BTW I'm planning to upload the SDLPoP AmigaOS4 version to www.os4depot.net. Can I uopload with sources? Or better send't em to you to create a new branch "SDLPoP_amigaos4" and then upload there. I'm a noob about github clone/branch/pull/... so if I should create such branch, could you enlight me where to find an easy tutorial?

You can find some Git tutorials here:

ok thx will look at them ASAP

Exactly what would you like to upload? to github the full sources ("big-endian") with changes/updates to build/use under AmigaOS4 (define amigaos4): -Added Makefile.amigaos4 to build PoP executable. -Added in config.h (#ifdef amigaos4) to show correct colors in game (somekind of RGB shifting issue). -Updated seg009.c and lighting.c (SDL_CreateRGBSurface) to use new config.h amigaos4 defines. -Updated option.c to use "#define strtoimax(a,b,c) strtoll(a,b,c)". -Added "pause game" on iconification. -Added AmigaOS version string and cookie stack [main.c]. -Added icon(s) (THX to samo79). -Updated to SDLPoP 1.20 (big-endian branch was 1.19). -Added gamecontrollerdb.txt file mappings (gamepad support database) [seg009.c]. -Fixed saving/loading SDLPoP.cfg from PoP drawer [seg009.c].

  1. Did you have to change the source to make SDLPoP compile on AmigaOS4, and do you want to upload those changes? * In this case I'd like to know: Did you clone my repo with Git, or did you download the source in I just downloaded .ZIP "big-endian" branch, updated code (and created makefile.amigaos4) with above changes.

some other way (in a ZIP file, etc.)? 2. And/or, do you want to upload the SDLPoP binaries compiled for AmigaOS4? If you want, I can send you archive I already have created on my hdd and I will upload to AmigaOS4 files web (os4depot.net is like aminet.net)

Saludos -- AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

NagyD commented 4 years ago

I just downloaded .ZIP "big-endian" branch, updated code (and created makefile.amigaos4) with above changes.

You should do the following:

BTW I'm planning to upload the SDLPoP AmigaOS4 version to www.os4depot.net. Can I uopload with sources?

Yes.