From 05ef8231b83a7a1014b23c9400a93725cabb10d0 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 29 May 2010 10:09:24 +0000 Subject: [PATCH] Changed both video plugins to save PNG screenshots. Made GCPad New default in trunk (it already is in stable). Fixed a hack in new wiimote plugin. Other minor changes. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5532 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/CommonPaths.h | 2 +- Source/Core/Common/Src/LogManager.cpp | 3 +- Source/Core/Core/Src/Core.cpp | 6 +- .../DirectInput/DirectInputJoystick.cpp | 2 +- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 14 +++- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 2 +- Source/Plugins/Plugin_Wiimote/Src/main.cpp | 6 +- .../Src/WiimoteEmu/EmuSubroutines.cpp | 22 ++++-- .../Src/WiimoteEmu/Speaker.cpp | 78 +++++++++---------- .../Src/WiimoteEmu/WiimoteEmu.cpp | 19 ++--- .../Src/WiimoteEmu/WiimoteEmu.h | 22 ++++-- .../Plugin_WiimoteNew/Src/WiimoteNew.cpp | 13 ++-- 12 files changed, 107 insertions(+), 82 deletions(-) diff --git a/Source/Core/Common/Src/CommonPaths.h b/Source/Core/Common/Src/CommonPaths.h index 9a65a3a4df..1a3b5168d1 100644 --- a/Source/Core/Common/Src/CommonPaths.h +++ b/Source/Core/Common/Src/CommonPaths.h @@ -132,7 +132,7 @@ // Plugin files #define DEFAULT_GFX_PLUGIN PLUGIN_PREFIX "Plugin_VideoOGL" PLUGIN_SUFFIX #define DEFAULT_DSP_PLUGIN PLUGIN_PREFIX "Plugin_DSP_HLE" PLUGIN_SUFFIX -#define DEFAULT_PAD_PLUGIN PLUGIN_PREFIX "Plugin_GCPad" PLUGIN_SUFFIX +#define DEFAULT_PAD_PLUGIN PLUGIN_PREFIX "Plugin_GCPadNew" PLUGIN_SUFFIX #define DEFAULT_WIIMOTE_PLUGIN PLUGIN_PREFIX "Plugin_Wiimote" PLUGIN_SUFFIX // Sys files diff --git a/Source/Core/Common/Src/LogManager.cpp b/Source/Core/Common/Src/LogManager.cpp index 559de0b7f5..d60dda56e4 100644 --- a/Source/Core/Common/Src/LogManager.cpp +++ b/Source/Core/Common/Src/LogManager.cpp @@ -168,8 +168,7 @@ void LogContainer::removeListener(LogListener *listener) { } bool LogContainer::isListener(LogListener *listener) const { - std::vector::const_iterator i = std::find(listeners.begin(), listeners.end(), listener); - return listeners.end() != i; + return listeners.end() != std::find(listeners.begin(), listeners.end(), listener); } void LogContainer::trigger(LogTypes::LOG_LEVELS level, const char *msg) { diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index 1a4497db25..5713cb88d0 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -581,9 +581,9 @@ static inline std::string GenerateScreenshotName() //append gameId, tempname only contains the folder here. tempname += gameId; - name = StringFromFormat("%s-%d.bmp", tempname.c_str(), index); - while(File::Exists(name.c_str())) - name = StringFromFormat("%s-%d.bmp", tempname.c_str(), ++index); + do + name = StringFromFormat("%s-%d.png", tempname.c_str(), index++); + while (File::Exists(name.c_str())); return name; } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp index 2b6bf6bb76..7731577629 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DirectInput/DirectInputJoystick.cpp @@ -6,7 +6,7 @@ inline bool operator<(const GUID & lhs, const GUID & rhs) { - return memcmp(&lhs, &rhs, sizeof(GUID)) < 0 ? true : false; + return memcmp(&lhs, &rhs, sizeof(GUID)) < 0; } namespace ciface diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index a8e23d516c..5745694a6a 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -1133,7 +1133,19 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) if(s_bScreenshot) { s_criticalScreenshot.Enter(); - D3DXSaveSurfaceToFileA(s_sScreenshotName, D3DXIFF_BMP, D3D::GetBackBufferSurface(), NULL, NULL); + + // create a R8G8B8 surface for the screenshot (no alpha channel) + // otherwise funky screenshots get saved + LPDIRECT3DSURFACE9 screenshot_surface; + if (D3D_OK == D3D::dev->CreateOffscreenPlainSurface(s_backbuffer_width, s_backbuffer_height, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &screenshot_surface, NULL)) + { + D3DXLoadSurfaceFromSurface(screenshot_surface, NULL, NULL, D3D::GetBackBufferSurface(), NULL, NULL, D3DX_DEFAULT, 0); + D3DXSaveSurfaceToFileA(s_sScreenshotName, D3DXIFF_PNG, screenshot_surface, NULL, NULL); + screenshot_surface->Release(); + } + else + PanicAlert("Failed to create surface for screenshot!"); + s_bScreenshot = false; s_criticalScreenshot.Leave(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 3c25772ac9..846eba1c56 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -1458,7 +1458,7 @@ THREAD_RETURN TakeScreenshot(void *pArgs) // Save the screenshot and finally kill the wxImage object // This is really expensive when saving to PNG, but not at all when using BMP - threadStruct->img->SaveFile(wxString::FromAscii(threadStruct->filename.c_str()), wxBITMAP_TYPE_BMP); + threadStruct->img->SaveFile(wxString::FromAscii(threadStruct->filename.c_str()), wxBITMAP_TYPE_PNG); threadStruct->img->Destroy(); // Show success messages diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp index 8d6ce2cdc2..c8f3c6ef60 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp @@ -400,7 +400,11 @@ void Wiimote_Update(int _number) unsigned int Wiimote_GetAttachedControllers() { - return 1; + unsigned int attached = 0; + for (unsigned int i=0; i<4; ++i) + if (WiiMoteEmu::WiiMapping[i].Source) + attached |= (1 << i); + return attached; } diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp index bb143008b4..3aa672b772 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp @@ -65,10 +65,8 @@ void Wiimote::ReportMode(const u16 _channelID, wm_report_mode* dr) m_reporting_mode = dr->mode; m_reporting_channel = _channelID; - // some hax to skip a few Update() cycles to fix a nunchuk prob in ztp and wii sports - // skipping 10 seems to work - // probably like 1/6th of a second that the user won't have control :/ - m_skip_update = 10; + // reset IR camera + memset(m_reg_ir, 0, sizeof(*m_reg_ir)); if (0 == dr->all_the_time) PanicAlert("Wiimote: Reporting Always is set to OFF! Everything should be fine, but games never do this."); @@ -154,8 +152,8 @@ void Wiimote::HidOutputReport(const u16 _channelID, wm_report* sr) //PanicAlert( "WM Speaker Mute: %d", sr->data[0] & 0x04 ); #ifdef USE_WIIMOTE_EMU_SPEAKER // testing - if (sr->data[0] ^ 0x04) - m_channel_status.step = 0; + if (sr->data[0] & 0x04) + memset(&m_channel_status, 0, sizeof(m_channel_status)); #endif m_speaker_mute = (sr->data[0] & 0x04) ? 1 : 0; break; @@ -418,6 +416,7 @@ void Wiimote::ReadData(const u16 _channelID, wm_read_data* rd) // want the requested address, not the above modified one rr.address = convert24bit(rd->address); rr.size = size; + //rr.channel = _channelID; rr.position = 0; rr.data = block; @@ -490,4 +489,15 @@ void Wiimote::SendReadDataReply(const u16 _channelID, ReadRequest& _request) g_WiimoteInitialize.pWiimoteInput(m_index, _channelID, data, sizeof(data)); } +void Wiimote::DoState(PointerWrap& p) +{ + // not working :( + //if (p.MODE_READ == p.GetMode()) + //{ + // // LOAD + // Reset(); // should cause a status report to be sent, then wii should re-setup wiimote + //} + //p.Do(m_reporting_channel); +} + } diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/Speaker.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/Speaker.cpp index 2296a0482a..4d8b07aa72 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/Speaker.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/Speaker.cpp @@ -1,39 +1,39 @@ - -#include "WiimoteEmu.h" - -#ifdef USE_WIIMOTE_EMU_SPEAKER - -namespace WiimoteEmu -{ - -void Wiimote::SpeakerData(wm_speaker_data* sd) -{ - SoundBuffer sb; - sb.samples = new s16[sd->length * 2]; - - s16* s = sb.samples; - const u8* const e = sd->data + sd->length; - for ( const u8* i = sd->data; i> 4 ); - } - - alGenBuffers(1, &sb.buffer); - // TODO make this not always 3000 - alBufferData(sb.buffer, AL_FORMAT_MONO16, sb.samples, (sd->length * sizeof(short) * 2), 3360); - // testing - //alBufferData(sb.buffer, AL_FORMAT_MONO16, sb.samples, (sd->length * sizeof(short) * 2), 48000/m_reg_speaker->sample_rate); - alSourceQueueBuffers(m_audio_source, 1, &sb.buffer); - - ALint state; - alGetSourcei(m_audio_source, AL_SOURCE_STATE, &state); - if (AL_PLAYING != state) - alSourcePlay(m_audio_source); - - m_audio_buffers.push(sb); -} - -} - -#endif + +#include "WiimoteEmu.h" + +#ifdef USE_WIIMOTE_EMU_SPEAKER + +namespace WiimoteEmu +{ + +void Wiimote::SpeakerData(wm_speaker_data* sd) +{ + SoundBuffer sb; + sb.samples = new s16[sd->length * 2]; + + s16* s = sb.samples; + const u8* const e = sd->data + sd->length; + for ( const u8* i = sd->data; idata[0] & 0x0F, &m_channel_status.hist1p, &m_channel_status.hist2p); + *s++ = NGCADPCM::ADPDecodeSample(*i >> 4, sd->data[0] >> 4, &m_channel_status.hist1p, &m_channel_status.hist2p); + } + + alGenBuffers(1, &sb.buffer); + // TODO make this not always 3000 + alBufferData(sb.buffer, AL_FORMAT_MONO16, sb.samples, (sd->length * sizeof(short) * 2), 3360); + // testing + //alBufferData(sb.buffer, AL_FORMAT_MONO16, sb.samples, (sd->length * sizeof(short) * 2), 48000/m_reg_speaker->sample_rate); + alSourceQueueBuffers(m_audio_source, 1, &sb.buffer); + + ALint state; + alGetSourcei(m_audio_source, AL_SOURCE_STATE, &state); + if (AL_PLAYING != state) + alSourcePlay(m_audio_source); + + m_audio_buffers.push(sb); +} + +} + +#endif \ No newline at end of file diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp index c76764167a..e682d9c870 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp @@ -208,9 +208,6 @@ void Wiimote::Reset() m_rumble_on = false; m_speaker_mute = false; - // used for some hax in Update() - m_skip_update = 0; - // will make the first Update() call send a status request // the first call to RequestStatus() will then set up the status struct extension bit m_extension->active_extension = -1; @@ -393,7 +390,7 @@ void Wiimote::Update() } // check if there is a read data request - if ( m_read_requests.size() ) + if (m_read_requests.size()) { ReadRequest& rr = m_read_requests.front(); // send up to 16 bytes to the wii @@ -428,15 +425,6 @@ void Wiimote::Update() if (false == m_reporting_auto) return; - // Some hax to skip a few update cycles after a change in reporting mode - // It fixes the nunchuk prob in ztp and wii sports. I have no idea why - // maybe its an m_reporting_channel problem? - if (m_skip_update) - { - --m_skip_update; - return; - } - // figure out what data we need const ReportFeatures& rpt = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE]; @@ -512,7 +500,10 @@ void Wiimote::Update() } // ----ir---- - if (rpt.ir) + // only if camera is fully enabled. + // should send 0xFF if camera isn't enabled maybe, + // 0x00 is working fine though + if (rpt.ir && 0x08 == m_reg_ir->data[0x30]) { float xx = 10000, yy = 0, zz = 0; diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h index ab6354dfce..740d6d60dc 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h @@ -3,10 +3,13 @@ //#define USE_WIIMOTE_EMU_SPEAKER +//#include +//#include // just used to get the OpenAL includes :p //#include #include +#include "ChunkFile.h" #include "WiimoteHid.h" #include "Encryption.h" @@ -47,9 +50,12 @@ public: void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size); void ControlChannel(const u16 _channelID, const void* _pData, u32 _Size); + void DoState(PointerWrap& p); + private: struct ReadRequest { + //u16 channel; unsigned int address, size, position; u8* data; }; @@ -86,12 +92,9 @@ private: bool m_rumble_on; bool m_speaker_mute; - bool m_reporting_auto; - unsigned int m_reporting_mode; - unsigned int m_reporting_channel; - - // hax - unsigned int m_skip_update; + bool m_reporting_auto; + u8 m_reporting_mode; + u16 m_reporting_channel; unsigned int m_shake_step[3]; unsigned int m_swing_step[3]; @@ -120,7 +123,10 @@ private: }; std::queue m_audio_buffers; ALuint m_audio_source; - ADPCMChannelStatus m_channel_status; + struct + { + int hist1p, hist2p; + } m_channel_status; #endif u8 m_eeprom[WIIMOTE_EEPROM_SIZE]; @@ -129,7 +135,7 @@ private: struct IrReg { - u8 unknown1[0x33]; + u8 data[0x33]; u8 mode; } *m_reg_ir; diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp index b23b2fa038..3776656115 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp @@ -191,10 +191,11 @@ void Wiimote_Update(int _number) // unsigned int Wiimote_GetAttachedControllers() { - //PanicAlert( "Wiimote_GetAttachedControllers" ); - // temporary - //return 0x0F; - return 1; + unsigned int attached = 0; + for (unsigned int i=0; i<4; ++i) + if (g_plugin.controllers[i]->default_device.ToString().length()) + attached |= (1 << i); + return attached; } // GLOBAL I N T E R F A C E @@ -325,7 +326,9 @@ void Shutdown(void) // void DoState(unsigned char **ptr, int mode) { - // do this later + PointerWrap p(ptr, mode); + for (unsigned int i=0; i<4; ++i) + ((WiimoteEmu::Wiimote*)g_plugin.controllers[i])->DoState(p); } // ___________________________________________________________________________