turican0 / remc2

Recode Binary code of game Magic Carpet2 to C/C++ language(remake MC2 for any platform)
GNU General Public License v3.0
111 stars 11 forks source link

joystick support #189

Open rodan opened 1 year ago

rodan commented 1 year ago

hello!

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

I'm confronted with the following facts:

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 commented 1 year ago

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 commented 1 year ago

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