diff --git a/include/yojimbo_config.h b/include/yojimbo_config.h index 12954043..e3fabc08 100644 --- a/include/yojimbo_config.h +++ b/include/yojimbo_config.h @@ -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) @@ -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 diff --git a/netcode/netcode.c b/netcode/netcode.c index ac7963d8..83b12370 100755 --- a/netcode/netcode.c +++ b/netcode/netcode.c @@ -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]; @@ -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 @@ -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; @@ -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); } } } diff --git a/source/yojimbo_base_client.cpp b/source/yojimbo_base_client.cpp index eab88c26..0b9ec1be 100644 --- a/source/yojimbo_base_client.cpp +++ b/source/yojimbo_base_client.cpp @@ -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; @@ -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 ); @@ -59,6 +65,9 @@ namespace yojimbo void BaseClient::Disconnect() { + // todo + printf( "BaseClient::Disconnect\n" ); + SetClientState( CLIENT_STATE_DISCONNECTED ); Reset(); } @@ -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 ); @@ -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 ); diff --git a/source/yojimbo_client.cpp b/source/yojimbo_client.cpp index 67223b1d..ccf65de3 100644 --- a/source/yojimbo_client.cpp +++ b/source/yojimbo_client.cpp @@ -10,6 +10,9 @@ 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; @@ -17,6 +20,9 @@ namespace yojimbo Client::~Client() { + // todo + printf( "Client::~Client\n" ); + // IMPORTANT: Please disconnect the client before destroying it yojimbo_assert( m_client == NULL ); } @@ -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 ); @@ -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(); @@ -100,6 +112,9 @@ namespace yojimbo void Client::Disconnect() { + // todo + printf( "Client::Disconnect\n" ); + BaseClient::Disconnect(); DestroyClient(); DestroyInternal(); @@ -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 ); } diff --git a/source/yojimbo_platform.cpp b/source/yojimbo_platform.cpp index ba285376..85551c6a 100644 --- a/source/yojimbo_platform.cpp +++ b/source/yojimbo_platform.cpp @@ -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; diff --git a/test.cpp b/test.cpp index 483ef565..8772e113 100644 --- a/test.cpp +++ b/test.cpp @@ -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 ) @@ -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 ); @@ -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 ); @@ -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 )