aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/Network/Sony/SQRNetworkManager.cpp
blob: f23a0a6300fb68e171b75ffa7fc9b69f13642d1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "stdafx.h"

#include "SQRNetworkManager.h"

bool SQRNetworkManager::s_safeToRespondToGameBootInvite = false;

void SQRNetworkManager::SafeToRespondToGameBootInvite()
{
	s_safeToRespondToGameBootInvite = true;
}

int SQRNetworkManager::GetSendQueueSizeBytes()
{
	int queueSize = 0;
	int playerCount = GetPlayerCount();
	for(int i = 0; i < playerCount; ++i)
	{
		SQRNetworkPlayer *player = GetPlayerByIndex( i );
		if( player != NULL )
		{
			queueSize += player->GetTotalSendQueueBytes();
		}
	}
	return queueSize;
}

int SQRNetworkManager::GetSendQueueSizeMessages()
{
	int queueSize = 0;
	int playerCount = GetPlayerCount();
	for(int i = 0; i < playerCount; ++i)
	{
		SQRNetworkPlayer *player = GetPlayerByIndex( i );
		if( player != NULL )
		{
			queueSize += player->GetTotalSendQueueMessages();
		}
	}
	return queueSize;
}

int SQRNetworkManager::GetOutstandingAckCount(SQRNetworkPlayer *pSQRPlayer)
{
	int ackCount = 0;
	int playerCount = GetPlayerCount();
	for(int i = 0; i < playerCount; ++i)
	{
		SQRNetworkPlayer *pSQRPlayer2 = GetPlayerByIndex( i );
		if( pSQRPlayer2 )
		{
			if( ( pSQRPlayer == pSQRPlayer2 ) || (pSQRPlayer->IsSameSystem(pSQRPlayer2) ) )
			{
				ackCount += pSQRPlayer2->m_acksOutstanding;
			}
		}
	}
	return ackCount;
}

void SQRNetworkManager::RequestWriteAck(int smallId)
{
	EnterCriticalSection(&m_csAckQueue);
	m_queuedAckRequests.push(smallId);
	LeaveCriticalSection(&m_csAckQueue);
}

void SQRNetworkManager::TickWriteAcks()
{
	EnterCriticalSection(&m_csAckQueue);
	while(m_queuedAckRequests.size() > 0)
	{
		int smallId = m_queuedAckRequests.front();
		m_queuedAckRequests.pop();
		SQRNetworkPlayer *player = GetPlayerBySmallId(smallId);
		if( player )
		{
			LeaveCriticalSection(&m_csAckQueue);
			player->WriteAck();
			EnterCriticalSection(&m_csAckQueue);
		}
	}
	LeaveCriticalSection(&m_csAckQueue);
}