Implement Wii input recording.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7130 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
smelenchuk 2011-02-11 18:53:51 +00:00
parent e480ab2b10
commit ca78d3639b
3 changed files with 137 additions and 90 deletions

View File

@ -20,6 +20,8 @@ inline double round(double x) { return (x-floor(x))>0.5 ? ceil(x) : floor(x); }
#include "MatrixMath.h" #include "MatrixMath.h"
#include "../../OnFrame.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
@ -664,12 +666,21 @@ void Wiimote::Update()
u8 data[MAX_PAYLOAD]; u8 data[MAX_PAYLOAD];
memset(data, 0, sizeof(data)); memset(data, 0, sizeof(data));
data[0] = 0xA1;
data[1] = m_reporting_mode;
// figure out what data we need // figure out what data we need
s8 rptf_size = MAX_PAYLOAD;;
if (Frame::IsPlayingInput())
{
Frame::PlayWiimote(data, rptf_size);
}
else
{
const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE]; const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE];
s8 rptf_size = rptf.size; rptf_size = rptf.size;
data[0] = 0xA1;
data[1] = m_reporting_mode;
// core buttons // core buttons
if (rptf.core) if (rptf.core)
@ -769,6 +780,11 @@ void Wiimote::Update()
} }
g_refresh_critsec.Leave(); g_refresh_critsec.Leave();
} }
if (Frame::IsRecordingInput())
{
Frame::RecordWiimote(data, rptf_size);
}
}
// don't send a data report if auto reporting is off // don't send a data report if auto reporting is off
if (false == m_reporting_auto && data[2] >= WM_REPORT_CORE) if (false == m_reporting_auto && data[2] >= WM_REPORT_CORE)

View File

@ -217,6 +217,15 @@ void RecordInput(SPADStatus *PadStatus, int controllerID)
fwrite(&g_padState, sizeof(ControllerState), 1, g_recordfd); fwrite(&g_padState, sizeof(ControllerState), 1, g_recordfd);
} }
void RecordWiimote(u8 *data, s8 size)
{
if(!IsRecordingInput())
return;
fwrite(&size, 1, 1, g_recordfd);
fwrite(data, 1, size, g_recordfd);
}
bool PlayInput(const char *filename) bool PlayInput(const char *filename)
{ {
if(!filename || g_playMode != MODE_NONE || g_recordfd) if(!filename || g_playMode != MODE_NONE || g_recordfd)
@ -369,6 +378,26 @@ void PlayController(SPADStatus *PadStatus, int controllerID)
} }
} }
void PlayWiimote(u8 *data, s8 &size)
{
s8 count = 0;
if(!IsPlayingInput())
return;
fread(&count, 1, 1, g_recordfd);
size = (count > size) ? size : count;
fread(data, 1, size, g_recordfd);
// TODO: merge this with the above so that there's no duplicate code
if(feof(g_recordfd))
{
Core::DisplayMessage("Movie End", 2000);
// TODO: read-only mode
//EndPlayInput();
g_playMode = MODE_RECORDING;
}
}
void EndPlayInput() { void EndPlayInput() {
if (g_recordfd) if (g_recordfd)
fclose(g_recordfd); fclose(g_recordfd);

View File

@ -110,10 +110,12 @@ void FrameSkipping();
bool BeginRecordingInput(int controllers); bool BeginRecordingInput(int controllers);
void RecordInput(SPADStatus *PadStatus, int controllerID); void RecordInput(SPADStatus *PadStatus, int controllerID);
void RecordWiimote(u8* data, s8 size);
bool PlayInput(const char *filename); bool PlayInput(const char *filename);
void LoadInput(const char *filename); void LoadInput(const char *filename);
void PlayController(SPADStatus *PadStatus, int controllerID); void PlayController(SPADStatus *PadStatus, int controllerID);
void PlayWiimote(u8* data, s8 &size);
void EndPlayInput(); void EndPlayInput();
void SaveRecording(const char *filename); void SaveRecording(const char *filename);