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

View File

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