~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/Core/Src/NetPlayClient.h

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#ifndef _NETPLAY_H
 
6
#define _NETPLAY_H
 
7
 
 
8
#include "Common.h"
 
9
#include "CommonTypes.h"
 
10
#include "Thread.h"
 
11
#include "Timer.h"
 
12
 
 
13
#include <SFML/Network.hpp>
 
14
 
 
15
#include "NetPlayProto.h"
 
16
#include "GCPadStatus.h"
 
17
 
 
18
#include <functional>
 
19
#include <map>
 
20
#include <queue>
 
21
#include <sstream>
 
22
 
 
23
#include "FifoQueue.h"
 
24
 
 
25
class NetPad
 
26
{
 
27
public:
 
28
        NetPad();
 
29
        NetPad(const SPADStatus* const);
 
30
 
 
31
        u32 nHi;
 
32
        u32 nLo;
 
33
};
 
34
 
 
35
class NetPlayUI
 
36
{
 
37
public:
 
38
        virtual ~NetPlayUI() {};
 
39
 
 
40
        virtual void BootGame(const std::string& filename) = 0;
 
41
        virtual void StopGame() = 0;
 
42
 
 
43
        virtual void Update() = 0;
 
44
        virtual void AppendChat(const std::string& msg) = 0;
 
45
 
 
46
        virtual void OnMsgChangeGame(const std::string& filename) = 0;
 
47
        virtual void OnMsgStartGame() = 0;
 
48
        virtual void OnMsgStopGame() = 0;
 
49
        virtual bool IsRecording() = 0;
 
50
};
 
51
 
 
52
class Player
 
53
{
 
54
 public:
 
55
        PlayerId                pid;
 
56
        std::string             name;
 
57
        std::string             revision;
 
58
        u32                     ping;
 
59
};
 
60
 
 
61
class NetPlayClient
 
62
{
 
63
public:
 
64
        void ThreadFunc();
 
65
 
 
66
        NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name);
 
67
        ~NetPlayClient();
 
68
 
 
69
        void GetPlayerList(std::string& list, std::vector<int>& pid_list);
 
70
        void GetPlayers(std::vector<const Player *>& player_list);
 
71
 
 
72
        bool is_connected;
 
73
 
 
74
        bool StartGame(const std::string &path);
 
75
        bool StopGame();
 
76
        void Stop();
 
77
        bool ChangeGame(const std::string& game);
 
78
        void SendChatMessage(const std::string& msg);
 
79
 
 
80
        // Send and receive pads values
 
81
        bool WiimoteUpdate(int _number, u8* data, const u8 size);
 
82
        bool GetNetPads(const u8 pad_nb, const SPADStatus* const, NetPad* const netvalues);
 
83
 
 
84
        u8 LocalPadToInGamePad(u8 localPad);
 
85
        u8 InGamePadToLocalPad(u8 localPad);
 
86
 
 
87
        u8 LocalWiimoteToInGameWiimote(u8 local_pad);
 
88
 
 
89
protected:
 
90
        void ClearBuffers();
 
91
 
 
92
        struct
 
93
        {
 
94
                std::recursive_mutex game;
 
95
                // lock order
 
96
                std::recursive_mutex players, send;
 
97
        } m_crit;
 
98
 
 
99
        Common::FifoQueue<NetPad>               m_pad_buffer[4];
 
100
        Common::FifoQueue<NetWiimote>   m_wiimote_buffer[4];
 
101
 
 
102
        NetPlayUI*              m_dialog;
 
103
        sf::SocketTCP   m_socket;
 
104
        std::thread             m_thread;
 
105
        sf::Selector<sf::SocketTCP>             m_selector;
 
106
 
 
107
        std::string             m_selected_game;
 
108
        volatile bool   m_is_running;
 
109
        volatile bool   m_do_loop;
 
110
 
 
111
        unsigned int    m_target_buffer_size;
 
112
 
 
113
        Player*         m_local_player;
 
114
 
 
115
        u32             m_current_game;
 
116
 
 
117
        PadMapping      m_pad_map[4];
 
118
        PadMapping      m_wiimote_map[4];
 
119
 
 
120
        bool m_is_recording;
 
121
 
 
122
private:
 
123
        void UpdateDevices();
 
124
        void SendPadState(const PadMapping in_game_pad, const NetPad& np);
 
125
        void SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw);
 
126
        unsigned int OnData(sf::Packet& packet);
 
127
 
 
128
        PlayerId                m_pid;
 
129
        std::map<PlayerId, Player>      m_players;
 
130
};
 
131
 
 
132
void NetPlay_Enable(NetPlayClient* const np);
 
133
void NetPlay_Disable();
 
134
 
 
135
#endif