Make real wiimote speaker not cause massive input delays.

Fixes issue 5966.
This commit is contained in:
Jordan Woyak 2013-02-04 20:57:08 -06:00
parent 03d9cca2fe
commit d5ec631337
2 changed files with 13 additions and 15 deletions

View File

@ -181,23 +181,23 @@ bool Wiimote::Read()
bool Wiimote::Write() bool Wiimote::Write()
{ {
Report rpt; Report rpt;
bool audio_written = false;
if (m_audio_reports.Pop(rpt)) if (last_audio_report.GetTimeDifference() > 6 && m_audio_reports.Pop(rpt))
{ {
last_audio_report.Update();
IOWrite(rpt.first, rpt.second); IOWrite(rpt.first, rpt.second);
delete[] rpt.first; delete[] rpt.first;
audio_written = true; return true;
} }
else if (m_write_reports.Pop(rpt))
if (m_write_reports.Pop(rpt))
{ {
IOWrite(rpt.first, rpt.second); IOWrite(rpt.first, rpt.second);
delete[] rpt.first; delete[] rpt.first;
return true; return true;
} }
return audio_written; return false;
} }
// Returns the next report that should be sent // Returns the next report that should be sent
@ -319,14 +319,9 @@ void Wiimote::ThreadFunc()
while (Write()) {} while (Write()) {}
Common::SleepCurrentThread(1); Common::SleepCurrentThread(1);
#else #else
bool read = false; bool const did_something = Write() || Read();
while (Write() || (read = true, IsOpen() && Read())) if (!did_something)
{ Common::SleepCurrentThread(1);
if (m_audio_reports.Size() && !read)
Read();
Common::SleepCurrentThread(m_audio_reports.Size() ? 5 : 2);
read = false;
}
#endif #endif
} }
} }

View File

@ -25,6 +25,7 @@
#include "ChunkFile.h" #include "ChunkFile.h"
#include "Thread.h" #include "Thread.h"
#include "FifoQueue.h" #include "FifoQueue.h"
#include "Timer.h"
#include "../Wiimote.h" #include "../Wiimote.h"
#include "../WiimoteEmu/WiimoteEmu.h" #include "../WiimoteEmu/WiimoteEmu.h"
@ -103,6 +104,8 @@ private:
Common::FifoQueue<Report> m_read_reports; Common::FifoQueue<Report> m_read_reports;
Common::FifoQueue<Report> m_write_reports; Common::FifoQueue<Report> m_write_reports;
Common::FifoQueue<Report> m_audio_reports; Common::FifoQueue<Report> m_audio_reports;
Common::Timer last_audio_report;
}; };
extern std::mutex g_refresh_lock; extern std::mutex g_refresh_lock;