Skip to content

Commit

Permalink
compile fixes & add mouse patch to mupen64plus-core
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Jun 25, 2024
1 parent 04f2ed6 commit ef28d45
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 84 deletions.
8 changes: 8 additions & 0 deletions Source/3rdParty/mupen64plus-core/src/api/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P
{
m64p_error rval;
int keysym, keymod;
int x, y;

if (!l_CoreInit)
return M64ERR_NOT_INIT;
Expand Down Expand Up @@ -315,6 +316,13 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P
keymod = (ParamInt >> 16) & 0xffff;
event_sdl_keyup(keysym, keymod);
return M64ERR_SUCCESS;
case M64CMD_SET_MOUSE_MOVE:
if (!g_EmulatorRunning)
return M64ERR_INVALID_STATE;
x = ParamInt & 0xffff;
y = (ParamInt >> 16) & 0xffff;
event_mouse_move(x, y);
return M64ERR_SUCCESS;
case M64CMD_SET_FRAME_CALLBACK:
*(void**)&g_FrameCallback = ParamPtr;
return M64ERR_SUCCESS;
Expand Down
3 changes: 3 additions & 0 deletions Source/3rdParty/mupen64plus-core/src/api/m64p_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef struct {
/*** Controller types ****/
#define CONT_TYPE_STANDARD 0
#define CONT_TYPE_VRU 1
#define CONT_TYPE_MOUSE 2

typedef struct {
int Present;
Expand Down Expand Up @@ -264,6 +265,7 @@ typedef void (*ptr_InitiateControllers)(CONTROL_INFO ControlInfo);
typedef void (*ptr_ReadController)(int Control, unsigned char *Command);
typedef void (*ptr_SDL_KeyDown)(int keymod, int keysym);
typedef void (*ptr_SDL_KeyUp)(int keymod, int keysym);
typedef void (*ptr_MouseMove)(int x, int y);
typedef void (*ptr_RenderCallback)(void);
typedef void (*ptr_SendVRUWord)(uint16_t length, uint16_t *word, uint8_t lang);
typedef void (*ptr_SetMicState)(int state);
Expand All @@ -277,6 +279,7 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo);
EXPORT void CALL ReadController(int Control, unsigned char *Command);
EXPORT void CALL SDL_KeyDown(int keymod, int keysym);
EXPORT void CALL SDL_KeyUp(int keymod, int keysym);
EXPORT void CALL MouseMove(int x, int y);
EXPORT void CALL RenderCallback(void);
EXPORT void CALL SendVRUWord(uint16_t length, uint16_t *word, uint8_t lang);
EXPORT void CALL SetMicState(int state);
Expand Down
3 changes: 2 additions & 1 deletion Source/3rdParty/mupen64plus-core/src/api/m64p_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ typedef enum {
M64CMD_PIF_OPEN,
M64CMD_ROM_SET_SETTINGS,
M64CMD_DISK_OPEN,
M64CMD_DISK_CLOSE
M64CMD_DISK_CLOSE,
M64CMD_SET_MOUSE_MOVE
} m64p_command;

typedef struct {
Expand Down
8 changes: 8 additions & 0 deletions Source/3rdParty/mupen64plus-core/src/main/eventloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ void event_sdl_keyup(int keysym, int keymod)
}
}

void event_mouse_move(int x, int y)
{
if (input.mouseMove != NULL)
{
input.mouseMove(x, y);
}
}

int event_gameshark_active(void)
{
return GamesharkActive;
Expand Down
1 change: 1 addition & 0 deletions Source/3rdParty/mupen64plus-core/src/main/eventloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern int event_set_core_defaults(void);
extern void event_initialize(void);
extern void event_sdl_keydown(int keysym, int keymod);
extern void event_sdl_keyup(int keysym, int keymod);
extern void event_mouse_move(int x, int y);
extern int event_gameshark_active(void);
extern void event_set_gameshark(int active);

Expand Down
13 changes: 7 additions & 6 deletions Source/3rdParty/mupen64plus-core/src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,12 +1778,13 @@ m64p_error main_run(void)
}
/* otherwise let the core do the processing */
else {
/* select appropriate controller
* FIXME: assume for now that only standard controller is compatible
* Use the rom db to know if other peripherals are compatibles (VRU, mouse, train, ...)
*/
const struct game_controller_flavor* cont_flavor =
&g_standard_controller_flavor;
const struct game_controller_flavor* cont_flavor;

if (Controls[i].Type == CONT_TYPE_MOUSE) {
cont_flavor = &g_mouse_controller_flavor;
} else {
cont_flavor = &g_standard_controller_flavor;
}

joybus_devices[i] = &g_dev.controllers[i];
ijoybus_devices[i] = &g_ijoybus_device_controller;
Expand Down
6 changes: 6 additions & 0 deletions Source/3rdParty/mupen64plus-core/src/plugin/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static const input_plugin_functions dummy_input = {
dummyinput_RomOpen,
dummyinput_SDL_KeyDown,
dummyinput_SDL_KeyUp,
NULL,
dummyinput_RenderCallback
};

Expand Down Expand Up @@ -403,6 +404,11 @@ static m64p_error plugin_connect_input(m64p_dynlib_handle plugin_handle)
DebugMessage(M64MSG_WARNING, "Input plugin does not contain VRU support.");
}

if (!GET_FUNC(ptr_MouseMove, input.mouseMove, "MouseMove"))
{
DebugMessage(M64MSG_WARNING, "Input plugin does not contain mouse support.");
}

/* check the version info */
(*input.getVersion)(&PluginType, &PluginVersion, &APIVersion, NULL, NULL);
if (PluginType != M64PLUGIN_INPUT || (APIVersion & 0xffff0000) != (INPUT_API_VERSION & 0xffff0000) || APIVersion < 0x020100)
Expand Down
1 change: 1 addition & 0 deletions Source/3rdParty/mupen64plus-core/src/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct _input_plugin_functions
ptr_RomOpen romOpen;
ptr_SDL_KeyDown keyDown;
ptr_SDL_KeyUp keyUp;
ptr_MouseMove mouseMove;
ptr_RenderCallback renderCallback;
ptr_SendVRUWord sendVRUWord;
ptr_SetMicState setMicState;
Expand Down
10 changes: 0 additions & 10 deletions Source/RMG-Core/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,6 @@ bool apply_plugin_settings(std::string pluginSettings[4])
return false;
}

// register mouse callback for input plugin,
// if it exists
if (pluginType == CorePluginType::Input)
{
if (plugin->SetResetMousePositionCallback != nullptr)
{
plugin->SetResetMousePositionCallback(ResetMousePositionCallback);
}
}

l_PluginFiles[i] = settingValue;

CoreAddCallbackMessage(CoreDebugMessageType::Info,
Expand Down
3 changes: 2 additions & 1 deletion Source/RMG-Core/m64p/api/m64p_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ EXPORT m64p_error CALL PluginConfig2(int);
typedef int (*ptr_PluginConfig2HasRomConfig)(void);
#if defined(M64P_PLUGIN_PROTOTYPES) || defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL PluginConfig2HasRomConfig(void);
#endif

/* SetResetMousePositionCallback()
*
Expand All @@ -59,4 +60,4 @@ EXPORT void CALL SetResetMousePositionCallback(ptr_ResetMousePositionCallback);
}
#endif

#endif // M64P_CUSTOM_H
#endif // M64P_CUSTOM_H
28 changes: 12 additions & 16 deletions Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,6 @@ void ControllerWidget::on_inputTypeComboBox_currentIndexChanged(int value)
{
groupBox_4,
deadZoneGroupBox,
groupBox,
groupBox_2,
groupBox_3,
groupBox_6,
};

if (value == 1)
Expand Down Expand Up @@ -1175,11 +1171,11 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
{
if (!sdlHatCentered && sdlHatDirection == direction)
{
this->controllerImageWidget->SetButtonState(button.button, true);
this->controllerImageWidget->SetControllerButtonState(button.button, true);
}
else
{
this->controllerImageWidget->SetButtonState(button.button, false);
this->controllerImageWidget->SetControllerButtonState(button.button, false);
}
}
}
Expand Down Expand Up @@ -1846,16 +1842,16 @@ void ControllerWidget::SaveSettings(QString section)

this->GetCurrentInputDevice(deviceName, deviceNum, true);

CoreSettingsSetValue(SettingsID::Input_PluggedIn, section, this->IsPluggedIn());
CoreSettingsSetValue(SettingsID::Input_InputType, section, this->inputTypeComboBox->currentIndex());
CoreSettingsSetValue(SettingsID::Input_DeviceName, section, deviceName.toStdString());
CoreSettingsSetValue(SettingsID::Input_DeviceNum, section, deviceNum);
CoreSettingsSetValue(SettingsID::Input_Deadzone, section, this->deadZoneSlider->value());
CoreSettingsSetValue(SettingsID::Input_Pak, section, this->optionsDialogSettings.ControllerPak);
CoreSettingsSetValue(SettingsID::Input_GameboyRom, section, this->optionsDialogSettings.GameboyRom);
CoreSettingsSetValue(SettingsID::Input_GameboySave, section, this->optionsDialogSettings.GameboySave);
CoreSettingsSetValue(SettingsID::Input_RemoveDuplicateMappings, section, this->optionsDialogSettings.RemoveDuplicateMappings);
CoreSettingsSetValue(SettingsID::Input_InvertAxis, section, this->optionsDialogSettings.InvertAxis);
CoreSettingsSetValue(SettingsID::Input_PluggedIn, sectionStr, this->IsPluggedIn());
CoreSettingsSetValue(SettingsID::Input_InputType, sectionStr, this->inputTypeComboBox->currentIndex());
CoreSettingsSetValue(SettingsID::Input_DeviceName, sectionStr, deviceName.toStdString());
CoreSettingsSetValue(SettingsID::Input_DeviceNum, sectionStr, deviceNum);
CoreSettingsSetValue(SettingsID::Input_Deadzone, sectionStr, this->deadZoneSlider->value());
CoreSettingsSetValue(SettingsID::Input_Pak, sectionStr, this->optionsDialogSettings.ControllerPak);
CoreSettingsSetValue(SettingsID::Input_GameboyRom, sectionStr, this->optionsDialogSettings.GameboyRom);
CoreSettingsSetValue(SettingsID::Input_GameboySave, sectionStr, this->optionsDialogSettings.GameboySave);
CoreSettingsSetValue(SettingsID::Input_RemoveDuplicateMappings, sectionStr, this->optionsDialogSettings.RemoveDuplicateMappings);
//CoreSettingsSetValue(SettingsID::Input_InvertAxis, sectionStr, this->optionsDialogSettings.InvertAxis);
CoreSettingsSetValue(SettingsID::Input_FilterEventsForButtons, sectionStr, this->optionsDialogSettings.FilterEventsForButtons);
CoreSettingsSetValue(SettingsID::Input_FilterEventsForAxis, sectionStr, this->optionsDialogSettings.FilterEventsForAxis);

Expand Down
7 changes: 1 addition & 6 deletions Source/RMG-Input/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum class N64ControllerButton

enum class InputDeviceType
{
Mouse = -5,
EmulateVRU = -4,
None = -3,
Automatic = -2,
Expand All @@ -46,12 +47,6 @@ enum class N64MouseButton
Invalid
};

enum class InputDeviceType
{
Controller = 0,
Mouse
};

enum class InputType
{
Keyboard = -1,
Expand Down
51 changes: 26 additions & 25 deletions Source/RMG-Input/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct InputProfile
int DeadzoneValue = 0;
int SensitivityValue = 100;

InputDeviceType DeviceType = InputDeviceType::Controller;
InputDeviceType DeviceType = InputDeviceType::Mouse;

N64ControllerPak ControllerPak = N64ControllerPak::None;

Expand Down Expand Up @@ -449,7 +449,7 @@ static void apply_controller_profiles(void)
l_ControlInfo.Controls[i].Type = CONT_TYPE_STANDARD;
}

l_ControlInfo.Controls[i].Type = (profile->DeviceType == InputDeviceType::Controller ? CONT_TYPE_STANDARD : CONT_TYPE_MOUSE);
l_ControlInfo.Controls[i].Type = (profile->DeviceType != InputDeviceType::Mouse ? CONT_TYPE_STANDARD : CONT_TYPE_MOUSE);
}
}

Expand Down Expand Up @@ -1285,36 +1285,37 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys)
if (Control == 0)
{
// mouse
if (profile->DeviceType == InputDeviceType::Mouse)
{ // n64 mouse
l_MouseMutex.lock();
if (profile->DeviceType == InputDeviceType::Mouse)
{ // n64 mouse
l_MouseMutex.lock();

// set left & right button state
Keys->A_BUTTON = l_MouseButtonState[0];
Keys->B_BUTTON = l_MouseButtonState[1];
// set left & right button state
Keys->A_BUTTON = l_MouseButtonState[0];
Keys->B_BUTTON = l_MouseButtonState[1];

if (!l_MouseMovements.empty())
{
// calculate how much the mouse has moved
const int x = l_MouseMovements.front().x - l_MouseMovements.back().x;
const int y = l_MouseMovements.front().y - l_MouseMovements.back().y;
if (!l_MouseMovements.empty())
{
// calculate how much the mouse has moved
const int x = l_MouseMovements.front().x - l_MouseMovements.back().x;
const int y = l_MouseMovements.front().y - l_MouseMovements.back().y;

// set axis state
Keys->X_AXIS = -x;
Keys->Y_AXIS = y;
// set axis state
Keys->X_AXIS = -x;
Keys->Y_AXIS = y;

l_MouseMovements.clear();
}
l_MouseMovements.clear();
}

l_MouseMutex.unlock();
l_MouseMutex.unlock();

// request front-end to reset mouse position
if (l_ResetMousPositionCallback != nullptr)
{
l_ResetMousPositionCallback();
}
// request front-end to reset mouse position
if (l_ResetMousPositionCallback != nullptr)
{
l_ResetMousPositionCallback();
}

return;
return;
}
}

Keys->A_BUTTON = get_button_state(profile, &profile->Button_A);
Expand Down
10 changes: 0 additions & 10 deletions Source/RMG/Callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,3 @@ void CoreCallbacks::coreStateCallback(CoreStateCallbackType type, int value)

emit l_CoreCallbacks->OnCoreStateCallback(type, value);
}

void CoreCallbacks::resetMousePositionCallback(void)
{
if (l_CoreCallbacks == nullptr)
{
return;
}

emit l_CoreCallbacks->OnResetMousePositionCallback();
}
2 changes: 0 additions & 2 deletions Source/RMG/Callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class CoreCallbacks : public QObject
void OnCoreDebugCallback(QList<CoreCallbackMessage> callbackMessages);
void OnCoreStateCallback(CoreStateCallbackType type, int value);

static void resetMousePositionCallback(void);

signals:
void OnCoreDebugCallback(CoreDebugMessageType type, QString context, QString message);
void OnResetMousePositionCallback(void);
Expand Down
8 changes: 1 addition & 7 deletions Source/RMG/UserInterface/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool MainWindow::Init(QApplication* app, bool showUI, bool launchROM)
this->coreCallBacks = new CoreCallbacks(this);

// connect signals early due to pending debug callbacks
connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, this, &MainWindow::on_Core_DebugCallback);
//connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, this, &MainWindow::on_Core_DebugCallback);
connect(coreCallBacks, &CoreCallbacks::OnCoreStateCallback, this, &MainWindow::on_Core_StateCallback);
connect(app, &QGuiApplication::applicationStateChanged, this, &MainWindow::on_QGuiApplication_applicationStateChanged);

Expand All @@ -105,12 +105,6 @@ bool MainWindow::Init(QApplication* app, bool showUI, bool launchROM)
{
this->addActions();
}

connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, this, &MainWindow::on_Core_DebugCallback);
connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, &this->logDialog, &Dialog::LogDialog::AddLogLine);
connect(coreCallBacks, &CoreCallbacks::OnResetMousePositionCallback, this, &MainWindow::on_Core_ResetMousPositionCallback, Qt::BlockingQueuedConnection);
connect(app, &QGuiApplication::applicationStateChanged, this, &MainWindow::on_QGuiApplication_applicationStateChanged);

return true;
}

Expand Down

0 comments on commit ef28d45

Please sign in to comment.