Skip to content

Commit

Permalink
Removed joystick code
Browse files Browse the repository at this point in the history
This was never fully implemented and has been essentially abandoned. If we want to
add this again, we should look to adding full game controller support (Steam controller,
for example), though I don't know how suited this game is for controller support. As for
as I can tell, the only working part was ever map scrolling.

Includes a sqrt -> std::sqrt conversion I forgot in this file awhile back.
  • Loading branch information
Vultraz committed Apr 14, 2018
1 parent 52f8e82 commit d384b96
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 750 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -91,6 +91,7 @@
* Fixed assertion when undoing actions in a synced context.
* Fixed assertion when saving game events mid-event.
* Fix MP password save error (#2745)
* Removed incomplete joystick support.

## Version 1.13.12
### Security fixes
Expand Down
186 changes: 0 additions & 186 deletions data/advanced_preferences.cfg
Expand Up @@ -193,190 +193,4 @@
[/advanced_preference]

#ifdef __UNUSED__
[advanced_preference]
field=joystick_support_enabled
name= _ "Joystick support"
type=boolean
default=no
[/advanced_preference]

[advanced_preference]
field=joystick_num_scroll_xaxis
name= _ "Joystick: number of the scroll X-axis joystick"
type=int
default=0
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_scroll_xaxis_num
name= _ "Joystick: number of the scroll X-axis"
type=int
default=0
min=0
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_num_scroll_yaxis
name= _ "Joystick: number of the scroll Y-axis joystick"
type=int
default=0
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_scroll_yaxis_num
name= _ "Joystick: number of the scroll Y-axis"
type=int
default=1
min=0
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_scroll_deadzone
name= _ "Joystick: deadzone of the scrolling stick"
type=int
default=1500
min=0
max=16000
step=500
[/advanced_preference]

[advanced_preference]
field=joystick_num_cursor_xaxis
name= _ "Joystick: number of the cursor X-axis joystick"
type=int
default=0
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_cursor_xaxis_num
name= _ "Joystick: number of the cursor X-axis"
type=int
default=3
min=0
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_num_cursor_yaxis
name= _ "Joystick: number of the cursor Y-axis joystick"
type=int
default=0
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_cursor_yaxis_num
name= _ "Joystick: number of the cursor Y-axis"
type=int
default=4
min=-1
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_cursor_deadzone
name= _ "Joystick: deadzone of the cursor stick"
type=int
default=1500
min=0
max=16000
step=500
[/advanced_preference]

[advanced_preference]
field=joystick_num_mouse_xaxis
name= _ "Joystick: number of the mouse X-axis joystick"
type=int
default=-1
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_mouse_xaxis_num
name= _ "Joystick: number of the mouse X-axis"
type=int
default=0
min=0
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_num_mouse_yaxis
name= _ "Joystick: number of the mouse Y-axis joystick"
type=int
default=-1
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_mouse_yaxis_num
name= _ "Joystick: number of the mouse Y-axis"
type=int
default=1
min=0
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_mouse_deadzone
name= _ "Joystick: deadzone of the mouse stick"
type=int
default=1500
min=0
max=16000
step=500
[/advanced_preference]

[advanced_preference]
field=joystick_num_thrusta_axis
name= _ "Joystick: number of the thrust axis joystick"
type=int
default=0
min=-1
max=3
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_thrusta_axis_num
name= _ "Joystick: number of the thrust axis"
type=int
default=2
min=0
max=7
step=1
[/advanced_preference]

[advanced_preference]
field=joystick_thrusta_deadzone
name= _ "Joystick: deadzone of the thruster"
type=int
default=1500
min=0
max=16000
step=500
[/advanced_preference]
#endif
1 change: 0 additions & 1 deletion source_lists/libwesnoth
Expand Up @@ -29,7 +29,6 @@ image.cpp
image_modifications.cpp
preferences/credentials.cpp
preferences/general.cpp
joystick.cpp
key.cpp
language.cpp
map/label.cpp
Expand Down
42 changes: 3 additions & 39 deletions src/controller_base.cpp
Expand Up @@ -40,7 +40,6 @@ controller_base::controller_base(const config& game_config)
, scroll_down_(false)
, scroll_left_(false)
, scroll_right_(false)
, joystick_manager_()
, key_release_listener_(*this)
{
}
Expand Down Expand Up @@ -175,7 +174,7 @@ bool controller_base::have_keyboard_focus()
return !gui2::is_in_dialog();
}

bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, double x_axis, double y_axis)
bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags)
{
const bool mouse_in_window =
CVideo::get_singleton().window_has_flags(SDL_WINDOW_MOUSE_FOCUS)
Expand Down Expand Up @@ -231,7 +230,7 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, dou
if(sdl::point_in_rect(mousex, mousey, rect) && mh_base.scroll_started()) {
// Scroll speed is proportional from the distance from the first
// middle click and scrolling speed preference.
const double speed = 0.04 * sqrt(static_cast<double>(scroll_speed));
const double speed = 0.04 * std::sqrt(static_cast<double>(scroll_speed));
const double snap_dist = 16; // Snap to horizontal/vertical scrolling
const double x_diff = (mousex - original_loc.x);
const double y_diff = (mousey - original_loc.y);
Expand All @@ -249,10 +248,6 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, dou
}
}

// scroll with joystick
dx += round_double(x_axis * scroll_speed);
dy += round_double(y_axis * scroll_speed);

return get_display().scroll(dx, dy);
}

Expand Down Expand Up @@ -298,44 +293,13 @@ void controller_base::play_slice(bool is_delay_enabled)

bool was_scrolling = scrolling_;

std::pair<double, double> values = joystick_manager_.get_scroll_axis_pair();
const double joystickx = values.first;
const double joysticky = values.second;

int mousex, mousey;
uint8_t mouse_flags = SDL_GetMouseState(&mousex, &mousey);

// TODO enable after an axis choosing mechanism is implemented
#if 0
std::pair<double, double> values = joystick_manager_.get_mouse_axis_pair();
mousex += values.first * 10;
mousey += values.second * 10;
SDL_WarpMouse(mousex, mousey);
#endif

scrolling_ = handle_scroll(mousex, mousey, mouse_flags, joystickx, joysticky);
scrolling_ = handle_scroll(mousex, mousey, mouse_flags);

map_location highlighted_hex = get_display().mouseover_hex();

// TODO: enable when the relative cursor movement is implemented well enough
#if 0
const map_location& selected_hex = get_display().selected_hex();

if (selected_hex != map_location::null_location()) {
if (joystick_manager_.next_highlighted_hex(highlighted_hex, selected_hex)) {
get_mouse_handler_base().mouse_motion(0,0, true, true, highlighted_hex);
get_display().scroll_to_tile(highlighted_hex, display::ONSCREEN_WARP, false, true);
scrolling_ = true;
}
} else
#endif

if(joystick_manager_.update_highlighted_hex(highlighted_hex) && get_display().get_map().on_board(highlighted_hex)) {
get_mouse_handler_base().mouse_motion(0, 0, true, true, highlighted_hex);
get_display().scroll_to_tile(highlighted_hex, display::ONSCREEN_WARP, false, true);
scrolling_ = true;
}

// be nice when window is not visible
// NOTE should be handled by display instead, to only disable drawing
if(is_delay_enabled && !CVideo::get_singleton().window_has_flags(SDL_WINDOW_SHOWN)) {
Expand Down
5 changes: 1 addition & 4 deletions src/controller_base.hpp
Expand Up @@ -37,7 +37,6 @@

#include "events.hpp"
#include "hotkey/hotkey_command.hpp"
#include "joystick.hpp"
#include "key.hpp"
#include "quit_confirmation.hpp"

Expand Down Expand Up @@ -142,7 +141,7 @@ class controller_base : public events::sdl_handler, public events::pump_monitor
* @see scrolling_, which is set if the display is being scrolled
* @return true when there was any scrolling, false otherwise
*/
bool handle_scroll(int mousex, int mousey, int mouse_flags, double joystickx, double joysticky);
bool handle_scroll(int mousex, int mousey, int mouse_flags);

/**
* Process mouse- and keypress-events from SDL.
Expand Down Expand Up @@ -185,8 +184,6 @@ class controller_base : public events::sdl_handler, public events::pump_monitor
bool scroll_left_;
bool scroll_right_;

joystick_manager joystick_manager_;

private:
/* A separate class for listening key-up events.
It's needed because otherwise such events might be consumed by a different event context
Expand Down

0 comments on commit d384b96

Please sign in to comment.