cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
868 stars 115 forks source link

Player 1 controls can affect other players in character selection #855

Closed Kurtsley closed 2 weeks ago

Kurtsley commented 4 weeks ago

The default player 1 controls (up, down, left, right), also control the menus of the second player if selected. The second player controls only affect the second player menu.

Video showing the issue: https://www.youtube.com/watch?v=HJVdF7TUMuY

I believe the character selection menus should be tied to the individual controls of the players. On the other hand, this could be used to mess with people when playing local coop...

Kurtsley commented 3 weeks ago

I think I've found the cause of this issue and would like some feedback.

It looks like this is the block of code responsible for the player selection menu input: https://github.com/cxong/cdogs-sdl/blob/fbac5741aecb520e3b7c46dbab3e098f4f1e0e70/src/prep.c#L410-L440

When player one pressed Up for example, the command was sent twice which ended up affecting the second player. I believe this is caused by the GetMenuCmd function at line 433. The input for this menu is processed at line 437 if there has not been an exit command.

Why does this block get called as well? https://github.com/cxong/cdogs-sdl/blob/fbac5741aecb520e3b7c46dbab3e098f4f1e0e70/src/prep.c#L430-L434

It looks like useMenuCmd checks if there are any local, alive players. If that is the case, process their key presses. GetMenuCmd and MenuProcessCmd both process the player 1 key presses. More specifically, it looks like GetMenuCmd controls both player menus in the player selection screen.

TLDR removing the above block which calls GetMenuCmd along with the useMenuCmd check fixes this issue.