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 Oct 19, 2019
1 parent 9a7b11f commit e643d2d
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 973 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -89,6 +89,7 @@
* Fix maps with scenario_generation= were unavailable in the editor.
* Passing relative paths to --user-data-dir is deprecated (part of PR#4449),
* On windows, relative paths that start with `.\` are not deprecated
* Removed incomplete joystick support.

## Version 1.15.1
### Editor
Expand Down Expand Up @@ -1030,6 +1031,7 @@
associated options as Wesnoth now uses SDL_image to write PNG files.
* Fixed assertion when saving game events mid-event.


## Version 1.13.12
### Security fixes
* Disallowed access to blacklisted file paths such as hidden files and
Expand Down
186 changes: 0 additions & 186 deletions data/advanced_preferences.cfg
Expand Up @@ -192,190 +192,4 @@ Note: this option only affects singleplayer, and the ‘Save random seed’ opti
[/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 @@ -32,7 +32,6 @@ picture.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 @@ -42,7 +42,6 @@ controller_base::controller_base()
, scroll_down_(false)
, scroll_left_(false)
, scroll_right_(false)
, joystick_manager_()
, key_release_listener_(*this)
, last_mouse_is_touch_(false)
, long_touch_timer_(0)
Expand Down Expand Up @@ -266,7 +265,7 @@ bool controller_base::have_keyboard_focus()
return true;
}

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 @@ -322,7 +321,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 @@ -340,10 +339,6 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, dou
}
}

// scroll with joystick
dx += std::round(x_axis * scroll_speed);
dy += std::round(y_axis * scroll_speed);

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

Expand Down Expand Up @@ -388,44 +383,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)) {
CVideo::delay(200);
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"
#include "video.hpp"
Expand Down Expand Up @@ -140,7 +139,7 @@ class controller_base : public video2::draw_layering, public events::pump_monito
* @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 @@ -191,8 +190,6 @@ class controller_base : public video2::draw_layering, public events::pump_monito
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
23 changes: 0 additions & 23 deletions src/game_launcher.cpp
Expand Up @@ -291,29 +291,6 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
}
}

bool game_launcher::init_joystick()
{
if (!preferences::joystick_support_enabled())
return false;

if(SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
return false;

int joysticks = SDL_NumJoysticks();
if (joysticks == 0) return false;

SDL_JoystickEventState(SDL_ENABLE);

bool joystick_found = false;
for (int i = 0; i<joysticks; i++) {

if (SDL_JoystickOpen(i))
joystick_found = true;
}
return joystick_found;
}

bool game_launcher::init_language()
{
if(!::load_language_list())
Expand Down
1 change: 0 additions & 1 deletion src/game_launcher.hpp
Expand Up @@ -59,7 +59,6 @@ class game_launcher

bool init_video();
bool init_language();
bool init_joystick();
bool init_lua_script();

bool play_test();
Expand Down
17 changes: 0 additions & 17 deletions src/hotkey/hotkey_item.cpp
Expand Up @@ -207,23 +207,6 @@ hotkey_ptr load_from_config(const config& cfg)
mouse->set_button(cfg["button"].to_int());
}
}
// TODO: add joystick support back
#if 0
const std::string& joystick_cfg = cfg["joystick"];
if (!joystick_cfg.empty()) {
joystick_ = cfg["joystick"].to_int();
}
const std::string& hat = cfg["hat"];
if (!hat.empty()) {
hat_ = cfg["hat"].to_int();
value_ = cfg["value"].to_int();
}

const std::string& button = cfg["button"];
if (!button.empty()) {
button_ = cfg["button"].to_int();
}
#endif

const std::string& key_cfg = cfg["key"];
if (!key_cfg.empty()) {
Expand Down

0 comments on commit e643d2d

Please sign in to comment.