diff --git a/dep/ggpo-x/ggpo-x.vcxproj b/dep/ggpo-x/ggpo-x.vcxproj
index 499cf85ac..0db68f9b3 100644
--- a/dep/ggpo-x/ggpo-x.vcxproj
+++ b/dep/ggpo-x/ggpo-x.vcxproj
@@ -14,11 +14,9 @@
-
-
@@ -34,10 +32,8 @@
-
-
diff --git a/dep/ggpo-x/ggpo-x.vcxproj.filters b/dep/ggpo-x/ggpo-x.vcxproj.filters
index 6f2e6dfd4..9fd65a704 100644
--- a/dep/ggpo-x/ggpo-x.vcxproj.filters
+++ b/dep/ggpo-x/ggpo-x.vcxproj.filters
@@ -6,9 +6,7 @@
-
-
@@ -32,9 +30,6 @@
network
-
- network
-
@@ -42,9 +37,7 @@
-
-
@@ -59,9 +52,6 @@
network
-
- network
-
diff --git a/dep/ggpo-x/include/ggponet.h b/dep/ggpo-x/include/ggponet.h
index 8888d3372..6da527395 100644
--- a/dep/ggpo-x/include/ggponet.h
+++ b/dep/ggpo-x/include/ggponet.h
@@ -8,6 +8,8 @@
#ifndef _GGPONET_H_
#define _GGPONET_H_
+#include "enet/enet.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -78,8 +80,7 @@ typedef struct GGPOPlayer {
struct {
} local;
struct {
- char ip_address[32];
- unsigned short port;
+ ENetPeer* peer;
} remote;
} u;
} GGPOPlayer;
@@ -153,8 +154,7 @@ typedef enum {
GGPO_EVENTCODE_TIMESYNC = 1005,
GGPO_EVENTCODE_CONNECTION_INTERRUPTED = 1006,
GGPO_EVENTCODE_CONNECTION_RESUMED = 1007,
- GGPO_EVENTCODE_CHAT = 1008,
- GGPO_EVENTCODE_DESYNC = 1009
+ GGPO_EVENTCODE_DESYNC = 1008
} GGPOEventCode;
/*
@@ -190,10 +190,6 @@ typedef struct {
struct {
GGPOPlayerHandle player;
} connection_resumed;
- struct {
- int senderID;
- const char* msg;
- } chat;
struct {
int nFrameOfDesync;
uint32_t ourCheckSum;
@@ -480,25 +476,6 @@ GGPO_API GGPOErrorCode __cdecl ggpo_add_local_input(GGPOSession *,
GGPOPlayerHandle player,
void *values,
int size);
-/*
- * ggpo_add_local_input --
- *
- * Used to notify GGPO.net of inputs that should be trasmitted to remote
- * players. ggpo_add_local_input must be called once every frame for
- * all player of type GGPO_PLAYERTYPE_LOCAL.
- *
- * player - The player handle returned for this player when you called
- * ggpo_add_local_player.
- *
- * values - The controller inputs for this player.
- *
- * size - The size of the controller inputs. This must be exactly equal to the
- * size passed into ggpo_start_session.
- */
-
-GGPO_API GGPOErrorCode __cdecl ggpo_client_chat(GGPOSession *,
- const char* message);
-
/*
* ggpo_synchronize_input --
*
@@ -575,15 +552,6 @@ GGPO_API GGPOErrorCode __cdecl ggpo_get_network_stats(GGPOSession *,
GGPO_API GGPOErrorCode __cdecl ggpo_set_disconnect_timeout(GGPOSession *,
int timeout);
/*
- * ggpo_enable_manual_network_polling --
- *
- * disables polling done by ggpo and it's expected that ggpo_poll_network will be used instead.
- *
- */
-
-GGPO_API GGPOErrorCode __cdecl ggpo_set_manual_network_polling(GGPOSession*,
- bool value);
- /*
* ggpo_set_disconnect_notify_start --
*
* The time to wait before the first GGPO_EVENTCODE_NETWORK_INTERRUPTED timeout
@@ -594,14 +562,12 @@ GGPO_API GGPOErrorCode __cdecl ggpo_set_manual_network_polling(GGPOSession*,
*/
GGPO_API GGPOErrorCode __cdecl ggpo_set_disconnect_notify_start(GGPOSession *,
int timeout);
-/*
-* ggpo_poll_network --
-*
-* polls the network socket for any messages to be sent and recieved.
-*
-*/
-GGPO_API GGPOErrorCode __cdecl ggpo_poll_network(GGPOSession*);
+/*
+ * ENet packet processing
+ */
+GGPO_API GGPOErrorCode __cdecl ggpo_handle_packet(GGPOSession*,
+ ENetPeer* peer, const ENetPacket* pkt);
/*
* ggpo_log --
diff --git a/dep/ggpo-x/src/backends/backend.h b/dep/ggpo-x/src/backends/backend.h
index 7b747e0ae..6296a1128 100644
--- a/dep/ggpo-x/src/backends/backend.h
+++ b/dep/ggpo-x/src/backends/backend.h
@@ -20,16 +20,14 @@ public:
virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) = 0;
virtual GGPOErrorCode IncrementFrame(uint16_t checksum) = 0;
virtual GGPOErrorCode CurrentFrame(int& current) =0;
- virtual GGPOErrorCode Chat(const char* text) = 0;// { return GGPO_OK; }
virtual GGPOErrorCode DisconnectPlayer(GGPOPlayerHandle handle) = 0;// { return GGPO_OK; }
- virtual GGPOErrorCode PollNetwork() = 0;
virtual GGPOErrorCode GetNetworkStats(GGPONetworkStats *stats, GGPOPlayerHandle handle) { return GGPO_OK; }
virtual GGPOErrorCode Logv(const char *fmt, va_list list) { ::Logv(fmt, list); return GGPO_OK; }
virtual GGPOErrorCode SetFrameDelay(GGPOPlayerHandle player, int delay) { return GGPO_ERRORCODE_UNSUPPORTED; }
virtual GGPOErrorCode SetDisconnectTimeout(int timeout) { return GGPO_ERRORCODE_UNSUPPORTED; }
virtual GGPOErrorCode SetDisconnectNotifyStart(int timeout) { return GGPO_ERRORCODE_UNSUPPORTED; }
- virtual GGPOErrorCode SetManualNetworkPolling(bool value) = 0;
+ virtual GGPOErrorCode OnPacket(ENetPeer* peer, const ENetPacket* pkt) = 0;
};
diff --git a/dep/ggpo-x/src/backends/p2p.cpp b/dep/ggpo-x/src/backends/p2p.cpp
index ce3fdcc58..dbffe9d67 100644
--- a/dep/ggpo-x/src/backends/p2p.cpp
+++ b/dep/ggpo-x/src/backends/p2p.cpp
@@ -27,7 +27,6 @@ Peer2PeerBackend::Peer2PeerBackend(GGPOSessionCallbacks *cb,
_callbacks = *cb;
_synchronizing = true;
_next_recommended_sleep = 0;
- _manual_network_polling = false;
/*
* Initialize the synchronziation layer
@@ -39,11 +38,6 @@ Peer2PeerBackend::Peer2PeerBackend(GGPOSessionCallbacks *cb,
config.num_prediction_frames = nframes;
_sync.Init(config);
- /*
- * Initialize the UDP port
- */
- _udp.Init(localport, &_poll, this);
-
_endpoints.resize(_num_players);
memset(_local_connect_status, 0, sizeof(_local_connect_status));
for (int i = 0; i < ARRAY_SIZE(_local_connect_status); i++) {
@@ -61,23 +55,20 @@ Peer2PeerBackend::~Peer2PeerBackend()
}
void
-Peer2PeerBackend::AddRemotePlayer(char *ip,
- uint16 port,
- int queue)
+Peer2PeerBackend::AddRemotePlayer(ENetPeer* peer, int queue)
{
/*
* Start the state machine (xxx: no)
*/
_synchronizing = true;
- _endpoints[queue].Init(&_udp, _poll, queue, ip, port, _local_connect_status);
+ _endpoints[queue].Init(peer, queue, _local_connect_status);
_endpoints[queue].SetDisconnectTimeout(_disconnect_timeout);
_endpoints[queue].SetDisconnectNotifyStart(_disconnect_notify_start);
_endpoints[queue].Synchronize();
}
-GGPOErrorCode Peer2PeerBackend::AddSpectator(char *ip,
- uint16 port)
+GGPOErrorCode Peer2PeerBackend::AddSpectator(ENetPeer* peer)
{
if (_num_spectators == GGPO_MAX_SPECTATORS) {
return GGPO_ERRORCODE_TOO_MANY_SPECTATORS;
@@ -90,7 +81,7 @@ GGPOErrorCode Peer2PeerBackend::AddSpectator(char *ip,
}
int queue = _num_spectators++;
- _spectators[queue].Init(&_udp, _poll, queue + 1000, ip, port, _local_connect_status);
+ _spectators[queue].Init(peer, queue + 1000, _local_connect_status);
_spectators[queue].SetDisconnectTimeout(_disconnect_timeout);
_spectators[queue].SetDisconnectNotifyStart(_disconnect_notify_start);
_spectators[queue].Synchronize();
@@ -155,20 +146,10 @@ void Peer2PeerBackend::CheckDesync()
GGPOErrorCode
Peer2PeerBackend::DoPoll()
{
- // Pass on chat
- for (int i = 0; i < _num_players; i++) {
- _endpoints[i].ConsumeChat([&](const char* msg) {
- GGPOEvent info;
- info.u.chat.senderID = i;
- info.code = GGPO_EVENTCODE_CHAT;
- info.u.chat.msg = msg;
- _callbacks.on_event(_callbacks.context, &info);
- });
- }
-
- if (!_sync.InRollback()) {
- if (!_manual_network_polling)
- _poll.Pump(0);
+ if (!_sync.InRollback())
+ {
+ for (UdpProtocol& udp : _endpoints)
+ udp.OnLoopPoll();
PollUdpProtocolEvents();
CheckDesync();
@@ -309,7 +290,7 @@ Peer2PeerBackend::AddPlayer(GGPOPlayer *player,
GGPOPlayerHandle *handle)
{
if (player->type == GGPO_PLAYERTYPE_SPECTATOR) {
- return AddSpectator(player->u.remote.ip_address, player->u.remote.port);
+ return AddSpectator(player->u.remote.peer);
}
int queue = player->player_num - 1;
@@ -319,7 +300,7 @@ Peer2PeerBackend::AddPlayer(GGPOPlayer *player,
*handle = QueueToPlayerHandle(queue);
if (player->type == GGPO_PLAYERTYPE_REMOTE) {
- AddRemotePlayer(player->u.remote.ip_address, player->u.remote.port, queue);
+ AddRemotePlayer(player->u.remote.peer, queue);
}
return GGPO_OK;
}
@@ -413,19 +394,6 @@ Peer2PeerBackend::CurrentFrame(int& current)
return GGPO_OK;
}
-GGPOErrorCode
-Peer2PeerBackend::PollNetwork()
-{
- _poll.Pump(0);
- return GGPO_OK;
-}
-
-GGPOErrorCode Peer2PeerBackend::SetManualNetworkPolling(bool value)
-{
- _manual_network_polling = value;
- return GGPO_OK;
-}
-
GGPOErrorCode
Peer2PeerBackend::IncrementFrame(uint16_t checksum1)
{
@@ -766,21 +734,6 @@ Peer2PeerBackend::SetDisconnectNotifyStart(int timeout)
return GGPO_OK;
}
-GGPOErrorCode
-Peer2PeerBackend::Chat(const char* text)
-{
- if (strlen(text) >= MAX_CHAT_LENGTH)
- return GGPO_CHAT_MESSAGE_TOO_LONG;
-
- // Send the input to all the remote players.
- for (int i = 0; i < _num_players; i++) {
- if (_endpoints[i].IsInitialized()) {
- _endpoints[i].SendChat(text);
- }
- }
- return GGPO_OK;
-}
-
GGPOErrorCode
Peer2PeerBackend::PlayerHandleToQueue(GGPOPlayerHandle player, int *queue)
{
@@ -793,21 +746,27 @@ Peer2PeerBackend::PlayerHandleToQueue(GGPOPlayerHandle player, int *queue)
}
-void
-Peer2PeerBackend::OnMsg(sockaddr_in &from, UdpMsg *msg, int len)
+GGPOErrorCode
+Peer2PeerBackend::OnPacket(ENetPeer* peer, const ENetPacket* pkt)
{
+ // ugh why is const so hard for some people...
+ UdpMsg* msg = const_cast(reinterpret_cast(pkt->data));
+ const int len = static_cast(pkt->dataLength);
+
for (int i = 0; i < _num_players; i++) {
- if (_endpoints[i].HandlesMsg(from, msg)) {
+ if (_endpoints[i].GetENetPeer() == peer) {
_endpoints[i].OnMsg(msg, len);
- return;
+ return GGPO_OK;
}
}
for (int i = 0; i < _num_spectators; i++) {
- if (_spectators[i].HandlesMsg(from, msg)) {
+ if (_spectators[i].GetENetPeer() == peer) {
_spectators[i].OnMsg(msg, len);
- return;
+ return GGPO_OK;
}
}
+
+ return GGPO_ERRORCODE_INVALID_PLAYER_HANDLE;
}
void
diff --git a/dep/ggpo-x/src/backends/p2p.h b/dep/ggpo-x/src/backends/p2p.h
index 7835a0cb9..3e3220a6b 100644
--- a/dep/ggpo-x/src/backends/p2p.h
+++ b/dep/ggpo-x/src/backends/p2p.h
@@ -9,13 +9,13 @@
#define _P2P_H
#include "types.h"
-#include "poll.h"
#include "sync.h"
#include "backend.h"
#include "timesync.h"
#include "network/udp_proto.h"
#include