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

joystick support #189

Open
rodan opened this issue Apr 10, 2023 · 2 comments
Open

joystick support #189

rodan opened this issue Apr 10, 2023 · 2 comments

Comments

@rodan
Copy link

rodan commented Apr 10, 2023

hello!

I'm working on a patch that would add joystick support for the game.

I'm confronted with the following facts:

  • the 'big stone' main menu expects a pointer position in the 0,0 .. 640,480 interval ignoring gameResW,H set in the ini file
  • the level selection map panel expects 0,0 .. 640,480 ignoring the ini file
  • during flight and any of the in-game panels the pointer position is expected in the 0,0 .. gameRes{Width, Height} interval, with a hardcoded 320,200 resting coordinate! this means that if I have a 1024x768 gameRes I can't reach any horizontal pixel over ~800 due to the hardcoded 320 'center' value which should have been 1024/2. which in turn means that I can't reach the last spell if the first one is currently selected.

none of these inconsistencies are noticeable when using a mouse - since the mouse can be moved to infinity in any direction, but a joystick has a limited movement arc. and ideally the entire arc has to map perfectly to the virtual canvas it controls.

so how should I treat the window size differences? and the hardcoded window center in flight mode?
what part of the reversed code can I force into submission?

dazed and confused,
peter

you can add a mouse coord debug output if you patch engine/Basic.cpp thusly:

diff --git a/remc2/engine/Basic.cpp b/remc2/engine/Basic.cpp
index 14e4652b7..b79378fe7 100644
--- a/remc2/engine/Basic.cpp
+++ b/remc2/engine/Basic.cpp
@@ -93,6 +93,8 @@ uint8_t* x_DWORD_18070C; // weak
 uint8_t* x_DWORD_180714; // weak
 uint8_t* x_DWORD_180718; // weak
 
+extern axis_2d x_WORD_E3760_mouse;
+
 //basic graphics
 
 char x_BYTE_D41CE = 0; // weak
@@ -1769,6 +1771,11 @@ void VGA_DrawPlayerCoordData(int x, int y)
                        " Yaw: " + std::to_string(rotData.yaw);
 
                VGA_Draw_stringXYtoBuffer(playerRotationStr.c_str(), x, y + 8, pdwScreenBuffer_351628, 'S');
+#if 1
+               axis_2d mouseData = x_WORD_E3760_mouse;
+               std::string mouseCoordStr = "x: " + std::to_string(mouseData.x) + " y: " + std::to_string(mouseData.y);
+               VGA_Draw_stringXYtoBuffer(mouseCoordStr.c_str(), x, y + 16, pdwScreenBuffer_351628, 'S');
+#endif
        }
 }
@thobbsinteractive
Copy link
Collaborator

Hi Peter,

Thanks for the hard work. I have not done much myself in the last month, but I am continuing the work on a windows installer.
Turican is currently focusing on MC1 and making a lot of progress.

If you make a pull request on my branch https://github.com/thobbsinteractive/magic-carpet-2-hd I will test it out this week. Joystick support is also one of my open enhancements.

When you launch the game it looks at the the config.ini file and uses windowResWidth and windowResHeight to create the SDL Window. After that the render buffer rendered to a texture and scaled. So Videos run at 320x200 and are scaled up. The menus are displayed at 640x480 and also scaled. The in game resolution (by default) uses gameResWidth and gameResHeight from the config.ini file. windowResWidth and windowResHeight should be global maybe they can be used to center the joystick in game?

@rodan
Copy link
Author

rodan commented Apr 10, 2023

Good evening,

sending a non (320,2x0) rest coord to the flight window will send me in an infinite spin since it looks like the roll and yaw calculation is also somehow hardcodedly centered on 320.

I have a solution for this, by using two separate linear interpolation equations for each axis. so whatever the rest position is given to any size window I can still reach the canvas edges. it works great.

my only problem now is the stone main menu and the level selection windows - since they are not gameResWH as my 'joystick canvas' is set up. but I'm sure you'll have an elegant solution for that :)

I will send you a pull request tomorrow so you can check it out.

many thanks,
peter

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

No branches or pull requests

2 participants