nJoy and PluginManager:

1. Avoided LoadLibrary() and FreeLibrary() in favor of using an existing LoadLibrary() because of an unresolved crash related to LoadLibrary() and nJoy. After several times of LoadLibrary() and FreeLibrary() of nJoy these seems to be some kind of memory corruption that brings up several error boxes from different places (not just nJoy) and then cause a crash.

2. Slowed down the moving of the pad initialization to InputCommon. I'm not against InputCommon at all, but I have to spend some more time with it before it works on Windows

3. Partly fixed a somewhat frequent failure of nJoy with SDL 1.3 that would give a strange DirectInput error message and cause the pads to not function. It's still present before the nJoy config windows is opened. It's only fixed on booting a game.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1991 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-01-23 10:00:59 +00:00
parent d450e054a4
commit 63ad74f9e8
19 changed files with 485 additions and 290 deletions

View File

@ -37,8 +37,10 @@ CPlugin::~CPlugin()
CPlugin::CPlugin(const char* _szName) : valid(false) CPlugin::CPlugin(const char* _szName) : valid(false)
{ {
if (m_hInstLib.Load(_szName)) { if (m_hInstLib.Load(_szName))
{
// Create pointers to the DLL functions
m_GetDllInfo = reinterpret_cast<TGetDllInfo> m_GetDllInfo = reinterpret_cast<TGetDllInfo>
(m_hInstLib.Get("GetDllInfo")); (m_hInstLib.Get("GetDllInfo"));
m_DllConfig = reinterpret_cast<TDllConfig> m_DllConfig = reinterpret_cast<TDllConfig>
@ -56,24 +58,28 @@ CPlugin::CPlugin(const char* _szName) : valid(false)
} }
if (m_GetDllInfo != 0 && if (m_GetDllInfo != 0 &&
m_DllConfig != 0 && m_DllConfig != 0 &&
m_DllDebugger != 0 && m_DllDebugger != 0 &&
m_SetDllGlobals != 0 && m_SetDllGlobals != 0 &&
m_Initialize != 0 && m_Initialize != 0 &&
m_Shutdown != 0 && m_Shutdown != 0 &&
m_DoState != 0) m_DoState != 0)
valid = true; valid = true;
// Save the filename for this plugin
Filename = _szName;
} }
void *CPlugin::LoadSymbol(const char *sym) { void *CPlugin::LoadSymbol(const char *sym)
{
return m_hInstLib.Get(sym); return m_hInstLib.Get(sym);
} }
// ______________________________________________________________________________________ // ______________________________________________________________________________________
// GetInfo: Get DLL info // GetInfo: Get DLL info
bool CPlugin::GetInfo(PLUGIN_INFO& _pluginInfo) { bool CPlugin::GetInfo(PLUGIN_INFO& _pluginInfo)
{
if (m_GetDllInfo != 0) if (m_GetDllInfo != 0)
{ {
m_GetDllInfo(&_pluginInfo); m_GetDllInfo(&_pluginInfo);

View File

@ -36,35 +36,37 @@ class CPlugin
{ {
public: public:
CPlugin(const char* _szName); CPlugin(const char* _szName);
~CPlugin(); ~CPlugin();
virtual bool IsValid() {return valid;}; virtual bool IsValid() {return valid;};
virtual std::string GetFilename() {return Filename;};
bool GetInfo(PLUGIN_INFO& _pluginInfo); bool GetInfo(PLUGIN_INFO& _pluginInfo);
void SetGlobals(PLUGIN_GLOBALS* _PluginGlobals); void SetGlobals(PLUGIN_GLOBALS* _PluginGlobals);
void *LoadSymbol(const char *sym); void *LoadSymbol(const char *sym);
void Config(HWND _hwnd); void Config(HWND _hwnd);
void About(HWND _hwnd); void About(HWND _hwnd);
void Debug(HWND _hwnd, bool Show); void Debug(HWND _hwnd, bool Show);
void DoState(unsigned char **ptr, int mode); void DoState(unsigned char **ptr, int mode);
void Initialize(void *init); void Initialize(void *init);
void Shutdown(); void Shutdown();
private: private:
DynamicLibrary m_hInstLib; DynamicLibrary m_hInstLib;
bool valid; bool valid;
std::string Filename;
// Functions // Functions
TGetDllInfo m_GetDllInfo; TGetDllInfo m_GetDllInfo;
TDllConfig m_DllConfig; TDllConfig m_DllConfig;
TDllDebugger m_DllDebugger; TDllDebugger m_DllDebugger;
TSetDllGlobals m_SetDllGlobals; TSetDllGlobals m_SetDllGlobals;
TInitialize m_Initialize; TInitialize m_Initialize;
TShutdown m_Shutdown; TShutdown m_Shutdown;
TDoState m_DoState; TDoState m_DoState;
}; };
} // end of namespace Common } // end of namespace Common

View File

@ -4,25 +4,27 @@
#include "pluginspecs_pad.h" #include "pluginspecs_pad.h"
#include "Plugin.h" #include "Plugin.h"
namespace Common { namespace Common
{
typedef void (__cdecl* TPAD_GetStatus)(u8, SPADStatus*); typedef void (__cdecl* TPAD_GetStatus)(u8, SPADStatus*);
typedef void (__cdecl* TPAD_Input)(u16, u8); typedef void (__cdecl* TPAD_Input)(u16, u8);
typedef void (__cdecl* TPAD_Rumble)(u8, unsigned int, unsigned int); typedef void (__cdecl* TPAD_Rumble)(u8, unsigned int, unsigned int);
typedef unsigned int (__cdecl* TPAD_GetAttachedPads)(); typedef unsigned int (__cdecl* TPAD_GetAttachedPads)();
class PluginPAD : public CPlugin { class PluginPAD : public CPlugin
{
public: public:
PluginPAD(const char *_Filename); PluginPAD(const char *_Filename);
~PluginPAD(); ~PluginPAD();
virtual bool IsValid() {return validPAD;}; virtual bool IsValid() {return validPAD;};
TPAD_GetStatus PAD_GetStatus; TPAD_GetStatus PAD_GetStatus;
TPAD_Input PAD_Input; TPAD_Input PAD_Input;
TPAD_Rumble PAD_Rumble; TPAD_Rumble PAD_Rumble;
TPAD_GetAttachedPads PAD_GetAttachedPads; TPAD_GetAttachedPads PAD_GetAttachedPads;
private: private:
bool validPAD; bool validPAD;
}; };
} }

View File

@ -1,7 +1,11 @@
#include "PluginVideo.h" #include "PluginVideo.h"
namespace Common { namespace Common
PluginVideo::PluginVideo(const char *_Filename) : CPlugin(_Filename), validVideo(false) { {
PluginVideo::PluginVideo(const char *_Filename) :
CPlugin(_Filename),
validVideo(false)
{
Video_Prepare = reinterpret_cast<TVideo_Prepare> Video_Prepare = reinterpret_cast<TVideo_Prepare>
(LoadSymbol("Video_Prepare")); (LoadSymbol("Video_Prepare"));

View File

@ -13,22 +13,23 @@ namespace Common {
typedef void (__cdecl* TVideo_AddMessage)(const char* pstr, unsigned int milliseconds); typedef void (__cdecl* TVideo_AddMessage)(const char* pstr, unsigned int milliseconds);
typedef void (__cdecl* TVideo_Stop)(); typedef void (__cdecl* TVideo_Stop)();
class PluginVideo : public CPlugin { class PluginVideo : public CPlugin
public: {
PluginVideo(const char *_Filename); public:
~PluginVideo(); PluginVideo(const char *_Filename);
virtual bool IsValid() {return validVideo;}; ~PluginVideo();
virtual bool IsValid() {return validVideo;};
TVideo_Prepare Video_Prepare; TVideo_Prepare Video_Prepare;
TVideo_SendFifoData Video_SendFifoData; TVideo_SendFifoData Video_SendFifoData;
TVideo_UpdateXFB Video_UpdateXFB; TVideo_UpdateXFB Video_UpdateXFB;
TVideo_Screenshot Video_Screenshot; TVideo_Screenshot Video_Screenshot;
TVideo_EnterLoop Video_EnterLoop; TVideo_EnterLoop Video_EnterLoop;
TVideo_AddMessage Video_AddMessage; TVideo_AddMessage Video_AddMessage;
TVideo_Stop Video_Stop; TVideo_Stop Video_Stop;
private: private:
bool validVideo; bool validVideo;
}; };
} }

View File

@ -191,7 +191,7 @@
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="true" OmitFramePointers="true"
EnableFiberSafeOptimizations="false" EnableFiberSafeOptimizations="false"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib" AdditionalIncludeDirectories="..\..\..\Externals\SDL\Include;.\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0" PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true" StringPooling="true"
RuntimeLibrary="0" RuntimeLibrary="0"

View File

@ -155,8 +155,6 @@ bool GetRealWiimote()
// ----------------- // -----------------
bool Init() bool Init()
{ {
//Console::Open();
if (g_pThread != NULL) if (g_pThread != NULL)
{ {
PanicAlert("ERROR: Emu Thread already running. Report this bug."); PanicAlert("ERROR: Emu Thread already running. Report this bug.");
@ -347,7 +345,18 @@ THREAD_RETURN EmuThread(void *pArg)
PADInitialize.pLog = Callback_PADLog; PADInitialize.pLog = Callback_PADLog;
PADInitialize.padNumber = i; PADInitialize.padNumber = i;
// Check if we should init the plugin // Check if we should init the plugin
Plugins.GetPAD(i)->Initialize((void *)&PADInitialize); if(Plugins.OkayToInitPlugin(i))
{
Plugins.GetPad(i)->Initialize(&PADInitialize);
// Check if joypad open failed, in that case try again
if(PADInitialize.padNumber == -1)
{
Plugins.GetPad(i)->Shutdown();
Plugins.FreePad();
Plugins.GetPad(i)->Initialize(&PADInitialize);
}
}
} }
// Load and Init WiimotePlugin - only if we are booting in wii mode // Load and Init WiimotePlugin - only if we are booting in wii mode

View File

@ -254,9 +254,8 @@ void Init()
g_Channel[i].m_InHi.Hex = 0; g_Channel[i].m_InHi.Hex = 0;
g_Channel[i].m_InLo.Hex = 0; g_Channel[i].m_InLo.Hex = 0;
// Access the pad and check the MAXPADS limit // Access the pap
Common::PluginPAD* pad = CPluginManager::GetInstance().GetPAD((i >= MAXPADS) ? (MAXPADS - 1): i); Common::PluginPAD* pad = CPluginManager::GetInstance().GetPad(i);
//Common::PluginPAD* pad = CPluginManager::GetInstance().GetPAD(i);
// Check if this pad is attached for the current plugin // Check if this pad is attached for the current plugin
if (pad != NULL && (pad->PAD_GetAttachedPads() & (1 << i))) if (pad != NULL && (pad->PAD_GetAttachedPads() & (1 << i)))

View File

@ -120,8 +120,7 @@ CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
SPADStatus PadStatus; SPADStatus PadStatus;
memset(&PadStatus, 0 ,sizeof(PadStatus)); memset(&PadStatus, 0 ,sizeof(PadStatus));
Common::PluginPAD* pad = Common::PluginPAD* pad =
//CPluginManager::GetInstance().GetPAD(ISIDevice::m_iDeviceNumber); CPluginManager::GetInstance().GetPad(ISIDevice::m_iDeviceNumber);
CPluginManager::GetInstance().GetPAD((ISIDevice::m_iDeviceNumber >= MAXPADS) ? (MAXPADS - 1): ISIDevice::m_iDeviceNumber);
pad->PAD_GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus); pad->PAD_GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
_Hi = (u32)((u8)PadStatus.stickY); _Hi = (u32)((u8)PadStatus.stickY);
@ -148,7 +147,7 @@ CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
void void
CSIDevice_GCController::SendCommand(u32 _Cmd) CSIDevice_GCController::SendCommand(u32 _Cmd)
{ {
Common::PluginPAD* pad = CPluginManager::GetInstance().GetPAD(0); Common::PluginPAD* pad = CPluginManager::GetInstance().GetPad(0);
UCommand command(_Cmd); UCommand command(_Cmd);
switch(command.Command) switch(command.Command)

View File

@ -15,20 +15,31 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <string>
//////////////////////////////////////////////////////////////////////////////////////////
// Include
// ¯¯¯¯¯¯¯¯¯¯¯¯
#include <string> // System
#include <vector> #include <vector>
//#include "Globals.h" //#include "Globals.h" // Local
#include "FileSearch.h"
#include "FileUtil.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "ConfigManager.h" #include "ConfigManager.h"
#include "LogManager.h" #include "LogManager.h"
#include "Core.h"
#include "FileSearch.h" // Common
#include "FileUtil.h"
#include "StringUtil.h" #include "StringUtil.h"
#include "ConsoleWindow.h"
CPluginManager CPluginManager::m_Instance; CPluginManager CPluginManager::m_Instance;
//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// The Plugin Manager Class
// ¯¯¯¯¯¯¯¯¯¯¯¯
CPluginManager::CPluginManager() : CPluginManager::CPluginManager() :
m_params(SConfig::GetInstance().m_LocalCoreStartupParameter) m_params(SConfig::GetInstance().m_LocalCoreStartupParameter)
{ {
@ -37,113 +48,189 @@ CPluginManager::CPluginManager() :
m_PluginGlobals->config = (void *)&SConfig::GetInstance(); m_PluginGlobals->config = (void *)&SConfig::GetInstance();
m_PluginGlobals->messageLogger = NULL; m_PluginGlobals->messageLogger = NULL;
m_InputManager = new InputManager();
m_PluginGlobals->inputManager = m_InputManager;
} }
// Function: FreeLibrary()
// Called from: This will be called when Dolphin is closed, not when we Stop a game
CPluginManager::~CPluginManager() CPluginManager::~CPluginManager()
{ {
if (m_PluginGlobals) Console::Print("Delete CPluginManager\n");
delete m_PluginGlobals;
ShutdownPlugins(); if (m_PluginGlobals) delete m_PluginGlobals;
delete m_InputManager; if (m_dsp) delete m_dsp;
if (m_video) delete m_video;
/**/
for (int i = 0; i < MAXPADS; i++)
{
if (m_pad[i] && OkayToInitPlugin(i))
{
Console::Print("Delete: %i\n", i);
delete m_pad[i];
}
m_pad[i] = NULL;
}
for (int i = 0; i < MAXWIIMOTES; i++)
if (m_wiimote[i]) delete m_wiimote[i];
} }
//////////////////////////////////////////////
bool CPluginManager::InitPlugins() {
if (! GetVideo()) { //////////////////////////////////////////////////////////////////////////////////////////
PanicAlert("Can't init Video Plugin"); // Init and ShutDown Plugins
return false; // ¯¯¯¯¯¯¯¯¯¯¯¯
// Point the m_pad[] and other variables to a certain plugin
bool CPluginManager::InitPlugins()
{
if (! GetVideo())
{
PanicAlert("Can't init Video Plugin");
return false;
} }
if (! GetDSP()) { if (! GetDSP())
PanicAlert("Can't init DSP Plugin"); {
return false; PanicAlert("Can't init DSP Plugin");
} return false;
if (! m_InputManager->Init()) {
PanicAlert("Can't init input manager");
return false;
} }
// Check if we get at least one pad or wiimote
bool pad = false; bool pad = false;
bool wiimote = false; bool wiimote = false;
// Init pad
for (int i = 0; i < MAXPADS; i++) for (int i = 0; i < MAXPADS; i++)
{ {
if (! m_params.m_strPadPlugin[i].empty()) if (! m_params.m_strPadPlugin[i].empty())
GetPAD(i); GetPad(i);
if (m_pad[i] != NULL)
if (m_pad[i] != NULL) pad = true;
pad = true;
} }
if (! pad)
if (! pad) {
PanicAlert("Can't init any PAD Plugins");
return false;
}
if (m_params.bWii) {
for (int i = 0; i < MAXWIIMOTES; i++)
{ {
if (! m_params.m_strWiimotePlugin[i].empty()) PanicAlert("Can't init any PAD Plugins");
GetWiimote(i); return false;
}
if (m_wiimote[i] != NULL) // Init wiimote
wiimote = true; if (m_params.bWii)
} {
for (int i = 0; i < MAXWIIMOTES; i++)
{
if (! m_params.m_strWiimotePlugin[i].empty())
GetWiimote(i);
if (! wiimote) { if (m_wiimote[i] != NULL)
PanicAlert("Can't init any Wiimote Plugins"); wiimote = true;
return false; }
} if (! wiimote)
{
PanicAlert("Can't init any Wiimote Plugins");
return false;
}
} }
return true; return true;
} }
void CPluginManager::ShutdownPlugins() void CPluginManager::ShutdownPlugins()
{ {
for (int i = 0; i < MAXPADS; i++) { // Check if we can shutdown the plugin
if (m_pad[i]) { for (int i = 0; i < MAXPADS; i++)
m_pad[i]->Shutdown(); {
delete m_pad[i]; if (m_pad[i] && OkayToInitPlugin(i))
m_pad[i] = NULL; {
//Console::Print("Shutdown: %i\n", i);
m_pad[i]->Shutdown();
//delete m_pad[i];
}
//m_pad[i] = NULL;
} }
for (int i = 0; i < MAXWIIMOTES; i++)
if (m_wiimote[i]) m_wiimote[i]->Shutdown();
if (m_video)
m_video->Shutdown();
if (m_dsp)
m_dsp->Shutdown();
}
//////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// Supporting functions
// ¯¯¯¯¯¯¯¯¯¯¯¯
// Called from: Get__() functions in this file only (not from anywhere else)
void *CPluginManager::LoadPlugin(const char *_rFilename, int Number)//, PLUGIN_TYPE type)
{
CPluginInfo info(_rFilename);
PLUGIN_TYPE type = info.GetPluginInfo().Type;
//std::string Filename = info.GetPluginInfo().Filename;
std::string Filename = _rFilename;
Common::CPlugin *plugin = NULL;
switch (type)
{
case PLUGIN_TYPE_VIDEO:
plugin = new Common::PluginVideo(_rFilename);
break;
case PLUGIN_TYPE_DSP:
plugin = new Common::PluginDSP(_rFilename);
break;
case PLUGIN_TYPE_PAD:
plugin = new Common::PluginPAD(_rFilename);
break;
case PLUGIN_TYPE_WIIMOTE:
plugin = new Common::PluginWiimote(_rFilename);
break;
default:
PanicAlert("Trying to load unsupported type %d", type);
} }
if (! m_InputManager->Shutdown()) { if (!plugin->IsValid())
PanicAlert("Error cleaning after input manager"); {
} PanicAlert("Can't open %s", _rFilename);
return NULL;
for (int i = 0; i < MAXWIIMOTES; i++) { }
if (m_wiimote[i]) {
m_wiimote[i]->Shutdown(); plugin->SetGlobals(m_PluginGlobals);
delete m_wiimote[i]; return plugin;
m_wiimote[i] = NULL;
}
}
if (m_video) {
m_video->Shutdown();
delete m_video;
m_video = NULL;
}
if (m_dsp) {
m_dsp->Shutdown();
delete m_dsp;
m_dsp = NULL;
}
} }
PLUGIN_GLOBALS* CPluginManager::GetGlobals() { // ----------------------------------------
/* Check if the plugin has already been initialized. If so, return the Id of the duplicate pad
so we can point the new m_pad[] to that */
// -------------
int CPluginManager::OkayToInitPlugin(int Plugin)
{
// Compare it to the earlier plugins
for(int i = 0; i < Plugin; i++)
if (m_params.m_strPadPlugin[Plugin] == m_params.m_strPadPlugin[i])
return i;
// No there is no duplicate plugin
return -1;
}
PLUGIN_GLOBALS* CPluginManager::GetGlobals()
{
return m_PluginGlobals; return m_PluginGlobals;
} }
// ---------------------------------------- // ----------------------------------------
// Create list of available plugins // Create list of available plugins
// ------------- // -------------
@ -181,88 +268,102 @@ void CPluginManager::ScanForPlugins()
} }
} }
} }
/////////////////////////////////////////////////
Common::PluginPAD *CPluginManager::GetPAD(int controller)
//////////////////////////////////////////////////////////////////////////////////////////
/* Create or return the already created plugin pointers. This will be called often for the
Pad and Wiimote from the SI_.cpp files. */
// ¯¯¯¯¯¯¯¯¯¯¯¯
Common::PluginPAD *CPluginManager::GetPad(int controller)
{ {
if (m_pad[controller] == NULL) if (m_pad[controller] != NULL)
m_pad[controller] = (Common::PluginPAD*)LoadPlugin(m_params.m_strPadPlugin[controller].c_str()); if (m_pad[controller]->GetFilename() == m_params.m_strPadPlugin[controller])
return m_pad[controller];
return m_pad[controller];
// Else do this
if(OkayToInitPlugin(controller) == -1)
{
m_pad[controller] = (Common::PluginPAD*)LoadPlugin(m_params.m_strPadPlugin[controller].c_str(), controller);
Console::Print("LoadPlugin: %i\n", controller);
}
else
{
Console::Print("Pointed: %i to %i\n", controller, OkayToInitPlugin(controller));
m_pad[controller] = m_pad[OkayToInitPlugin(controller)];
}
return m_pad[controller];
} }
Common::PluginWiimote *CPluginManager::GetWiimote(int controller) Common::PluginWiimote *CPluginManager::GetWiimote(int controller)
{ {
if (m_wiimote[controller] == NULL) if (m_pad[controller] != NULL)
m_wiimote[controller] = (Common::PluginWiimote*)LoadPlugin if (m_wiimote[controller]->GetFilename() == m_params.m_strWiimotePlugin[controller])
(m_params.m_strWiimotePlugin[controller].c_str()); return m_wiimote[controller];
// Else load a new plugin
m_wiimote[controller] = (Common::PluginWiimote*)LoadPlugin(m_params.m_strWiimotePlugin[controller].c_str());
return m_wiimote[controller]; return m_wiimote[controller];
} }
Common::PluginDSP *CPluginManager::GetDSP() Common::PluginDSP *CPluginManager::GetDSP()
{ {
if (m_dsp == NULL) if (m_dsp != NULL)
if (m_dsp->GetFilename() == m_params.m_strDSPPlugin)
return m_dsp;
// Else load a new plugin
m_dsp = (Common::PluginDSP*)LoadPlugin(m_params.m_strDSPPlugin.c_str()); m_dsp = (Common::PluginDSP*)LoadPlugin(m_params.m_strDSPPlugin.c_str());
return m_dsp; return m_dsp;
} }
Common::PluginVideo *CPluginManager::GetVideo() { Common::PluginVideo *CPluginManager::GetVideo()
{
if (m_video != NULL)
if (m_video->GetFilename() == m_params.m_strVideoPlugin)
return m_video;
if (m_video == NULL) // Else load a new plugin
m_video = (Common::PluginVideo*)LoadPlugin(m_params.m_strVideoPlugin.c_str()); m_video = (Common::PluginVideo*)LoadPlugin(m_params.m_strVideoPlugin.c_str());
return m_video; return m_video;
} }
Common::PluginPAD *CPluginManager::FreePad()
void *CPluginManager::LoadPlugin(const char *_rFilename)//, PLUGIN_TYPE type)
{ {
CPluginInfo info(_rFilename); delete m_pad[0];
PLUGIN_TYPE type = info.GetPluginInfo().Type; m_pad[0] = NULL; m_pad[1] = NULL; m_pad[2] = NULL; m_pad[3] = NULL;
Common::CPlugin *plugin = NULL; m_pad[0] = (Common::PluginPAD*)LoadPlugin(m_params.m_strPadPlugin[0].c_str(), 0);
switch (type) { return m_pad[0];
case PLUGIN_TYPE_VIDEO:
plugin = new Common::PluginVideo(_rFilename);
break;
case PLUGIN_TYPE_PAD:
plugin = new Common::PluginPAD(_rFilename);
break;
case PLUGIN_TYPE_DSP:
plugin = new Common::PluginDSP(_rFilename);
break;
case PLUGIN_TYPE_WIIMOTE:
plugin = new Common::PluginWiimote(_rFilename);
break;
default:
PanicAlert("Trying to load unsupported type %d", type);
}
if (!plugin->IsValid()) {
PanicAlert("Can't open %s", _rFilename);
return NULL;
}
plugin->SetGlobals(m_PluginGlobals);
return plugin;
} }
///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// Call DLL functions
// ¯¯¯¯¯¯¯¯¯¯¯¯
// ---------------------------------------- // ----------------------------------------
// Open config window. _rFilename = plugin filename ,ret = the dll slot number // Open config window. Input: _rFilename = Plugin filename , Type = Plugin type
// ------------- // -------------
void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename) void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type)
{ {
//m_InputManager->Init();
Common::CPlugin *plugin = new Common::CPlugin(_rFilename); switch(Type)
m_InputManager->Init(); {
plugin->SetGlobals(m_PluginGlobals); case PLUGIN_TYPE_VIDEO:
plugin->Config((HWND)_Parent); GetVideo()->Config((HWND)_Parent);
delete plugin; break;
m_InputManager->Shutdown(); case PLUGIN_TYPE_DSP:
GetDSP()->Config((HWND)_Parent);
break;
case PLUGIN_TYPE_PAD:
GetPad(0)->Config((HWND)_Parent);
break;
case PLUGIN_TYPE_WIIMOTE:
GetWiimote(0)->Config((HWND)_Parent);
break;
}
//m_InputManager->Shutdown();
} }
// ---------------------------------------- // ----------------------------------------
@ -270,10 +371,14 @@ void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename)
// ------------- // -------------
void CPluginManager::OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show) void CPluginManager::OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show)
{ {
if (Type == PLUGIN_TYPE_VIDEO) { switch(Type)
GetVideo()->Debug((HWND)_Parent, Show); {
} else if (Type == PLUGIN_TYPE_DSP) { case PLUGIN_TYPE_VIDEO:
GetDSP()->Debug((HWND)_Parent, Show); GetVideo()->Debug((HWND)_Parent, Show);
break;
case PLUGIN_TYPE_DSP:
GetDSP()->Debug((HWND)_Parent, Show);
break;
} }
} }
@ -285,13 +390,15 @@ CPluginInfo::CPluginInfo(const char *_rFileName)
, m_Valid(false) , m_Valid(false)
{ {
Common::CPlugin *plugin = new Common::CPlugin(_rFileName); Common::CPlugin *plugin = new Common::CPlugin(_rFileName);
if (plugin->IsValid()) { if (plugin->IsValid())
if (plugin->GetInfo(m_PluginInfo)) {
m_Valid = true; if (plugin->GetInfo(m_PluginInfo))
else m_Valid = true;
PanicAlert("Could not get info about plugin %s", _rFileName); else
delete plugin; PanicAlert("Could not get info about plugin %s", _rFileName);
}
delete plugin;
}
} }
///////////////////////////////////////////

View File

@ -47,20 +47,23 @@ class CPluginManager
{ {
public: public:
static CPluginManager& GetInstance() {return(m_Instance);} static CPluginManager& GetInstance() {return(m_Instance);}
Common::PluginPAD *GetPAD(int controller); Common::PluginPAD *GetPad(int controller);
Common::PluginWiimote *GetWiimote(int controller); Common::PluginWiimote *GetWiimote(int controller);
Common::PluginDSP *GetDSP(); Common::PluginDSP *GetDSP();
Common::PluginVideo *GetVideo(); Common::PluginVideo *GetVideo();
Common::PluginPAD *FreePad();
bool InitPlugins(); bool InitPlugins();
void ShutdownPlugins(); void ShutdownPlugins();
int OkayToInitPlugin(int Plugin); int OkayToInitPlugin(int Plugin);
void ScanForPlugins(); void ScanForPlugins();
void OpenConfig(void* _Parent, const char *_rFilename); void OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type);
void OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show); void OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show);
const CPluginInfos& GetPluginInfos() {return(m_PluginInfos);} const CPluginInfos& GetPluginInfos() {return(m_PluginInfos);}
PLUGIN_GLOBALS* GetGlobals(); PLUGIN_GLOBALS* GetGlobals();
private: private:
static CPluginManager m_Instance; static CPluginManager m_Instance;
bool m_Initialized; bool m_Initialized;
@ -75,7 +78,7 @@ private:
SCoreStartupParameter& m_params; SCoreStartupParameter& m_params;
CPluginManager(); CPluginManager();
~CPluginManager(); ~CPluginManager();
void *LoadPlugin(const char *_rFilename); void *LoadPlugin(const char *_rFilename, int Number = 0);
}; };

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="DebuggerWX" Name="DebuggerWX"
ProjectGUID="{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}" ProjectGUID="{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}"
RootNamespace="DebuggerWX" RootNamespace="DebuggerWX"
@ -179,7 +179,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
WholeProgramOptimization="false" WholeProgramOptimization="false"
AdditionalIncludeDirectories="..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc" AdditionalIncludeDirectories="..\..\..\Externals\SDL\Include;..\Common\Src;..\Core\Src;..\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\wxWidgets\Include;..\..\..\Externals\wxWidgets\Include\msvc"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WXMSW__;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="0" RuntimeLibrary="0"
BufferSecurityCheck="false" BufferSecurityCheck="false"

View File

@ -22,6 +22,7 @@
#include <vector> #include <vector>
#include "Core.h" // Core #include "Core.h" // Core
#include "ConsoleWindow.h" // Core
#include "Globals.h" // Local #include "Globals.h" // Local
#include "ConfigMain.h" #include "ConfigMain.h"
@ -681,18 +682,23 @@ void CConfigMain::DVDRootChanged(wxFileDirPickerEvent& WXUNUSED (event))
{ {
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDVDRoot = DVDRoot->GetPath().ToAscii(); SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDVDRoot = DVDRoot->GetPath().ToAscii();
} }
// ==========================
// =======================================================
// Plugins settings
// -------------
// Update plugin filenames
void CConfigMain::OnSelectionChanged(wxCommandEvent& WXUNUSED (event)) void CConfigMain::OnSelectionChanged(wxCommandEvent& WXUNUSED (event))
{ {
GetFilename(GraphicSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin); GetFilename(GraphicSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin);
GetFilename(DSPSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin); GetFilename(DSPSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin);
for (int i = 0; i < MAXPADS; i++) for (int i = 0; i < MAXPADS; i++)
GetFilename(PADSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strPadPlugin[i]); GetFilename(PADSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strPadPlugin[i]);
for (int i = 0; i < MAXWIIMOTES; i++) for (int i = 0; i < MAXWIIMOTES; i++)
GetFilename(WiimoteSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin[i]); GetFilename(WiimoteSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin[i]);
} }
void CConfigMain::OnConfig(wxCommandEvent& event) void CConfigMain::OnConfig(wxCommandEvent& event)
@ -716,15 +722,25 @@ void CConfigMain::OnConfig(wxCommandEvent& event)
break; break;
} }
} }
// ==========================
void CConfigMain::CallConfig(wxChoice* _pChoice)
{
int Index = _pChoice->GetSelection();
Console::Print("CallConfig: %i\n", Index);
if (Index >= 0)
{
const CPluginInfo* pInfo = static_cast<CPluginInfo*>(_pChoice->GetClientData(Index));
if (pInfo != NULL)
CPluginManager::GetInstance().OpenConfig((HWND) this->GetHandle(), pInfo->GetFileName().c_str(), pInfo->GetPluginInfo().Type);
}
}
// =======================================================
// Plugins settings
// -------------
void CConfigMain::FillChoiceBox(wxChoice* _pChoice, int _PluginType, const std::string& _SelectFilename) void CConfigMain::FillChoiceBox(wxChoice* _pChoice, int _PluginType, const std::string& _SelectFilename)
{ {
Console::Print("FillChoiceBox\n");
_pChoice->Clear(); _pChoice->Clear();
int Index = -1; int Index = -1;
@ -750,31 +766,16 @@ void CConfigMain::FillChoiceBox(wxChoice* _pChoice, int _PluginType, const std::
_pChoice->Select(Index); _pChoice->Select(Index);
} }
void CConfigMain::CallConfig(wxChoice* _pChoice)
{
int Index = _pChoice->GetSelection();
if (Index >= 0)
{
const CPluginInfo* pInfo = static_cast<CPluginInfo*>(_pChoice->GetClientData(Index));
if (pInfo != NULL)
CPluginManager::GetInstance().OpenConfig((HWND) this->GetHandle(), pInfo->GetFileName().c_str());
}
}
bool CConfigMain::GetFilename(wxChoice* _pChoice, std::string& _rFilename) bool CConfigMain::GetFilename(wxChoice* _pChoice, std::string& _rFilename)
{ {
_rFilename.clear(); _rFilename.clear();
int Index = _pChoice->GetSelection(); int Index = _pChoice->GetSelection();
printf("%i\n", Index);
if (Index >= 0) if (Index >= 0)
{ {
const CPluginInfo* pInfo = static_cast<CPluginInfo*>(_pChoice->GetClientData(Index)); const CPluginInfo* pInfo = static_cast<CPluginInfo*>(_pChoice->GetClientData(Index));
_rFilename = pInfo->GetFileName(); _rFilename = pInfo->GetFileName();
printf("%s\n", _rFilename.c_str()); Console::Print("GetFilename: %i %s\n", Index, _rFilename.c_str());
return(true); return(true);
} }

View File

@ -435,7 +435,7 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
else else
{ {
if(Core::GetState() != Core::CORE_UNINITIALIZED) if(Core::GetState() != Core::CORE_UNINITIALIZED)
CPluginManager::GetInstance().GetPAD(0)->PAD_Input(event.GetKeyCode(), 1); // 1 = Down CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 1); // 1 = Down
event.Skip(); event.Skip();
} }
} }
@ -443,7 +443,7 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
void CFrame::OnKeyUp(wxKeyEvent& event) void CFrame::OnKeyUp(wxKeyEvent& event)
{ {
if(Core::GetState() != Core::CORE_UNINITIALIZED) if(Core::GetState() != Core::CORE_UNINITIALIZED)
CPluginManager::GetInstance().GetPAD(0)->PAD_Input(event.GetKeyCode(), 0); // 0 = Up CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 0); // 0 = Up
event.Skip(); event.Skip();
} }
@ -453,7 +453,7 @@ void CFrame::OnKeyUp(wxKeyEvent& event)
double GetDoubleTime() double GetDoubleTime()
{ {
wxDateTime datetime = wxDateTime::UNow(); // Get timestamp wxDateTime datetime = wxDateTime::UNow(); // Get timestamp
u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970(); // Get continous timestamp u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970(); // Get continuous timestamp
/* Remove a few years. We only really want enough seconds to make sure that we are /* Remove a few years. We only really want enough seconds to make sure that we are
detecting actual actions, perhaps 60 seconds is enough really, but I leave a detecting actual actions, perhaps 60 seconds is enough really, but I leave a

View File

@ -539,7 +539,8 @@ void CFrame::OnPluginGFX(wxCommandEvent& WXUNUSED (event))
{ {
CPluginManager::GetInstance().OpenConfig( CPluginManager::GetInstance().OpenConfig(
GetHandle(), GetHandle(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin.c_str() SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin.c_str(),
PLUGIN_TYPE_VIDEO
); );
} }
@ -548,7 +549,8 @@ void CFrame::OnPluginDSP(wxCommandEvent& WXUNUSED (event))
{ {
CPluginManager::GetInstance().OpenConfig( CPluginManager::GetInstance().OpenConfig(
GetHandle(), GetHandle(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin.c_str() SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin.c_str(),
PLUGIN_TYPE_DSP
); );
} }
@ -556,14 +558,16 @@ void CFrame::OnPluginPAD(wxCommandEvent& WXUNUSED (event))
{ {
CPluginManager::GetInstance().OpenConfig( CPluginManager::GetInstance().OpenConfig(
GetHandle(), GetHandle(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strPadPlugin[0].c_str() SConfig::GetInstance().m_LocalCoreStartupParameter.m_strPadPlugin[0].c_str(),
PLUGIN_TYPE_PAD
); );
} }
void CFrame::OnPluginWiimote(wxCommandEvent& WXUNUSED (event)) void CFrame::OnPluginWiimote(wxCommandEvent& WXUNUSED (event))
{ {
CPluginManager::GetInstance().OpenConfig( CPluginManager::GetInstance().OpenConfig(
GetHandle(), GetHandle(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin[0].c_str() SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin[0].c_str(),
PLUGIN_TYPE_WIIMOTE
); );
} }

View File

@ -175,7 +175,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="2" Optimization="2"
EnableIntrinsicFunctions="true" EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs;..\..\..\Externals\wxWidgets\include;..\..\..\Externals\wxWidgets\lib\vc_lib\msw;..\..\..\Externals\wxWidgets\include\msvc;&quot;$(SolutionDir)..\Externals\SDL\Include&quot;" AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs;..\..\..\Externals\wxWidgets\include;..\..\..\Externals\wxWidgets\lib\vc_lib\msw;..\..\..\Externals\wxWidgets\include\msvc;..\..\..\Externals\SDL\Include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
StringPooling="true" StringPooling="true"
RuntimeLibrary="0" RuntimeLibrary="0"

View File

@ -146,6 +146,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Main", "..\Branches\MusicMo
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Player", "..\Branches\MusicMod\Player\Player.vcproj", "{0B72B5D6-5D72-4391-84A7-9CCA5392668A}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Player", "..\Branches\MusicMod\Player\Player.vcproj", "{0B72B5D6-5D72-4391-84A7-9CCA5392668A}"
ProjectSection(ProjectDependencies) = postProject
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestPlayer", "..\Branches\MusicMod\TestPlayer\TestPlayer.vcproj", "{0D14F1E9-490B-4A2D-A4EF-0535E8B3C718}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestPlayer", "..\Branches\MusicMod\TestPlayer\TestPlayer.vcproj", "{0D14F1E9-490B-4A2D-A4EF-0535E8B3C718}"
EndProject EndProject

View File

@ -35,7 +35,7 @@ typedef struct
{ {
HWND hWnd; HWND hWnd;
TLog pLog; TLog pLog;
int padNumber; int padNumber;
} SPADInitialize; } SPADInitialize;
typedef struct typedef struct

View File

@ -181,11 +181,12 @@ void GetDllInfo(PLUGIN_INFO* _PluginInfo)
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) { void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
} }
// Call config dialog // Call config dialog
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void DllConfig(HWND _hParent) void DllConfig(HWND _hParent)
{ {
#ifdef _WIN32
// Start the pads so we can use them in the configuration and advanced controls // Start the pads so we can use them in the configuration and advanced controls
if(!emulator_running) if(!emulator_running)
{ {
@ -196,11 +197,32 @@ void DllConfig(HWND _hParent)
emulator_running = false; // Set it back to false emulator_running = false; // Set it back to false
} }
#if defined(HAVE_WX) && HAVE_WX g_Config.Load(); // Load settings
// We don't need a parent for this wxDialog
//wxWindow win;
//win.SetHWND(_hParent);
//ConfigBox frame(&win);
//win.SetHWND(0);
m_frame = new ConfigBox(NULL); m_frame = new ConfigBox(NULL);
m_frame->ShowModal(); m_frame->ShowModal();
#endif
#else
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
{
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
return;
}
g_Config.Load(); // load settings
#if defined(HAVE_WX) && HAVE_WX
ConfigBox frame(NULL);
frame.ShowModal();
#endif
#endif
} }
void DllDebugger(HWND _hParent, bool Show) { void DllDebugger(HWND _hParent, bool Show) {
@ -218,19 +240,30 @@ void Initialize(void *init)
{ {
// Debugging // Debugging
//Console::Open(); //Console::Open();
SPADInitialize *_PADInitialize = (SPADInitialize*)init;
//Console::Print("Initialize: %i\n", SDL_WasInit(0)); Console::Print("Initialize: %i, %i\n", _PADInitialize->padNumber, SDL_WasInit(0));
SPADInitialize _PADInitialize = *(SPADInitialize*)init;
emulator_running = true; emulator_running = true;
#ifdef _DEBUG #ifdef _DEBUG
DEBUG_INIT(); DEBUG_INIT();
#endif #endif
#ifdef _WIN32 /* SDL 1.3 use DirectInput instead of the old Microsoft Multimeda API, and with this we need
m_hWnd = (HWND)_PADInitialize.hWnd; the SDL_INIT_VIDEO flag to */
#endif if (!SDL_WasInit(0))
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{
#ifdef _WIN32
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
#else
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
#endif
return;
}
#ifdef _WIN32
m_hWnd = (HWND)_PADInitialize->hWnd;
#endif
Search_Devices(); // Populate joyinfo for all attached devices Search_Devices(); // Populate joyinfo for all attached devices
g_Config.Load(); // Load joystick mapping, PadMapping[].ID etc g_Config.Load(); // Load joystick mapping, PadMapping[].ID etc
if (PadMapping[0].enabled) if (PadMapping[0].enabled)
@ -241,6 +274,18 @@ void Initialize(void *init)
joystate[2].joy = SDL_JoystickOpen(PadMapping[2].ID); joystate[2].joy = SDL_JoystickOpen(PadMapping[2].ID);
if (PadMapping[3].enabled) if (PadMapping[3].enabled)
joystate[3].joy = SDL_JoystickOpen(PadMapping[3].ID); joystate[3].joy = SDL_JoystickOpen(PadMapping[3].ID);
//_PADInitialize->padNumber = 55;
/* Check if any of the pads failed to open. In Windows there is a strange "IDirectInputDevice2::
SetDataFormat() DirectX error -2147024809" after a few Open and Close */
if( (PadMapping[0].enabled && joystate[0].joy == NULL)
|| (PadMapping[1].enabled && joystate[1].joy == NULL)
|| (PadMapping[2].enabled && joystate[2].joy == NULL)
|| (PadMapping[3].enabled && joystate[3].joy == NULL))
{
_PADInitialize->padNumber = -1;
Console::Print("%s\n", SDL_GetError());
}
} }
@ -258,15 +303,22 @@ int Search_Devices()
if (joyinfo) if (joyinfo)
{ {
delete [] joyinfo; delete [] joyinfo;
joyinfo = new CONTROLLER_INFO [numjoy];
}
else
{
joyinfo = new CONTROLLER_INFO [numjoy];
} }
joyinfo = new CONTROLLER_INFO [numjoy];
// Warn the user if no PadMapping are detected // Warn the user if no PadMapping are detected
if (numjoy == 0) if (numjoy == 0)
{ {
PanicAlert("No Joystick detected!\n"); #ifdef _WIN32
return 0; //MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
#else
printf("No Joystick detected!\n");
#endif
return 0;
} }
#ifdef _DEBUG #ifdef _DEBUG
@ -309,35 +361,35 @@ int Search_Devices()
Called from: The Dolphin Core, ConfigBox::OnClose() */ Called from: The Dolphin Core, ConfigBox::OnClose() */
void Shutdown() void Shutdown()
{ {
//Console::Print("Shutdown: %i\n", SDL_WasInit(0)); Console::Print("Shutdown: %i\n", SDL_WasInit(0));
if (PadMapping[0].enabled && SDL_JoystickOpened(PadMapping[0].ID)) if (PadMapping[0].enabled && SDL_JoystickOpened(PadMapping[0].ID))
SDL_JoystickClose(joystate[0].joy); SDL_JoystickClose(joystate[0].joy);
if (PadMapping[1].enabled && SDL_JoystickOpened(PadMapping[1].ID)) if (PadMapping[1].enabled && SDL_JoystickOpened(PadMapping[1].ID))
SDL_JoystickClose(joystate[1].joy); SDL_JoystickClose(joystate[1].joy);
if (PadMapping[2].enabled && SDL_JoystickOpened(PadMapping[2].ID)) if (PadMapping[2].enabled && SDL_JoystickOpened(PadMapping[2].ID))
SDL_JoystickClose(joystate[2].joy); SDL_JoystickClose(joystate[2].joy);
if (PadMapping[3].enabled && SDL_JoystickOpened(PadMapping[3].ID)) if (PadMapping[3].enabled && SDL_JoystickOpened(PadMapping[3].ID))
SDL_JoystickClose(joystate[3].joy); SDL_JoystickClose(joystate[3].joy);
#ifdef _DEBUG SDL_Quit();
DEBUG_QUIT();
#endif #ifdef _DEBUG
DEBUG_QUIT();
if(joyinfo) { #endif
delete [] joyinfo; delete [] joyinfo;
joyinfo = NULL; joyinfo = NULL;
}
emulator_running = false;
emulator_running = false;
#ifdef _WIN32
#ifdef _WIN32 #ifdef USE_RUMBLE_DINPUT_HACK
#ifdef USE_RUMBLE_DINPUT_HACK FreeDirectInput();
FreeDirectInput(); #endif
#endif #elif defined(__linux__)
#elif defined(__linux__) close(fd);
close(fd); #endif
#endif
} }
@ -512,11 +564,14 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
Console::ClearScreen(); Console::ClearScreen();
Console::Print( Console::Print(
"Trigger type: %s Left:%04x Right:%04x Value:%i\n" "Trigger type: %s Left:%04x Right:%04x Value:%i\n"
"D-Pad type: %s L:%i R:%i U:%i D:%i", "D-Pad type: %s L:%i R:%i U:%i D:%i"
"Main stick x, y: %i %i",
(PadMapping[_numPAD].triggertype ? "CTL_TRIGGER_XINPUT" : "CTL_TRIGGER_SDL"), (PadMapping[_numPAD].triggertype ? "CTL_TRIGGER_XINPUT" : "CTL_TRIGGER_SDL"),
TriggerLeft, TriggerRight, TriggerValue, TriggerLeft, TriggerRight, TriggerValue,
(PadMapping[_numPAD].controllertype ? "CTL_DPAD_CUSTOM" : "CTL_DPAD_HAT"), (PadMapping[_numPAD].controllertype ? "CTL_DPAD_CUSTOM" : "CTL_DPAD_HAT"),
0, 0, 0, 0 0, 0, 0, 0,
main_stick_x, main_stick_y
);*/ );*/
} }
@ -731,7 +786,7 @@ void GetJoyState(int controller)
ReadButton(controller, CTL_START); ReadButton(controller, CTL_START);
// //
if (PadMapping[controller].halfpress < joyinfo[controller].NumButtons) if (PadMapping[controller].halfpress < Buttons)
joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].halfpress); joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, PadMapping[controller].halfpress);
// Check if we have an analog or digital joypad // Check if we have an analog or digital joypad