Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[NetPlay] Allow recording movies during netplay.
Fixes issue 6207.
  • Loading branch information
RachelBryk committed Sep 3, 2013
1 parent 7e1959a commit 8ae10b3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Source/Core/Core/Src/HW/SI.cpp
Expand Up @@ -644,7 +644,10 @@ int GetTicksToNextSIPoll()
// Poll for input at regular intervals (once per frame) when playing or recording a movie
if (Movie::IsPlayingInput() || Movie::IsRecordingInput())
{
return SystemTimers::GetTicksPerSecond() / VideoInterface::TargetRefreshRate;
if (Movie::IsNetPlayRecording())
return SystemTimers::GetTicksPerSecond() / VideoInterface::TargetRefreshRate / 2;
else
return SystemTimers::GetTicksPerSecond() / VideoInterface::TargetRefreshRate;
}
if (NetPlay::IsNetPlayRunning())
return SystemTimers::GetTicksPerSecond() / VideoInterface::TargetRefreshRate / 2;
Expand Down
22 changes: 19 additions & 3 deletions Source/Core/Core/Src/Movie.cpp
Expand Up @@ -24,6 +24,7 @@
#include "../../Common/Src/NandPaths.h"
#include "polarssl/md5.h"
#include "scmrev.h"
#include "NetPlayClient.h"

// The chunk to allocate movie data in multiples of.
#define DTM_BASE_LENGTH (1024)
Expand All @@ -50,8 +51,8 @@ u64 g_currentFrame = 0, g_totalFrames = 0; // VI
u64 g_currentLagCount = 0, g_totalLagCount = 0; // just stats
u64 g_currentInputCount = 0, g_totalInputCount = 0; // just stats
u64 g_recordingStartTime; // seconds since 1970 that recording started
bool bSaveConfig, bSkipIdle, bDualCore, bProgressive, bDSPHLE, bFastDiscSpeed = false;
bool bMemcard, g_bClearSave, bSyncGPU = false;
bool bSaveConfig = false, bSkipIdle = false, bDualCore = false, bProgressive = false, bDSPHLE = false, bFastDiscSpeed = false;
bool bMemcard = false, g_bClearSave = false, bSyncGPU = false, bNetPlay = false;
std::string videoBackend = "unknown";
int iCPUCore = 1;
bool g_bDiscChange = false;
Expand Down Expand Up @@ -360,6 +361,11 @@ bool IsSyncGPU()
return bSyncGPU;
}

bool IsNetPlayRecording()
{
return bNetPlay;
}

void ChangePads(bool instantly)
{
if (Core::GetState() == Core::CORE_UNINITIALIZED)
Expand Down Expand Up @@ -409,7 +415,14 @@ bool BeginRecordingInput(int controllers)
g_currentFrame = g_totalFrames = 0;
g_currentLagCount = g_totalLagCount = 0;
g_currentInputCount = g_totalInputCount = 0;
g_recordingStartTime = Common::Timer::GetLocalTimeSinceJan1970();
if (NetPlay::IsNetPlayRunning())
{
bNetPlay = true;
g_recordingStartTime = NETPLAY_INITIAL_GCTIME;
}
else
g_recordingStartTime = Common::Timer::GetLocalTimeSinceJan1970();

g_rerecords = 0;

for (int i = 0; i < 4; i++)
Expand Down Expand Up @@ -682,6 +695,7 @@ void ReadHeader()
bMemcard = tmpHeader.bMemcard;
bongos = tmpHeader.bongos;
bSyncGPU = tmpHeader.bSyncGPU;
bNetPlay = tmpHeader.bNetPlay;
memcpy(revision, tmpHeader.revision, ARRAYSIZE(revision));
}
else
Expand Down Expand Up @@ -1108,6 +1122,7 @@ void SaveRecording(const char *filename)
header.bMemcard = bMemcard;
header.bClearSave = g_bClearSave;
header.bSyncGPU = bSyncGPU;
header.bNetPlay = bNetPlay;
strncpy((char *)header.discChange, g_discChange.c_str(),ARRAYSIZE(header.discChange));
strncpy((char *)header.author, author.c_str(),ARRAYSIZE(header.author));
memcpy(header.md5,MD5,16);
Expand Down Expand Up @@ -1168,6 +1183,7 @@ void GetSettings()
videoBackend = g_video_backend->GetName();
bSyncGPU = SConfig::GetInstance().m_LocalCoreStartupParameter.bSyncGPU;
iCPUCore = SConfig::GetInstance().m_LocalCoreStartupParameter.iCPUCore;
bNetPlay = NetPlay::IsNetPlayRunning();
if (!Core::g_CoreStartupParameter.bWii)
g_bClearSave = !File::Exists(SConfig::GetInstance().m_strMemoryCardA);
bMemcard = SConfig::GetInstance().m_EXIDevice[0] == EXIDEVICE_MEMORYCARD;
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/Src/Movie.h
Expand Up @@ -107,7 +107,8 @@ struct DTMHeader {
bool bClearSave; // Create a new memory card when playing back a movie if true
u8 bongos;
bool bSyncGPU;
u8 reserved[14]; // Padding for any new config options
bool bNetPlay;
u8 reserved[13]; // Padding for any new config options
u8 discChange[40]; // Name of iso file to switch to, for two disc games.
u8 revision[20]; // Git hash
u8 reserved2[27]; // Make heading 256 bytes, just because we can
Expand Down Expand Up @@ -142,6 +143,7 @@ bool IsUsingMemcard();
bool IsSyncGPU();
void SetGraphicsConfig();
void GetSettings();
bool IsNetPlayRecording();

bool IsUsingPad(int controller);
bool IsUsingWiimote(int wiimote);
Expand Down
30 changes: 29 additions & 1 deletion Source/Core/Core/Src/NetPlayClient.cpp
Expand Up @@ -17,6 +17,7 @@
// for wiimote/ OSD messages
#include "Core.h"
#include "ConfigManager.h"
#include "Movie.h"

std::mutex crit_netplay_client;
static NetPlayClient * netplay_client = NULL;
Expand Down Expand Up @@ -420,6 +421,21 @@ bool NetPlayClient::StartGame(const std::string &path)

ClearBuffers();

if (m_dialog->IsRecording())
{

if (Movie::IsReadOnly())
Movie::SetReadOnly(false);

u8 controllers_mask = 0;
for (unsigned int i = 0; i < 4; ++i)
{
if (m_pad_map[i] > 0)
controllers_mask |= (1 << i);
}
Movie::BeginRecordingInput(controllers_mask);
}

// boot game
m_dialog->BootGame(path);

Expand Down Expand Up @@ -527,6 +543,18 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, const SPADStatus* const pad_stat
Common::SleepCurrentThread(1);
}

SPADStatus tmp;
tmp.stickY = ((u8*)&netvalues->nHi)[0];
tmp.stickX = ((u8*)&netvalues->nHi)[1];
tmp.button = ((u16*)&netvalues->nHi)[1];

tmp.substickX = ((u8*)&netvalues->nLo)[3];
tmp.substickY = ((u8*)&netvalues->nLo)[2];
tmp.triggerLeft = ((u8*)&netvalues->nLo)[1];
tmp.triggerRight = ((u8*)&netvalues->nLo)[0];
Movie::RecordInput(&tmp, pad_nb);
Movie::InputUpdate();

return true;
}

Expand Down Expand Up @@ -634,7 +662,7 @@ u32 CEXIIPL::NetPlay_GetGCTime()
std::lock_guard<std::mutex> lk(crit_netplay_client);

if (netplay_client)
return 1272737767; // watev
return NETPLAY_INITIAL_GCTIME; // watev
else
return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/Src/NetPlayClient.h
Expand Up @@ -22,6 +22,8 @@

#include "FifoQueue.h"

const int NETPLAY_INITIAL_GCTIME = 1272737767;

class NetPad
{
public:
Expand All @@ -46,6 +48,7 @@ class NetPlayUI
virtual void OnMsgChangeGame(const std::string& filename) = 0;
virtual void OnMsgStartGame() = 0;
virtual void OnMsgStopGame() = 0;
virtual bool IsRecording() = 0;
};

extern NetSettings g_NetPlaySettings;
Expand Down Expand Up @@ -117,6 +120,8 @@ class NetPlayClient

PadMapping m_pad_map[4];

bool m_is_recording;

private:
void UpdateDevices();
void SendPadState(const PadMapping in_game_pad, const NetPad& np);
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/DolphinWX/Src/NetWindow.cpp
Expand Up @@ -354,6 +354,9 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game
bottom_szr->Add(m_memcard_write, 0, wxCENTER);
}

m_record_chkbox = new wxCheckBox(panel, wxID_ANY, _("Record input"));
bottom_szr->Add(m_record_chkbox, 0, wxCENTER);

bottom_szr->AddStretchSpacer(1);
bottom_szr->Add(quit_btn);

Expand Down Expand Up @@ -565,6 +568,11 @@ void NetPlayDiag::OnConfigPads(wxCommandEvent&)
netplay_server->SetPadMapping(mapping);
}

bool NetPlayDiag::IsRecording()
{
return m_record_chkbox->GetValue();
}

ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* const game_list, wxString& game_name)
: wxDialog(parent, wxID_ANY, _("Change Game"), wxDefaultPosition, wxDefaultSize)
, m_game_name(game_name)
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinWX/Src/NetWindow.h
Expand Up @@ -81,6 +81,8 @@ class NetPlayDiag : public wxFrame, public NetPlayUI

static NetPlayDiag *&GetInstance() { return npd; };

bool IsRecording();

private:
DECLARE_EVENT_TABLE()

Expand All @@ -97,6 +99,7 @@ class NetPlayDiag : public wxFrame, public NetPlayUI
wxTextCtrl* m_chat_text;
wxTextCtrl* m_chat_msg_text;
wxCheckBox* m_memcard_write;
wxCheckBox* m_record_chkbox;

std::string m_selected_game;
wxButton* m_game_btn;
Expand Down

0 comments on commit 8ae10b3

Please sign in to comment.