Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate Frame Delay w/ Only Local Players #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/lib/ggpo/backends/p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Peer2PeerBackend::Peer2PeerBackend(GGPOSessionCallbacks *cb,
*/
_callbacks.begin_game(gamename);
}

Peer2PeerBackend::~Peer2PeerBackend()
{
delete [] _endpoints;
Expand All @@ -69,7 +69,7 @@ Peer2PeerBackend::AddRemotePlayer(char *ip,
* Start the state machine (xxx: no)
*/
_synchronizing = true;

_endpoints[queue].Init(&_udp, _poll, queue, ip, port, _local_connect_status);
_endpoints[queue].SetDisconnectTimeout(_disconnect_timeout);
_endpoints[queue].SetDisconnectNotifyStart(_disconnect_notify_start);
Expand Down Expand Up @@ -104,14 +104,23 @@ Peer2PeerBackend::DoPoll(int timeout)
if (!_sync.InRollback()) {
_poll.Pump(0);

const int current_frame = _sync.GetFrameCount();

// To simulate input delay with only local players present,
// check synchronization state on first frame. If only
// local players are present, then _synchronizing is always
// false -- representing local play w/ input delay.
if (current_frame == 0) {
CheckInitialSync();
}

PollUdpProtocolEvents();

if (!_synchronizing) {
_sync.CheckSimulation(timeout);

// notify all of our endpoints of their local frame number for their
// next connection quality report
int current_frame = _sync.GetFrameCount();
for (int i = 0; i < _num_players; i++) {
_endpoints[i].SetLocalFrameNumber(current_frame);
}
Expand All @@ -129,7 +138,7 @@ Peer2PeerBackend::DoPoll(int timeout)
if (_num_spectators > 0) {
while (_next_spectator_frame <= total_min_confirmed) {
Log("pushing frame %d to spectators.\n", _next_spectator_frame);

GameInput input;
input.frame = _next_spectator_frame;
input.size = _input_size * _num_players;
Expand Down Expand Up @@ -275,7 +284,7 @@ Peer2PeerBackend::AddLocalInput(GGPOPlayerHandle player,
if (_synchronizing) {
return GGPO_ERRORCODE_NOT_SYNCHRONIZED;
}

result = PlayerHandleToQueue(player, &queue);
if (!GGPO_SUCCEEDED(result)) {
return result;
Expand Down Expand Up @@ -328,7 +337,7 @@ Peer2PeerBackend::SyncInput(void *values,

GGPOErrorCode
Peer2PeerBackend::IncrementFrame(void)
{
{
Log("End of frame (%d)...\n", _sync.GetFrameCount());
_sync.IncrementFrame();
DoPoll(0);
Expand Down Expand Up @@ -465,7 +474,7 @@ Peer2PeerBackend::DisconnectPlayer(GGPOPlayerHandle player)
if (!GGPO_SUCCEEDED(result)) {
return result;
}

if (_local_connect_status[queue].disconnected) {
return GGPO_ERRORCODE_PLAYER_DISCONNECTED;
}
Expand Down Expand Up @@ -533,8 +542,8 @@ Peer2PeerBackend::GetNetworkStats(GGPONetworkStats *stats, GGPOPlayerHandle play
}

GGPOErrorCode
Peer2PeerBackend::SetFrameDelay(GGPOPlayerHandle player, int delay)
{
Peer2PeerBackend::SetFrameDelay(GGPOPlayerHandle player, int delay)
{
int queue;
GGPOErrorCode result;

Expand All @@ -543,7 +552,7 @@ Peer2PeerBackend::SetFrameDelay(GGPOPlayerHandle player, int delay)
return result;
}
_sync.SetFrameDelay(queue, delay);
return GGPO_OK;
return GGPO_OK;
}

GGPOErrorCode
Expand Down Expand Up @@ -581,7 +590,7 @@ Peer2PeerBackend::PlayerHandleToQueue(GGPOPlayerHandle player, int *queue)
return GGPO_OK;
}


void
Peer2PeerBackend::OnMsg(sockaddr_in &from, UdpMsg *msg, int len)
{
Expand Down