Now you can switch between Emulated and Real WiiMotes, connect more Real Wiimotes and even pair them up (if you have MS BT Stack) during gameplay!

All you gotta do is Pause the emulation! That's useful for when your batteries run out during gameplay, for example...

But if you change the WiiMote source (between Emulated, Real or Inactive) you must disconnect and reconnect (Menu Tools -> Connect WiiMote) the WiiMotes affected by the change...

Thanks to jack.fr0st who did all the emulation state notification work!

Now every plugin has a way to know the current emulation state (paused, stopped or playing)

@ayuanx: I thought about doing a PostMessage(g_WiimoteInitialize.hWnd, WM_USER, WIIMOTE_DISCONNECT, current_number); so that the user gets asked to reconnect that WiiMote, trying to avoid having to disconnect and reconnect, but it didn't work because shooting that message only asks to reconnect, doesn't do a disconnect... Do you have any ideas on how to accomplish that?

Also, if anyone could check if Issue 1916 is finally fixed... Or at least when is the cursor being hidden or not...

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4789 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
fgfemperor 2010-01-06 19:26:52 +00:00
parent 623a09b5a5
commit 64167bcb60
18 changed files with 117 additions and 37 deletions

View File

@ -40,6 +40,7 @@ CPlugin::CPlugin(const char* _szName) : valid(false)
m_Initialize = NULL;
m_Shutdown = NULL;
m_DoState = NULL;
m_EmuStateChange = NULL;
if (m_hInstLib.Load(_szName))
{
@ -57,6 +58,8 @@ CPlugin::CPlugin(const char* _szName) : valid(false)
(m_hInstLib.Get("Shutdown"));
m_DoState = reinterpret_cast<TDoState>
(m_hInstLib.Get("DoState"));
m_EmuStateChange = reinterpret_cast<TEmuStateChange>
(m_hInstLib.Get("EmuStateChange"));
// Check if the plugin has all the functions it shold have
if (m_GetDllInfo != 0 &&
@ -65,7 +68,8 @@ CPlugin::CPlugin(const char* _szName) : valid(false)
m_SetDllGlobals != 0 &&
m_Initialize != 0 &&
m_Shutdown != 0 &&
m_DoState != 0)
m_DoState != 0 &&
m_EmuStateChange != 0)
valid = true;
}
@ -112,6 +116,11 @@ void CPlugin::DoState(unsigned char **ptr, int mode) {
m_DoState(ptr, mode);
}
void CPlugin::EmuStateChange(PLUGIN_EMUSTATE newState) {
if (m_EmuStateChange != NULL)
m_EmuStateChange(newState);
}
void CPlugin::Initialize(void *init)
{
if (m_Initialize != NULL)

View File

@ -31,6 +31,7 @@ namespace Common
typedef void (__cdecl * TInitialize)(void *);
typedef void (__cdecl * TShutdown)();
typedef void (__cdecl * TDoState)(unsigned char**, int);
typedef void (__cdecl * TEmuStateChange)(PLUGIN_EMUSTATE);
class CPlugin
{
@ -50,6 +51,7 @@ public:
void About(HWND _hwnd);
void Debug(HWND _hwnd, bool Show);
void DoState(unsigned char **ptr, int mode);
void EmuStateChange(PLUGIN_EMUSTATE newState);
void Initialize(void *init);
void Shutdown();
@ -66,6 +68,7 @@ private:
TInitialize m_Initialize;
TShutdown m_Shutdown;
TDoState m_DoState;
TEmuStateChange m_EmuStateChange;
};
} // Namespace

View File

@ -196,6 +196,7 @@ void Stop() // - Hammertime!
{
const SCoreStartupParameter& _CoreParameter = SConfig::GetInstance().m_LocalCoreStartupParameter;
g_bStopping = true;
CPluginManager::GetInstance().EmuStateChange(PLUGIN_EMUSTATE_STOP);
WARN_LOG(CONSOLE, "Stop [Main Thread]\t\t---- Shutting down ----");
@ -531,10 +532,12 @@ void SetState(EState _State)
case CORE_PAUSE:
CCPU::EnableStepping(true); // Break
CPluginManager::GetInstance().GetDSP()->DSP_ClearAudioBuffer();
CPluginManager::GetInstance().EmuStateChange(PLUGIN_EMUSTATE_PAUSE);
break;
case CORE_RUN:
CCPU::EnableStepping(false);
CPluginManager::GetInstance().GetDSP()->DSP_ClearAudioBuffer();
CPluginManager::GetInstance().EmuStateChange(PLUGIN_EMUSTATE_PLAY);
break;
default:
PanicAlert("Invalid state");

View File

@ -462,6 +462,17 @@ void CPluginManager::FreeWiimote(u32 Wiimote)
}
}
void CPluginManager::EmuStateChange(PLUGIN_EMUSTATE newState)
{
GetVideo()->EmuStateChange(newState);
GetDSP()->EmuStateChange(newState);
//TODO: OpenConfig below only uses GetXxx(0) aswell
// Would we need to call all plugins?
// If yes, how would one check if the plugin was not
// just created by GetXxx(idx) because there was none?
GetPad(0)->EmuStateChange(newState);
GetWiimote(0)->EmuStateChange(newState);
}

View File

@ -57,6 +57,8 @@ public:
void FreePad(u32 Pad);
void FreeWiimote(u32 Wiimote);
void EmuStateChange(PLUGIN_EMUSTATE newState);
bool InitPlugins();
void ShutdownPlugins();
void ShutdownVideoPlugin();

View File

@ -83,6 +83,12 @@ enum PLUGIN_TYPE {
#define STATE_MODE_WRITE 2
#define STATE_MODE_MEASURE 3
// used for notification on emulation state
enum PLUGIN_EMUSTATE {
PLUGIN_EMUSTATE_PLAY = 1,
PLUGIN_EMUSTATE_PAUSE,
PLUGIN_EMUSTATE_STOP,
};
// Export structs
// ------------
@ -169,6 +175,13 @@ EXPORT void CALL Shutdown(void);
//
EXPORT void CALL DoState(unsigned char **ptr, int mode);
// ___________________________________________________________________________
// Function: EmuStateChange
// Purpose: Notifies the plugin of a change in emulation state
// input: newState
// output: none
//
EXPORT void CALL EmuStateChange(PLUGIN_EMUSTATE newState);
#if defined(__cplusplus)

View File

@ -243,6 +243,9 @@ void DoState(unsigned char **ptr, int mode)
CDSPHandler::GetInstance().GetUCode()->DoState(p);
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
// Mailbox fuctions
unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox)

View File

@ -170,6 +170,10 @@ void DoState(unsigned char **ptr, int mode)
p.Do(g_InitMixer);
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
void DllDebugger(HWND _hParent, bool Show)
{
#if defined(HAVE_WX) && HAVE_WX

View File

@ -700,6 +700,10 @@ void DoState(unsigned char **ptr, int mode)
#endif
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
void Shutdown()
{
// Save the recording and reset the counter

View File

@ -121,7 +121,7 @@ void InitPP(int adapter, int f, int aa_mode, D3DPRESENT_PARAMETERS *pp)
pp->SwapEffect = D3DSWAPEFFECT_DISCARD;
pp->Windowed = FALSE;
//if(g_Config.bHideCursor)
if(!g_Config.RenderToMainframe)
//if(!g_Config.RenderToMainframe)
ShowCursor(FALSE);
}
else

View File

@ -310,6 +310,10 @@ void DoState(unsigned char **ptr, int mode) {
VideoCommon_DoState(p);
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
void Video_EnterLoop()
{
Fifo_EnterLoop(g_VideoInitialize);

View File

@ -377,6 +377,10 @@ void DoState(unsigned char **ptr, int mode) {
}
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
// This is called after Video_Initialize() from the Core
void Video_Prepare(void)
{

View File

@ -92,6 +92,10 @@ void DoState(unsigned char **ptr, int mode)
{
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
void Shutdown(void)
{
}

View File

@ -112,7 +112,7 @@ void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
break;
#ifdef WIN32
case ID_BUTTONPAIRUP:
if(!g_EmulatorRunning) {
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY) {
m_ButtonPairUp->Enable(false);
if (WiiMoteReal::WiimotePairUp() > 0) { //Only temporay solution TODO: 2nd step: threaded.
// sleep would be required (but not best way to solve that cuz 3000ms~ would be needed, which is not convenient),cuz BT device is not ready yet when calling DoRefreshReal()
@ -151,6 +151,7 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
// Basic Settings
m_InputSource[i] = new wxChoice(m_Controller[i], IDC_INPUT_SOURCE, wxDefaultPosition, wxDefaultSize, arrayStringFor_source, 0, wxDefaultValidator);
m_InputSource[i]->SetToolTip(wxT("This can only be changed when the emulator is paused or stopped."));
// Emulated Wiimote
m_SidewaysWiimote[i] = new wxCheckBox(m_Controller[i], IDC_SIDEWAYSWIIMOTE, wxT("Sideways Wiimote"));
@ -164,10 +165,10 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
m_Extension[i] = new wxChoice(m_Controller[i], IDC_EXTCONNECTED, wxDefaultPosition, wxDefaultSize, arrayStringFor_extension, 0, wxDefaultValidator);
m_ConnectRealWiimote[i] = new wxCheckBox(m_Controller[i], IDC_CONNECT_REAL, wxT("Connect Real Wiimote"));
m_ConnectRealWiimote[i]->SetToolTip(wxT("Connected to the Real WiiMote(s). This can not be changed during gameplay."));
m_ConnectRealWiimote[i]->SetToolTip(wxT("Connected to the Real WiiMote(s).\nThis can only be changed when the emulator is paused or stopped."));
m_FoundWiimote[i] = new wxStaticText(m_Controller[i], ID_FOUND_REAL, wxT("Found 0 WiiMotes"));
m_RefreshRealWiiMote[i] = new wxButton(m_Controller[i], ID_REFRESH_REAL, wxT("Refresh Real WiiMotes"));
m_RefreshRealWiiMote[i]->SetToolTip(wxT("Reconnect to all Real WiiMotes. This is useful if you recently connected another one."));
m_RefreshRealWiiMote[i]->SetToolTip(wxT("Reconnect to all Real WiiMotes.\nThis is useful if you recently connected another one.\nThis can only be done when the emulator is paused or stopped."));
//IR Pointer
m_TextScreenWidth[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Width: 000"));
@ -301,7 +302,7 @@ void WiimoteBasicConfigDialog::UpdateOnce(wxTimerEvent& event)
void WiimoteBasicConfigDialog::DoConnectReal()
{
if(g_Config.bConnectRealWiimote)
if (g_Config.bConnectRealWiimote)
{
if (!g_RealWiiMoteInitialized)
{
@ -320,15 +321,14 @@ void WiimoteBasicConfigDialog::DoConnectReal()
void WiimoteBasicConfigDialog::DoRefreshReal()
{
if(!g_Config.bConnectRealWiimote || g_EmulatorRunning)
return;
if (g_Config.bConnectRealWiimote && g_EmulatorState != PLUGIN_EMUSTATE_PLAY)
{
if (g_RealWiiMoteInitialized)
WiiMoteReal::Shutdown();
if (!g_RealWiiMoteInitialized)
{
WiiMoteReal::Initialize();
UpdateGUI();;
}
UpdateGUI();
}
void WiimoteBasicConfigDialog::DoUseReal()
@ -351,7 +351,7 @@ void WiimoteBasicConfigDialog::DoUseReal()
DEBUG_LOG(WIIMOTE, "DoUseReal() Connect extension: %i", !UsingExtension);
DoExtensionConnectedDisconnected(UsingExtension ? 1 : 0);
if (g_EmulatorRunning)
if (g_EmulatorState == PLUGIN_EMUSTATE_PLAY)
{
// Disable the checkbox for a moment
SetCursor(wxCursor(wxCURSOR_WAIT));
@ -400,28 +400,30 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
switch (event.GetId())
{
case IDC_CONNECT_REAL:
if(!g_EmulatorRunning)
// If the config dialog was open when the user click on Play/Pause, the GUI was not updated, so this could crash everything!
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY)
{
g_Config.bConnectRealWiimote = m_ConnectRealWiimote[m_Page]->IsChecked();
DoConnectReal();
}
break;
case IDC_INPUT_SOURCE:
if (m_InputSource[m_Page]->GetSelection() == 2)
// If the config dialog was open when the user click on Play/Pause, the GUI was not updated, so this could crash everything!
if (g_EmulatorState == PLUGIN_EMUSTATE_PLAY)
{
if(!g_EmulatorRunning)
PanicAlert("This can only be changed when the emulator is paused or stopped!");
WiiMoteEmu::WiiMapping[m_Page].Source = 0;
}
else
{
if (m_InputSource[m_Page]->GetSelection() == 2)
{
WiiMoteEmu::WiiMapping[m_Page].Source = 2;
DoUseReal();
}
else
{
PanicAlert("You can't change to Real WiiMote when a game is running!");
WiiMoteEmu::WiiMapping[m_Page].Source = 0;
}
}
else
WiiMoteEmu::WiiMapping[m_Page].Source = m_InputSource[m_Page]->GetSelection();
}
break;
case IDC_SIDEWAYSWIIMOTE:
WiiMoteEmu::WiiMapping[m_Page].bSideways = m_SidewaysWiimote[m_Page]->IsChecked();
@ -437,7 +439,7 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
DoExtensionConnectedDisconnected(WiiMoteEmu::EXT_NONE);
// It doesn't seem to be needed but shouldn't it at least take 25 ms to
// reconnect an extension after we disconnected another?
if(g_EmulatorRunning)
if (g_EmulatorRunning)
SLEEP(25);
// Update status
WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected = m_Extension[m_Page]->GetSelection();
@ -477,12 +479,13 @@ void WiimoteBasicConfigDialog::UpdateGUI()
mean that the wiimote must be sent the current reporting mode and the channel ID after it
has been initialized. Functions for that are basically already in place so these two options
could possibly be simplified to one option. */
m_InputSource[m_Page]->Enable(g_EmulatorState != PLUGIN_EMUSTATE_PLAY);
m_ConnectRealWiimote[m_Page]->SetValue(g_Config.bConnectRealWiimote);
m_ConnectRealWiimote[m_Page]->Enable(!g_EmulatorRunning);
m_RefreshRealWiiMote[m_Page]->Enable(!g_EmulatorRunning && g_Config.bConnectRealWiimote);
m_ButtonPairUp->Enable(!g_EmulatorRunning);
m_ConnectRealWiimote[m_Page]->Enable(g_EmulatorState != PLUGIN_EMUSTATE_PLAY);
m_RefreshRealWiiMote[m_Page]->Enable(g_EmulatorState != PLUGIN_EMUSTATE_PLAY && g_Config.bConnectRealWiimote);
m_ButtonPairUp->Enable(g_EmulatorState != PLUGIN_EMUSTATE_PLAY);
wxString Found;
if(g_Config.bConnectRealWiimote)
if (g_Config.bConnectRealWiimote)
Found.Printf(wxT("Connected to %i Real WiiMote(s)"), WiiMoteReal::g_NumberOfWiiMotes);
else
Found.Printf(wxT("Not connected to Real WiiMotes"));

View File

@ -80,6 +80,8 @@ std::vector<int> g_UpdateTimeList (5, 0);
// Movement recording
std::vector<SRecordingAll> VRecording(RECORDING_ROWS);
PLUGIN_EMUSTATE g_EmulatorState = PLUGIN_EMUSTATE_STOP;
// Standard crap to make wxWidgets happy
#ifdef _WIN32
HINSTANCE g_hInstance;
@ -185,6 +187,8 @@ void DllConfig(HWND _hParent)
m_BasicConfigFrame = new WiimoteBasicConfigDialog(GetParentedWxWindow(_hParent));
else if (!m_BasicConfigFrame->GetParent()->IsShown())
m_BasicConfigFrame->Close(true);
// Update the GUI (because it was not updated when it had been already open before...)
m_BasicConfigFrame->UpdateGUI();
// Only allow one open at a time
if (!m_BasicConfigFrame->IsShown())
{
@ -294,7 +298,10 @@ void DoState(unsigned char **ptr, int mode)
return;
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
g_EmulatorState = newState;
}
/* This function produce Wiimote Input (reports from the Wiimote) in response
to Output from the Wii. It's called from WII_IPC_HLE_WiiMote.cpp.

View File

@ -22,6 +22,7 @@
#include <vector>
#include "CommonTypes.h"
#include "pluginspecs_wiimote.h"
#if defined(HAVE_X11) && HAVE_X11
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@ -89,6 +90,9 @@ struct SRecordingAll
// Movement recording
extern std::vector<SRecordingAll> VRecording;
extern PLUGIN_EMUSTATE g_EmulatorState;
#endif

View File

@ -315,7 +315,7 @@ int Initialize()
g_RealWiiMotePresent = false;
g_RealWiiMoteAllocated = false;
if(g_Config.bConnectRealWiimote)
if (g_Config.bConnectRealWiimote)
{
// Call Wiiuse.dll
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
@ -356,7 +356,7 @@ int Initialize()
#endif
// If we are connecting from the config window without a game running we set the LEDs
if (!g_EmulatorRunning && g_RealWiiMotePresent)
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY && g_RealWiiMotePresent)
FlashLights(true);
// Create a new thread and start listening for Wiimote data
@ -389,7 +389,7 @@ int Initialize()
// Allocate each Real WiiMote found to a WiiMote slot with Source set to "WiiMote Real"
void Allocate()
{
if(!g_RealWiiMoteInitialized)
if (!g_RealWiiMoteInitialized)
Initialize();
// Clear the wiimote classes
@ -419,9 +419,8 @@ void Allocate()
}
}
// If we found a valid slot for this WiiMote...
if(current_number < MAX_WIIMOTES)
if (current_number < MAX_WIIMOTES)
{
g_WiiMotes[current_number] = new CWiiMote(current_number, g_WiiMotesFromWiiUse[i]);
g_WiimoteInUse[current_number] = true;
switch (current_number)
@ -490,7 +489,7 @@ void Shutdown(void)
}
// Flash flights
if (!g_EmulatorRunning && g_RealWiiMotePresent)
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY && g_RealWiiMotePresent)
FlashLights(false);
// Clean up wiiuse

View File

@ -294,6 +294,9 @@ void DoState(unsigned char **ptr, int mode)
#endif
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
// Set PAD status
// --------------