Permalink
Browse files

Merge pull request #115 from TeamHypersomnia/master

public HasMessagesToSend, unused field, fixed an assertion
  • Loading branch information...
gafferongames committed Dec 18, 2018
2 parents 01e0a0b + c285f2a commit ce9573cdc1ceafec36366f56d7db7f386f71df01
Showing with 44 additions and 7 deletions.
  1. +27 −1 yojimbo.cpp
  2. +17 −6 yojimbo.h
@@ -1586,7 +1586,7 @@ namespace yojimbo

if ( !config.disableBlocks )
{
m_sendBlock = YOJIMBO_NEW( *m_allocator, SendBlockData, *m_allocator, m_config.maxBlockSize, m_config.GetMaxFragmentsPerBlock() );
m_sendBlock = YOJIMBO_NEW( *m_allocator, SendBlockData, *m_allocator, m_config.GetMaxFragmentsPerBlock() );
m_receiveBlock = YOJIMBO_NEW( *m_allocator, ReceiveBlockData, *m_allocator, m_config.maxBlockSize, m_config.GetMaxFragmentsPerBlock() );
}
else
@@ -2349,6 +2349,12 @@ namespace yojimbo
return !m_messageSendQueue->IsFull();
}

bool UnreliableUnorderedChannel::HasMessagesToSend() const
{
yojimbo_assert( m_messageSendQueue );
return !m_messageSendQueue->IsEmpty();
}

void UnreliableUnorderedChannel::SendMessage( Message * message, void *context )
{
yojimbo_assert( message );
@@ -2686,6 +2692,12 @@ namespace yojimbo
return m_channel[channelIndex]->CanSendMessage();
}

bool Connection::HasMessagesToSend( int channelIndex ) const {
yojimbo_assert( channelIndex >= 0 );
yojimbo_assert( channelIndex < m_connectionConfig.numChannels );
return m_channel[channelIndex]->HasMessagesToSend();
}

void Connection::SendMessage( int channelIndex, Message * message, void *context)
{
yojimbo_assert( channelIndex >= 0 );
@@ -3095,6 +3107,12 @@ namespace yojimbo
return m_connection->CanSendMessage( channelIndex );
}

bool BaseClient::HasMessagesToSend( int channelIndex ) const
{
yojimbo_assert( m_connection );
return m_connection->HasMessagesToSend( channelIndex );
}

void BaseClient::SendMessage( int channelIndex, Message * message )
{
yojimbo_assert( m_connection );
@@ -3628,6 +3646,14 @@ namespace yojimbo
return m_clientConnection[clientIndex]->CanSendMessage( channelIndex );
}

bool BaseServer::HasMessagesToSend( int clientIndex, int channelIndex ) const
{
yojimbo_assert( clientIndex >= 0 );
yojimbo_assert( clientIndex < m_maxClients );
yojimbo_assert( m_clientConnection[clientIndex] );
return m_clientConnection[clientIndex]->HasMessagesToSend( channelIndex );
}

void BaseServer::SendMessage( int clientIndex, int channelIndex, Message * message )
{
yojimbo_assert( clientIndex >= 0 );
@@ -2965,7 +2965,7 @@ namespace yojimbo
if ( Stream::IsWriting )
{
length = (int) strlen( string );
yojimbo_assert( length < buffer_size - 1 );
yojimbo_assert( length < buffer_size );
}
serialize_int( stream, length, 0, buffer_size - 1 );
serialize_bytes( stream, (uint8_t*)string, length );
@@ -4120,6 +4120,13 @@ namespace yojimbo

virtual bool CanSendMessage() const = 0;

/**
Are there any messages in the send queue?
@returns True if there is at least one message in the send queue.
*/

virtual bool HasMessagesToSend() const = 0;

/**
Queue a message to be sent across this channel.
@param message The message to be sent.
@@ -4455,22 +4462,19 @@ namespace yojimbo

struct SendBlockData
{
SendBlockData( Allocator & allocator, int maxBlockSize, int maxFragmentsPerBlock )
SendBlockData( Allocator & allocator, int maxFragmentsPerBlock )
{
m_allocator = &allocator;
ackedFragment = YOJIMBO_NEW( allocator, BitArray, allocator, maxFragmentsPerBlock );
fragmentSendTime = (double*) YOJIMBO_ALLOCATE( allocator, sizeof( double) * maxFragmentsPerBlock );
blockData = (uint8_t*) YOJIMBO_ALLOCATE( allocator, maxBlockSize );
yojimbo_assert( ackedFragment );
yojimbo_assert( fragmentSendTime );
yojimbo_assert( blockData );
Reset();
}

~SendBlockData()
{
YOJIMBO_DELETE( *m_allocator, BitArray, ackedFragment );
YOJIMBO_FREE( *m_allocator, blockData );
YOJIMBO_FREE( *m_allocator, fragmentSendTime );
}

@@ -4490,7 +4494,6 @@ namespace yojimbo
uint16_t blockMessageId; ///< The message id the block is attached to.
BitArray * ackedFragment; ///< Has fragment n been received?
double * fragmentSendTime; ///< Last time fragment was sent.
uint8_t * blockData; ///< The block data.

private:

@@ -4603,6 +4606,8 @@ namespace yojimbo

bool CanSendMessage() const;

bool HasMessagesToSend() const;

void SendMessage( Message * message, void *context );

Message * ReceiveMessage();
@@ -4654,6 +4659,8 @@ namespace yojimbo

bool CanSendMessage( int channelIndex ) const;

bool HasMessagesToSend( int channelIndex ) const;

void SendMessage( int channelIndex, Message * message, void *context = 0);

Message * ReceiveMessage( int channelIndex );
@@ -5237,6 +5244,8 @@ namespace yojimbo

bool CanSendMessage( int clientIndex, int channelIndex ) const;

bool HasMessagesToSend( int clientIndex, int channelIndex ) const;

void SendMessage( int clientIndex, int channelIndex, Message * message );

Message * ReceiveMessage( int clientIndex, int channelIndex );
@@ -5640,6 +5649,8 @@ namespace yojimbo

bool CanSendMessage( int channelIndex ) const;

bool HasMessagesToSend( int channelIndex ) const;

void SendMessage( int channelIndex, Message * message );

Message * ReceiveMessage( int channelIndex );

0 comments on commit ce9573c

Please sign in to comment.