Skip to content

Commit

Permalink
wip tracking down breaking in most recent version of netcode integrat…
Browse files Browse the repository at this point in the history
…ed today
  • Loading branch information
gafferongames committed Sep 18, 2024
1 parent af6e648 commit f7d256b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 deletions.
5 changes: 4 additions & 1 deletion include/yojimbo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define YOJIMBO_MAJOR_VERSION 1
#define YOJIMBO_MINOR_VERSION 2
#define YOJIMBO_PATCH_VERSION 4
#define YOJIMBO_PATCH_VERSION 5

#if !defined(YOJIMBO_DEBUG) && !defined(YOJIMBO_RELEASE)
#if defined(NDEBUG)
Expand Down Expand Up @@ -66,6 +66,9 @@
#define YOJIMBO_PLATFORM YOJIMBO_PLATFORM_UNIX
#endif

// todo
#define YOJIMBO_DEBUG 1

#ifdef YOJIMBO_DEBUG

#define YOJIMBO_DEBUG_MEMORY_LEAKS 1
Expand Down
15 changes: 12 additions & 3 deletions netcode/netcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ void netcode_set_assert_function( void (*function)( NETCODE_CONST char *, NETCOD

void netcode_printf( int level, NETCODE_CONST char * format, ... )
{
if ( level > log_level )
return;
// todo
(void) level;
// if ( level > log_level )
// return;
va_list args;
va_start( args, format );
char buffer[4*1024];
Expand Down Expand Up @@ -3112,6 +3114,9 @@ void netcode_client_send_packet_to_server_internal( struct netcode_client_t * cl

if ( client->config.network_simulator )
{
// todo
printf( "sent packet through network simulator\n" );

netcode_network_simulator_send_packet( client->config.network_simulator, &client->address, &client->server_address, packet_data, packet_bytes );
}
else
Expand Down Expand Up @@ -3180,7 +3185,7 @@ void netcode_client_send_packets( struct netcode_client_t * client )
if ( client->last_packet_send_time + ( 1.0 / NETCODE_PACKET_SEND_RATE ) >= client->time )
return;

netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "client sent connection keep-alive packet to server\n" );
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "client sent connection keep alive packet to server\n" );

struct netcode_connection_keep_alive_packet_t packet;
packet.packet_type = NETCODE_CONNECTION_KEEP_ALIVE_PACKET;
Expand Down Expand Up @@ -4953,6 +4958,10 @@ void netcode_server_check_for_timeouts( struct netcode_server_t * server )
{
netcode_printf( NETCODE_LOG_LEVEL_INFO, "server timed out client %d\n", i );
netcode_server_disconnect_client_internal( server, i, 0 );

// todo
printf( "*** BROKEN ***\n" );
exit(1);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions source/yojimbo_base_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace yojimbo
{
BaseClient::BaseClient( Allocator & allocator, const ClientServerConfig & config, Adapter & adapter, double time ) : m_config( config )
{
// todo
printf( "BaseClient::BaseClient\n" );

m_allocator = &allocator;
m_adapter = &adapter;
m_time = time;
Expand All @@ -51,6 +54,9 @@ namespace yojimbo

BaseClient::~BaseClient()
{
// todo
printf( "BaseClient::~BaseClient\n" );

// IMPORTANT: Please disconnect the client before destroying it
yojimbo_assert( m_clientState <= CLIENT_STATE_DISCONNECTED );
YOJIMBO_FREE( *m_allocator, m_packetBuffer );
Expand All @@ -59,6 +65,9 @@ namespace yojimbo

void BaseClient::Disconnect()
{
// todo
printf( "BaseClient::Disconnect\n" );

SetClientState( CLIENT_STATE_DISCONNECTED );
Reset();
}
Expand Down Expand Up @@ -127,6 +136,9 @@ namespace yojimbo

void BaseClient::CreateInternal()
{
// todo
printf( "BaseClient::CreateInternal\n" );

yojimbo_assert( m_allocator );
yojimbo_assert( m_adapter );
yojimbo_assert( m_clientMemory == NULL );
Expand All @@ -137,6 +149,10 @@ namespace yojimbo
m_messageFactory = m_adapter->CreateMessageFactory( *m_clientAllocator );
m_connection = YOJIMBO_NEW( *m_clientAllocator, Connection, *m_clientAllocator, *m_messageFactory, m_config, m_time );
yojimbo_assert( m_connection );

// todo
printf( "m_connection = %p\n", m_connection );

if ( m_config.networkSimulator )
{
m_networkSimulator = YOJIMBO_NEW( *m_clientAllocator, NetworkSimulator, *m_clientAllocator, m_config.maxSimulatorPackets, m_time );
Expand Down
21 changes: 21 additions & 0 deletions source/yojimbo_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ namespace yojimbo
Client::Client( Allocator & allocator, const Address & address, const ClientServerConfig & config, Adapter & adapter, double time )
: BaseClient( allocator, config, adapter, time ), m_config( config ), m_address( address )
{
// todo
printf( "Client::Client\n" );

m_clientId = 0;
m_client = NULL;
m_boundAddress = m_address;
}

Client::~Client()
{
// todo
printf( "Client::~Client\n" );

// IMPORTANT: Please disconnect the client before destroying it
yojimbo_assert( m_client == NULL );
}
Expand All @@ -28,6 +34,9 @@ namespace yojimbo

void Client::InsecureConnect( const uint8_t privateKey[], uint64_t clientId, const Address serverAddresses[], int numServerAddresses )
{
// todo
printf( "Client::InsecureConnect\n" );

yojimbo_assert( serverAddresses );
yojimbo_assert( numServerAddresses > 0 );
yojimbo_assert( numServerAddresses <= NETCODE_MAX_SERVERS_PER_CONNECT );
Expand Down Expand Up @@ -82,6 +91,9 @@ namespace yojimbo

void Client::Connect( uint64_t clientId, uint8_t * connectToken )
{
// todo
printf( "Client::Connect\n" );

yojimbo_assert( connectToken );
Disconnect();
CreateInternal();
Expand All @@ -100,6 +112,9 @@ namespace yojimbo

void Client::Disconnect()
{
// todo
printf( "Client::Disconnect\n" );

BaseClient::Disconnect();
DestroyClient();
DestroyInternal();
Expand Down Expand Up @@ -146,11 +161,17 @@ namespace yojimbo
const int state = netcode_client_state( m_client );
if ( state < NETCODE_CLIENT_STATE_DISCONNECTED )
{
// todo
printf( "error state %d\n", state );

Disconnect();
SetClientState( CLIENT_STATE_ERROR );
}
else if ( state == NETCODE_CLIENT_STATE_DISCONNECTED )
{
// todo
printf( "set disconnected state %d\n", state );

Disconnect();
SetClientState( CLIENT_STATE_DISCONNECTED );
}
Expand Down
3 changes: 2 additions & 1 deletion source/yojimbo_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static void default_assert_handler( const char * condition, const char * functio
#endif
}

static int log_level = 0;
// todo
static int log_level = 1000; //0;

static int (*printf_function)( const char *, ... ) = printf;

Expand Down
27 changes: 24 additions & 3 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,16 @@ void test_client_server_messages()

for ( int iteration = 0; iteration < 2; ++iteration )
{
// connect and wait until connection completes

// todo
printf( "iteration %d\n", iteration );

client.InsecureConnect( privateKey, clientId, serverAddress );

// todo
printf( "A\n" );

const int NumIterations = 10000;

for ( int i = 0; i < NumIterations; ++i )
Expand All @@ -1386,12 +1394,19 @@ void test_client_server_messages()
break;
}

// todo
printf( "B\n" );

// verify connection has completed successfully

check( !client.IsConnecting() );
check( client.IsConnected() );
check( server.GetNumConnectedClients() == 1 );
check( client.GetClientIndex() == 0 );
check( server.IsClientConnected(0) );

// send a bunch of messages and pump until they are received

const int NumMessagesSent = config.channel[0].messageSendQueueSize;

SendClientToServerMessages( client, NumMessagesSent );
Expand All @@ -1403,14 +1418,18 @@ void test_client_server_messages()

for ( int i = 0; i < NumIterations; ++i )
{
if ( !client.IsConnected() )
break;

Client * clients[] = { &client };
Server * servers[] = { &server };

PumpClientServerUpdate( time, clients, 1, servers, 1 );

if ( !client.IsConnected() )
{
// todo
printf( "client is not connected\n" );
break;
}

ProcessServerToClientMessages( client, numMessagesReceivedFromServer );

ProcessClientToServerMessages( server, client.GetClientIndex(), numMessagesReceivedFromClient );
Expand All @@ -1424,6 +1443,8 @@ void test_client_server_messages()
check( numMessagesReceivedFromClient == NumMessagesSent );
check( numMessagesReceivedFromServer == NumMessagesSent );

// disconnect and pump until client disconnects

client.Disconnect();

for ( int i = 0; i < NumIterations; ++i )
Expand Down

0 comments on commit f7d256b

Please sign in to comment.