Cleaned up NetPlay a bit, fixed some UI text.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6425 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-11-16 01:55:29 +00:00
parent d0e8d8a509
commit 71f842e8c0
10 changed files with 88 additions and 228 deletions

View File

@ -133,22 +133,15 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
u32 netValues[2] = {0};
int NetPlay = 2;
#if defined(HAVE_WX) && HAVE_WX
NetPlay = NetPlay_GetInput(ISIDevice::m_iDeviceNumber, PadStatus, netValues);
#endif
if (NetPlay != 2)
u32 netValues[2];
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, PadStatus, netValues))
{
if (NetPlay == 1)
{
_Hi = netValues[0]; // first 4 bytes
_Low = netValues[1]; // last 4 bytes
}
_Hi = netValues[0]; // first 4 bytes
_Low = netValues[1]; // last 4 bytes
return true;
}
#endif
Frame::SetPolledDevice();

View File

@ -103,7 +103,7 @@ public:
virtual int RunBuffer(u8* _pBuffer, int _iLength);
// Send and Receive pad input from network
static int NetPlay_GetInput(u8 numPAD, SPADStatus status, u32 *PADStatus);
static bool NetPlay_GetInput(u8 numPAD, SPADStatus status, u32 *PADStatus);
static u8 NetPlay_GetPadNum(u8 numPAD);
// Return true on new data

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Version="9.00"
Name="Dolphin"
ProjectGUID="{A72606EF-C5C1-4954-90AD-F0F93A8D97D9}"
RootNamespace="DolphinWX"
@ -943,10 +943,6 @@
<Filter
Name="NetPlay"
>
<File
RelativePath=".\Src\LockingQueue.h"
>
</File>
<File
RelativePath=".\Src\NetPlay.cpp"
>

View File

@ -1,47 +0,0 @@
#ifndef _LOCKINGQUEUE_H_
#define _LOCKINGQUEUE_H_
#include "Thread.h"
#include <queue>
// i should make one of those single reader/ single writer queues
template <typename T>
class LockingQueue
{
public:
size_t Size()
{
m_crit.Enter();
const size_t s = m_queue.size();
m_crit.Leave();
return s;
}
void Push(const T& t)
{
m_crit.Enter();
m_queue.push(t);
m_crit.Leave();
}
bool Pop(T& t)
{
m_crit.Enter();
if (m_queue.size())
{
t = m_queue.front();
m_queue.pop();
m_crit.Leave();
return true;
}
m_crit.Leave();
return false;
}
private:
std::queue<T> m_queue;
Common::CriticalSection m_crit;
};
#endif

View File

@ -133,13 +133,15 @@ NetPad::NetPad(const SPADStatus* const pad_status)
// called from ---NETPLAY--- thread
void NetPlay::ClearBuffers()
{
// clear pad buffers, no clear method ?
// clear pad buffers, Clear method isn't thread safe
for (unsigned int i=0; i<4; ++i)
{
while (m_pad_buffer[i].size())
m_pad_buffer[i].pop();
while (m_wiimote_buffer[i].size())
m_wiimote_buffer[i].pop();
while (m_pad_buffer[i].Size())
m_pad_buffer[i].Pop();
while (m_wiimote_buffer[i].Size())
m_wiimote_buffer[i].Pop();
m_wiimote_input[i].clear();
}
}
@ -157,17 +159,16 @@ bool NetPlay::GetNetPads(const u8 pad_nb, const SPADStatus* const pad_status, Ne
{
NetPad np(pad_status);
m_crit.buffer.Enter(); // lock buffer
// adjust the buffer either up or down
while (m_pad_buffer[in_game_num].size() <= m_target_buffer_size)
// inserting multiple padstates or dropping states
while (m_pad_buffer[in_game_num].Size() <= m_target_buffer_size)
{
// add to buffer
m_pad_buffer[in_game_num].push(np);
m_pad_buffer[in_game_num].Push(np);
// send
SendPadState(pad_nb, np);
}
m_crit.buffer.Leave();
}
m_crit.players.Leave();
@ -176,23 +177,18 @@ bool NetPlay::GetNetPads(const u8 pad_nb, const SPADStatus* const pad_status, Ne
//bufftimer.Start();
// get padstate from buffer and send to game
m_crit.buffer.Enter(); // lock buffer
while (0 == m_pad_buffer[pad_nb].size())
while (!m_pad_buffer[pad_nb].Pop(*netvalues))
{
m_crit.buffer.Leave();
// wait for receiving thread to push some data
Common::SleepCurrentThread(1);
if (false == m_is_running)
return false;
m_crit.buffer.Enter();
// TODO: check the time of bufftimer here,
// if it gets pretty high, ask the user if they want to disconnect
}
*netvalues = m_pad_buffer[pad_nb].front();
m_pad_buffer[pad_nb].pop();
m_crit.buffer.Leave();
//u64 hangtime = bufftimer.GetTimeElapsed();
//if (hangtime > 10)
@ -213,14 +209,10 @@ void NetPlay::WiimoteInput(int _number, u16 _channelID, const void* _pData, u32
// does this local pad map in game?
if (in_game_num < 4)
{
m_crit.buffer.Enter();
{
m_wiimote_input[_number].resize(m_wiimote_input[_number].size() + 1);
m_wiimote_input[_number].back().assign((char*)_pData, (char*)_pData + _Size);
m_wiimote_input[_number].back().channel = _channelID;
m_crit.buffer.Leave();
}
m_crit.players.Leave();
@ -237,41 +229,33 @@ void NetPlay::WiimoteUpdate(int _number)
// does this local pad map in game?
if (in_game_num < 4)
{
m_crit.buffer.Enter();
m_wiimote_buffer[in_game_num].push(m_wiimote_input[_number]);
m_wiimote_buffer[in_game_num].Push(m_wiimote_input[_number]);
// TODO: send it
m_wiimote_input[_number].clear();
m_crit.buffer.Leave();
}
m_crit.players.Leave();
m_crit.buffer.Enter();
if (0 == m_wiimote_buffer[_number].size())
if (0 == m_wiimote_buffer[_number].Size())
{
//PanicAlert("PANIC");
return;
}
NetWiimote& nw = m_wiimote_buffer[_number].front();
NetWiimote nw;
m_wiimote_buffer[_number].Pop(nw);
NetWiimote::const_iterator
i = nw.begin(), e = nw.end();
for ( ; i!=e; ++i)
Core::Callback_WiimoteInterruptChannel(_number, i->channel, &(*i)[0], (u32)i->size() + RPT_SIZE_HACK);
m_wiimote_buffer[_number].pop();
m_crit.buffer.Leave();
}
// called from ---GUI--- thread
bool NetPlay::StartGame(const std::string &path)
{
CritLocker game_lock(m_crit.game); // lock game state
if (m_is_running)
{
PanicAlert("Game is already running!");
@ -283,17 +267,16 @@ bool NetPlay::StartGame(const std::string &path)
m_is_running = true;
NetPlay_Enable(this);
ClearBuffers();
// boot game
::main_frame->BootGame(path);
//BootManager::BootCore(path);
// TODO: i dont know if i like this here
ClearBuffers();
// temporary
NetWiimote nw;
for (unsigned int i = 0; i<4; ++i)
for (unsigned int f = 0; f<2; ++f)
m_wiimote_buffer[i].push(nw);
m_wiimote_buffer[i].Push(nw);
return true;
}
@ -336,14 +319,14 @@ u8 NetPlay::GetPadNum(u8 numPAD)
// called from ---CPU--- thread
// Actual Core function which is called on every frame
int CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, SPADStatus PadStatus, u32 *PADStatus)
bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, SPADStatus PadStatus, u32 *PADStatus)
{
CritLocker crit(::crit_netplay_ptr);
if (::netplay_ptr)
return netplay_ptr->GetNetPads(numPAD, &PadStatus, (NetPad*)PADStatus) ? 1 : 0;
return netplay_ptr->GetNetPads(numPAD, &PadStatus, (NetPad*)PADStatus);
else
return 2;
return false;
}
// called from ---CPU--- thread

View File

@ -7,18 +7,17 @@
#include "Thread.h"
#include "Timer.h"
// hax, i hope something like this isn't needed on non-windows
#define _WINSOCK2API_
#include <SFML/Network.hpp>
#include "GCPadStatus.h"
//#include <wx/wx.h>
#include <map>
#include <queue>
#include <sstream>
#include "FifoQueue.h"
class NetPlayDiag;
class NetPad
@ -38,32 +37,34 @@ struct Rpt : public std::vector<u8>
typedef std::vector<Rpt> NetWiimote;
#define NETPLAY_VERSION "Dolphin NetPlay 2.2"
#define NETPLAY_VERSION "Dolphin NetPlay r6423"
// messages
#define NP_MSG_PLAYER_JOIN 0x10
#define NP_MSG_PLAYER_LEAVE 0x11
enum
{
NP_MSG_PLAYER_JOIN = 0x10,
NP_MSG_PLAYER_LEAVE = 0x11,
#define NP_MSG_CHAT_MESSAGE 0x30
NP_MSG_CHAT_MESSAGE = 0x30,
#define NP_MSG_PAD_DATA 0x60
#define NP_MSG_PAD_MAPPING 0x61
#define NP_MSG_PAD_BUFFER 0x62
NP_MSG_PAD_DATA = 0x60,
NP_MSG_PAD_MAPPING = 0x61,
NP_MSG_PAD_BUFFER = 0x62,
#define NP_MSG_WIIMOTE_DATA 0x70
#define NP_MSG_WIIMOTE_MAPPING 0x71 // just using pad mapping for now
NP_MSG_WIIMOTE_DATA = 0x70,
NP_MSG_WIIMOTE_MAPPING = 0x71, // just using pad mapping for now
#define NP_MSG_START_GAME 0xA0
#define NP_MSG_CHANGE_GAME 0xA1
#define NP_MSG_STOP_GAME 0xA2
#define NP_MSG_DISABLE_GAME 0xA3
NP_MSG_START_GAME = 0xA0,
NP_MSG_CHANGE_GAME = 0xA1,
NP_MSG_STOP_GAME = 0xA2,
NP_MSG_DISABLE_GAME = 0xA3,
#define NP_MSG_READY 0xD0
#define NP_MSG_NOT_READY 0xD1
NP_MSG_READY = 0xD0,
NP_MSG_NOT_READY = 0xD1,
#define NP_MSG_PING 0xE0
#define NP_MSG_PONG 0xE1
// end messages
NP_MSG_PING = 0xE0,
NP_MSG_PONG = 0xE1,
};
typedef u8 MessageId;
typedef u8 PlayerId;
@ -128,7 +129,7 @@ protected:
{
Common::CriticalSection game;
// lock order
Common::CriticalSection players, buffer, send;
Common::CriticalSection players, send;
} m_crit;
class Player
@ -143,8 +144,8 @@ protected:
std::string revision;
};
std::queue<NetPad> m_pad_buffer[4];
std::queue<NetWiimote> m_wiimote_buffer[4];
Common::FifoQueue<NetPad> m_pad_buffer[4];
Common::FifoQueue<NetWiimote> m_wiimote_buffer[4];
NetWiimote m_wiimote_input[4];
@ -161,7 +162,7 @@ protected:
Player* m_local_player;
u32 m_on_game;
u32 m_current_game;
private:
@ -198,11 +199,11 @@ private:
class Client : public Player
{
public:
Client() : ping(0), on_game(0) {}
Client() : ping(0), current_game(0) {}
sf::SocketTCP socket;
u64 ping;
u32 on_game;
u32 current_game;
};
void SendPadState(const PadMapping local_nb, const NetPad& np);

View File

@ -159,9 +159,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
// trusting server for good map value (>=0 && <4)
// add to pad buffer
m_crit.buffer.Enter(); // lock buffer
m_pad_buffer[(unsigned)map].push(np);
m_crit.buffer.Leave();
m_pad_buffer[(unsigned)map].Push(np);
}
break;
@ -170,9 +168,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
u32 size = 0;
packet >> size;
m_crit.buffer.Enter(); // lock buffer
m_target_buffer_size = size;
m_crit.buffer.Leave();
}
break;
@ -193,9 +189,9 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_START_GAME :
{
m_crit.buffer.Enter(); // lock buffer
packet >> m_on_game;
m_crit.buffer.Leave();
m_crit.game.Enter(); // lock buffer
packet >> m_current_game;
m_crit.game.Leave();
wxCommandEvent evt(wxEVT_THREAD, NP_GUI_EVT_START_GAME);
m_dialog->GetEventHandler()->AddPendingEvent(evt);
@ -299,7 +295,6 @@ void NetPlayClient::SendChatMessage(const std::string& msg)
spac << (MessageId)NP_MSG_CHAT_MESSAGE;
spac << msg;
CritLocker player_lock(m_crit.players); // lock players
CritLocker send_lock(m_crit.send); // lock send
m_socket.Send(spac);
}
@ -320,7 +315,7 @@ void NetPlayClient::SendPadState(const PadMapping local_nb, const NetPad& np)
// called from ---GUI--- thread
bool NetPlayClient::StartGame(const std::string &path)
{
m_crit.buffer.Enter(); // lock buffer
CritLocker game_lock(m_crit.game); // lock game state
if (false == NetPlay::StartGame(path))
return false;
@ -328,9 +323,7 @@ bool NetPlayClient::StartGame(const std::string &path)
// tell server i started the game
sf::Packet spac;
spac << (MessageId)NP_MSG_START_GAME;
spac << m_on_game;
m_crit.buffer.Leave();
spac << m_current_game;
CritLocker send_lock(m_crit.send); // lock send
m_socket.Send(spac);
@ -339,10 +332,7 @@ bool NetPlayClient::StartGame(const std::string &path)
}
// called from ---GUI--- thread
bool NetPlayClient::ChangeGame(const std::string &game)
bool NetPlayClient::ChangeGame(const std::string&)
{
// warning removal
game.size();
return true;
}

View File

@ -257,7 +257,7 @@ unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket)
{
if (m_is_running)
{
PanicAlert("Client disconnect while game is running!! NetPlay is disabled. You manually stop the game.");
PanicAlert("Client disconnect while game is running!! NetPlay is disabled. You must manually stop the game.");
CritLocker game_lock(m_crit.game); // lock game state
m_is_running = false;
NetPlay_Disable();
@ -397,9 +397,7 @@ void NetPlayServer::AdjustPadBufferSize(unsigned int size)
{
CritLocker game_lock(m_crit.game); // lock game state
m_crit.buffer.Enter(); // lock buffer
m_target_buffer_size = size;
m_crit.buffer.Leave();
// tell clients to change buffer size
sf::Packet spac;
@ -448,10 +446,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
case NP_MSG_PAD_DATA :
{
m_crit.buffer.Enter(); // lock buffer
// if this is pad data from the last game still being received, ignore it
if (player.on_game != m_on_game)
if (player.current_game != m_current_game)
break;
PadMapping map = 0;
@ -470,8 +466,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
return 1;
// add to pad buffer
m_pad_buffer[(unsigned)map].push(np);
m_crit.buffer.Leave();
m_pad_buffer[(unsigned)map].Push(np);
// relay to clients
sf::Packet spac;
@ -501,7 +496,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
case NP_MSG_START_GAME :
{
packet >> player.on_game;
packet >> player.current_game;
}
break;
@ -542,6 +537,7 @@ void NetPlayServer::SendChatMessage(const std::string& msg)
spac << (PlayerId)0; // server id always 0
spac << msg;
CritLocker player_lock(m_crit.players); // lock players
CritLocker send_lock(m_crit.send); // lock send
SendToClients(spac);
}
@ -581,14 +577,13 @@ void NetPlayServer::SendPadState(const PadMapping local_nb, const NetPad& np)
// called from ---GUI--- thread
bool NetPlayServer::StartGame(const std::string &path)
{
m_crit.buffer.Enter(); // lock buffer
CritLocker game_lock(m_crit.game); // lock game state
if (false == NetPlay::StartGame(path))
return false;
// TODO: i dont like this here
m_on_game = Common::Timer::GetTimeMs();
m_crit.buffer.Leave();
m_current_game = Common::Timer::GetTimeMs();
// no change, just update with clients
AdjustPadBufferSize(m_target_buffer_size);
@ -596,7 +591,7 @@ bool NetPlayServer::StartGame(const std::string &path)
// tell clients to start game
sf::Packet spac;
spac << (MessageId)NP_MSG_START_GAME;
spac << m_on_game;
spac << m_current_game;
CritLocker player_lock(m_crit.players); // lock players
CritLocker send_lock(m_crit.send); // lock send

View File

@ -84,8 +84,8 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl*
wxStaticText* const alert_lbl = new wxStaticText(connect_tab, wxID_ANY
, wxT("ALERT:\n\nNetPlay will currently only work properly when using the following settings:")
wxT("\n - Dual Core [OFF]")
wxT("\n - Audio Throttle [OFF/ON] (try both)")
wxT("\n - DSP LLE/HLE (try both)")
wxT("\n - Audio Throttle [OFF]")
wxT("\n - DSP-HLE with \"Null Audio\" or DSP-LLE")
wxT("\n - Manually set the exact number of controllers that will be used to [Standard Controller]")
wxT("\n\nAll players should try to use the same Dolphin version and settings.")
wxT("\nDisable all memory cards or send them to all players before starting.")
@ -178,11 +178,8 @@ NetPlaySetupDiag::~NetPlaySetupDiag()
inifile.Save(dolphin_ini);
}
void NetPlaySetupDiag::OnHost(wxCommandEvent& event)
void NetPlaySetupDiag::OnHost(wxCommandEvent&)
{
// warning removal
event.GetId();
if (::netplay_ptr)
{
PanicAlert("A NetPlay window is already open!!");
@ -217,11 +214,8 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent& event)
}
}
void NetPlaySetupDiag::OnJoin(wxCommandEvent& event)
void NetPlaySetupDiag::OnJoin(wxCommandEvent&)
{
// warning removal
event.GetId();
if (::netplay_ptr)
{
PanicAlert("A NetPlay window is already open!!");
@ -248,11 +242,8 @@ void NetPlaySetupDiag::OnJoin(wxCommandEvent& event)
}
}
void NetPlaySetupDiag::OnQuit(wxCommandEvent& event)
void NetPlaySetupDiag::OnQuit(wxCommandEvent&)
{
// warning removal
event.GetId();
Destroy();
}
@ -359,11 +350,8 @@ NetPlayDiag::~NetPlayDiag()
}
}
void NetPlayDiag::OnChat(wxCommandEvent& event)
void NetPlayDiag::OnChat(wxCommandEvent&)
{
// warning removal
event.GetId();
wxString s = m_chat_msg_text->GetValue();
if (s.Length())
@ -374,11 +362,8 @@ void NetPlayDiag::OnChat(wxCommandEvent& event)
}
}
void NetPlayDiag::OnStart(wxCommandEvent& event)
void NetPlayDiag::OnStart(wxCommandEvent&)
{
// warning removal
event.GetId();
// find path for selected game
std::string ntmp, ptmp, path;
std::istringstream nss(m_game_list->GetGameNames()), pss(m_game_list->GetGamePaths());
@ -399,19 +384,13 @@ void NetPlayDiag::OnStart(wxCommandEvent& event)
PanicAlert("Game not found!!");
}
void NetPlayDiag::OnStop(wxCommandEvent& event)
void NetPlayDiag::OnStop(wxCommandEvent&)
{
// warning removal
event.GetId();
::netplay_ptr->StopGame();
}
void NetPlayDiag::OnPadBuffHelp(wxCommandEvent& event)
void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&)
{
// warning removal
event.GetId();
const u64 time = ((NetPlayServer*)::netplay_ptr)->CalculateMinimumBufferTime();
std::ostringstream ss;
ss << "< Calculated from pings: required buffer: "
@ -432,20 +411,14 @@ void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event)
m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent).Append(wxT('\n')));
}
void NetPlayDiag::OnQuit(wxCommandEvent& event)
void NetPlayDiag::OnQuit(wxCommandEvent&)
{
// warning removal
event.GetId();
Destroy();
}
// update gui
void NetPlayDiag::OnThread(wxCommandEvent& event)
{
// warning removal
event.GetId();
// player list
m_playerids.clear();
std::string tmps;
@ -495,11 +468,8 @@ void NetPlayDiag::OnThread(wxCommandEvent& event)
}
}
void NetPlayDiag::OnChangeGame(wxCommandEvent& event)
void NetPlayDiag::OnChangeGame(wxCommandEvent&)
{
// warning removal
event.GetId();
wxString game_name;
ChangeGameDiag* const cgd = new ChangeGameDiag(this, m_game_list, game_name);
cgd->ShowModal();
@ -512,11 +482,8 @@ void NetPlayDiag::OnChangeGame(wxCommandEvent& event)
}
}
void NetPlayDiag::OnConfigPads(wxCommandEvent& event)
void NetPlayDiag::OnConfigPads(wxCommandEvent&)
{
// warning removal
event.GetId();
int mapping[4];
// get selected player id
@ -565,11 +532,8 @@ ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* cons
SetSizerAndFit(dlg_szr);
}
void ChangeGameDiag::OnPick(wxCommandEvent& event)
void ChangeGameDiag::OnPick(wxCommandEvent&)
{
// warning removal
event.GetId();
// return the selected game name
m_game_name = m_game_lbox->GetStringSelection();
Destroy();

View File

@ -30,23 +30,10 @@
#include <wx/gbsizer.h>
#include <wx/listbox.h>
#include <wx/spinctrl.h>
//#include <wx/thread.h>
#include "GameListCtrl.h"
// just leaving these here so i can find something later if i need it
//#include "Frame.h"
//#include "Globals.h"
//#include "BootManager.h"
//#include "Common.h"
//#include "NetStructs.h"
//#include "Core.h"
//#include "HW/SI.h"
//#include "HW/SI_Device.h"
//#include "HW/SI_DeviceGCController.h"
//#include "Timer.h"
#include "LockingQueue.h"
#include "FifoQueue.h"
enum
{
@ -82,8 +69,7 @@ public:
, const std::string& game, const bool is_hosting = false);
~NetPlayDiag();
LockingQueue<std::string> chat_msgs;
//std::string chat_msg;
Common::FifoQueue<std::string> chat_msgs;
void OnStart(wxCommandEvent& event);
void OnStop(wxCommandEvent& event);
@ -109,7 +95,6 @@ private:
std::vector<int> m_playerids;
const CGameListCtrl* const m_game_list;
//NetPlay* const m_netplay;
};
DECLARE_EVENT_TYPE(wxEVT_THREAD, -1)