Skip to content

Commit 53ddbf6

Browse files
committed
reduce dreamlink's SDL dependency
1 parent 1be9722 commit 53ddbf6

File tree

5 files changed

+16
-62
lines changed

5 files changed

+16
-62
lines changed

core/hw/maple/maple_if.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "hw/naomi/card_reader.h"
1010

1111
#include <memory>
12+
13+
// TODO: should we move these to maple folder?
1214
#include <sdl/dreamlink.h>
1315
#include <sdl/dreamconn.h>
1416

core/sdl/dreamconn.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
#include "dreamconn.h"
2020

21-
#ifdef USE_DREAMCASTCONTROLLER
2221
#include "hw/maple/maple_devs.h"
22+
#include "hw/maple/maple_if.h"
2323
#include "ui/gui.h"
2424
#include <cfg/option.h>
2525
#include <SDL.h>
@@ -35,7 +35,6 @@
3535
#include <windows.h>
3636
#include <setupapi.h>
3737
#endif
38-
#include <hw/maple/maple_if.h>
3938

4039
// TODO: it doesn't seem sound to assume that only one dreamlink will need reconnecting at a time.
4140
std::shared_ptr<DreamLink> dreamlink_needs_reconnect = nullptr;
@@ -217,18 +216,9 @@ void DreamConn::connect() {
217216

218217
iostream.expires_from_now(std::chrono::duration<u32>::max()); // don't use a 64-bit based duration to avoid overflow
219218

220-
// TODO: unsure whether to adjust or to delete this condition. We need to stay connected to be notified if a peripheral gets plugged back in later on
221-
if (true || (hasVmu() || hasRumble()))
222-
{
223-
NOTICE_LOG(INPUT, "Connected to DreamcastController[%d]: Type:%s, VMU:%d, Rumble Pack:%d", bus, getName().c_str(), hasVmu(), hasRumble());
224-
maple_io_connected = true;
225-
}
226-
else
227-
{
228-
WARN_LOG(INPUT, "DreamcastController[%d] connection: no VMU or Rumble Pack connected", bus);
229-
disconnect();
230-
return;
231-
}
219+
// Remain connected even if no devices were found, so that plugging one in later will be detected
220+
NOTICE_LOG(INPUT, "Connected to DreamcastController[%d]: Type:%s, VMU:%d, Rumble Pack:%d", bus, getName().c_str(), hasVmu(), hasRumble());
221+
maple_io_connected = true;
232222
}
233223

234224
void DreamConn::disconnect() {
@@ -239,5 +229,3 @@ void DreamConn::disconnect() {
239229

240230
NOTICE_LOG(INPUT, "Disconnected from DreamcastController[%d]", bus);
241231
}
242-
243-
#endif

core/sdl/dreamconn.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#pragma once
2020
#include "dreamlink.h"
2121

22-
#ifdef USE_DREAMCASTCONTROLLER
23-
2422
#include <asio.hpp>
2523
#include <mutex>
2624

@@ -101,5 +99,3 @@ class DreamConn : public DreamLink
10199

102100
void disconnect() override;
103101
};
104-
105-
#endif // USE_DREAMCASTCONTROLLER

core/sdl/dreamlink.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -242,39 +242,4 @@ void DreamLinkGamepad::checkKeyCombo() {
242242
if (ltrigPressed && rtrigPressed && startPressed)
243243
gui_open_settings();
244244
}
245-
246-
#else // USE_DREAMCASTCONTROLLER
247-
248-
bool DreamLinkGamepad::isDreamcastController(int deviceIndex) {
249-
return false;
250-
}
251-
DreamLinkGamepad::DreamLinkGamepad(int maple_port, int joystick_idx, SDL_Joystick* sdl_joystick)
252-
: SDLGamepad(maple_port, joystick_idx, sdl_joystick) {
253-
}
254-
DreamLinkGamepad::~DreamLinkGamepad() {
255-
}
256-
void DreamLinkGamepad::set_maple_port(int port) {
257-
SDLGamepad::set_maple_port(port);
258-
}
259-
void DreamLinkGamepad::registered() {
260-
}
261-
bool DreamLinkGamepad::gamepad_btn_input(u32 code, bool pressed) {
262-
return SDLGamepad::gamepad_btn_input(code, pressed);
263-
}
264-
bool DreamLinkGamepad::gamepad_axis_input(u32 code, int value) {
265-
return SDLGamepad::gamepad_axis_input(code, value);
266-
}
267-
void DreamLinkGamepad::resetMappingToDefault(bool arcade, bool gamepad) {
268-
SDLGamepad::resetMappingToDefault(arcade, gamepad);
269-
}
270-
const char *DreamLinkGamepad::get_button_name(u32 code) {
271-
return SDLGamepad::get_button_name(code);
272-
}
273-
const char *DreamLinkGamepad::get_axis_name(u32 code) {
274-
return SDLGamepad::get_axis_name(code);
275-
}
276-
std::shared_ptr<InputMapping> DreamLinkGamepad::getDefaultMapping() {
277-
return SDLGamepad::getDefaultMapping();
278-
}
279-
280245
#endif

core/sdl/dreamlink.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@
1818
*/
1919
#pragma once
2020

21-
// This file contains abstraction layer for access to different kinds of physical controllers
21+
// This file contains abstraction layer for access to different kinds of remote peripherals.
22+
// This includes both real Dreamcast controllers, VMUs, rumble packs etc. but also emulated VMUs.
2223

2324
#include "types.h"
2425
#include "emulator.h"
25-
#include "sdl_gamepad.h"
26-
27-
#include <functional>
28-
#include <memory>
29-
#include <array>
3026

31-
#if (defined(_WIN32) || defined(__linux__) || (defined(__APPLE__) && defined(TARGET_OS_MAC))) && !defined(TARGET_UWP)
27+
#if (defined(_WIN32) || defined(__linux__) || (defined(__APPLE__) && defined(TARGET_OS_MAC))) && !defined(TARGET_UWP) && defined(USE_SDL)
3228
#define USE_DREAMCASTCONTROLLER 1
29+
#include "sdl_gamepad.h"
3330
#endif
3431

32+
#include <functional>
3533
#include <memory>
34+
#include <array>
3635

3736
struct MapleMsg
3837
{
@@ -96,9 +95,11 @@ class DreamLink : public std::enable_shared_from_this<DreamLink>
9695
return -1;
9796
}
9897

98+
#if defined(USE_DREAMCASTCONTROLLER)
9999
//! Allows a DreamLink device to dictate the default mapping
100100
virtual void setDefaultMapping(const std::shared_ptr<InputMapping>& mapping) const {
101101
}
102+
#endif
102103

103104
//! Allows button names to be defined by a DreamLink device
104105
//! @param[in] code The button code to retrieve name of
@@ -140,6 +141,7 @@ class DreamLink : public std::enable_shared_from_this<DreamLink>
140141
virtual void disconnect() = 0;
141142
};
142143

144+
#if defined(USE_DREAMCASTCONTROLLER)
143145
class DreamLinkGamepad : public SDLGamepad
144146
{
145147
public:
@@ -168,6 +170,7 @@ class DreamLinkGamepad : public SDLGamepad
168170
bool startPressed = false;
169171
std::string device_guid;
170172
};
173+
#endif
171174

172175
extern std::vector<std::shared_ptr<DreamLink>> allDreamLinks;
173176
void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart);

0 commit comments

Comments
 (0)