Skip to content

Commit f7d256b

Browse files
committed
wip tracking down breaking in most recent version of netcode integrated today
1 parent af6e648 commit f7d256b

File tree

6 files changed

+79
-8
lines changed

6 files changed

+79
-8
lines changed

include/yojimbo_config.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#define YOJIMBO_MAJOR_VERSION 1
3535
#define YOJIMBO_MINOR_VERSION 2
36-
#define YOJIMBO_PATCH_VERSION 4
36+
#define YOJIMBO_PATCH_VERSION 5
3737

3838
#if !defined(YOJIMBO_DEBUG) && !defined(YOJIMBO_RELEASE)
3939
#if defined(NDEBUG)
@@ -66,6 +66,9 @@
6666
#define YOJIMBO_PLATFORM YOJIMBO_PLATFORM_UNIX
6767
#endif
6868

69+
// todo
70+
#define YOJIMBO_DEBUG 1
71+
6972
#ifdef YOJIMBO_DEBUG
7073

7174
#define YOJIMBO_DEBUG_MEMORY_LEAKS 1

netcode/netcode.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ void netcode_set_assert_function( void (*function)( NETCODE_CONST char *, NETCOD
121121

122122
void netcode_printf( int level, NETCODE_CONST char * format, ... )
123123
{
124-
if ( level > log_level )
125-
return;
124+
// todo
125+
(void) level;
126+
// if ( level > log_level )
127+
// return;
126128
va_list args;
127129
va_start( args, format );
128130
char buffer[4*1024];
@@ -3112,6 +3114,9 @@ void netcode_client_send_packet_to_server_internal( struct netcode_client_t * cl
31123114

31133115
if ( client->config.network_simulator )
31143116
{
3117+
// todo
3118+
printf( "sent packet through network simulator\n" );
3119+
31153120
netcode_network_simulator_send_packet( client->config.network_simulator, &client->address, &client->server_address, packet_data, packet_bytes );
31163121
}
31173122
else
@@ -3180,7 +3185,7 @@ void netcode_client_send_packets( struct netcode_client_t * client )
31803185
if ( client->last_packet_send_time + ( 1.0 / NETCODE_PACKET_SEND_RATE ) >= client->time )
31813186
return;
31823187

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

31853190
struct netcode_connection_keep_alive_packet_t packet;
31863191
packet.packet_type = NETCODE_CONNECTION_KEEP_ALIVE_PACKET;
@@ -4953,6 +4958,10 @@ void netcode_server_check_for_timeouts( struct netcode_server_t * server )
49534958
{
49544959
netcode_printf( NETCODE_LOG_LEVEL_INFO, "server timed out client %d\n", i );
49554960
netcode_server_disconnect_client_internal( server, i, 0 );
4961+
4962+
// todo
4963+
printf( "*** BROKEN ***\n" );
4964+
exit(1);
49564965
}
49574966
}
49584967
}

source/yojimbo_base_client.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace yojimbo
3434
{
3535
BaseClient::BaseClient( Allocator & allocator, const ClientServerConfig & config, Adapter & adapter, double time ) : m_config( config )
3636
{
37+
// todo
38+
printf( "BaseClient::BaseClient\n" );
39+
3740
m_allocator = &allocator;
3841
m_adapter = &adapter;
3942
m_time = time;
@@ -51,6 +54,9 @@ namespace yojimbo
5154

5255
BaseClient::~BaseClient()
5356
{
57+
// todo
58+
printf( "BaseClient::~BaseClient\n" );
59+
5460
// IMPORTANT: Please disconnect the client before destroying it
5561
yojimbo_assert( m_clientState <= CLIENT_STATE_DISCONNECTED );
5662
YOJIMBO_FREE( *m_allocator, m_packetBuffer );
@@ -59,6 +65,9 @@ namespace yojimbo
5965

6066
void BaseClient::Disconnect()
6167
{
68+
// todo
69+
printf( "BaseClient::Disconnect\n" );
70+
6271
SetClientState( CLIENT_STATE_DISCONNECTED );
6372
Reset();
6473
}
@@ -127,6 +136,9 @@ namespace yojimbo
127136

128137
void BaseClient::CreateInternal()
129138
{
139+
// todo
140+
printf( "BaseClient::CreateInternal\n" );
141+
130142
yojimbo_assert( m_allocator );
131143
yojimbo_assert( m_adapter );
132144
yojimbo_assert( m_clientMemory == NULL );
@@ -137,6 +149,10 @@ namespace yojimbo
137149
m_messageFactory = m_adapter->CreateMessageFactory( *m_clientAllocator );
138150
m_connection = YOJIMBO_NEW( *m_clientAllocator, Connection, *m_clientAllocator, *m_messageFactory, m_config, m_time );
139151
yojimbo_assert( m_connection );
152+
153+
// todo
154+
printf( "m_connection = %p\n", m_connection );
155+
140156
if ( m_config.networkSimulator )
141157
{
142158
m_networkSimulator = YOJIMBO_NEW( *m_clientAllocator, NetworkSimulator, *m_clientAllocator, m_config.maxSimulatorPackets, m_time );

source/yojimbo_client.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ namespace yojimbo
1010
Client::Client( Allocator & allocator, const Address & address, const ClientServerConfig & config, Adapter & adapter, double time )
1111
: BaseClient( allocator, config, adapter, time ), m_config( config ), m_address( address )
1212
{
13+
// todo
14+
printf( "Client::Client\n" );
15+
1316
m_clientId = 0;
1417
m_client = NULL;
1518
m_boundAddress = m_address;
1619
}
1720

1821
Client::~Client()
1922
{
23+
// todo
24+
printf( "Client::~Client\n" );
25+
2026
// IMPORTANT: Please disconnect the client before destroying it
2127
yojimbo_assert( m_client == NULL );
2228
}
@@ -28,6 +34,9 @@ namespace yojimbo
2834

2935
void Client::InsecureConnect( const uint8_t privateKey[], uint64_t clientId, const Address serverAddresses[], int numServerAddresses )
3036
{
37+
// todo
38+
printf( "Client::InsecureConnect\n" );
39+
3140
yojimbo_assert( serverAddresses );
3241
yojimbo_assert( numServerAddresses > 0 );
3342
yojimbo_assert( numServerAddresses <= NETCODE_MAX_SERVERS_PER_CONNECT );
@@ -82,6 +91,9 @@ namespace yojimbo
8291

8392
void Client::Connect( uint64_t clientId, uint8_t * connectToken )
8493
{
94+
// todo
95+
printf( "Client::Connect\n" );
96+
8597
yojimbo_assert( connectToken );
8698
Disconnect();
8799
CreateInternal();
@@ -100,6 +112,9 @@ namespace yojimbo
100112

101113
void Client::Disconnect()
102114
{
115+
// todo
116+
printf( "Client::Disconnect\n" );
117+
103118
BaseClient::Disconnect();
104119
DestroyClient();
105120
DestroyInternal();
@@ -146,11 +161,17 @@ namespace yojimbo
146161
const int state = netcode_client_state( m_client );
147162
if ( state < NETCODE_CLIENT_STATE_DISCONNECTED )
148163
{
164+
// todo
165+
printf( "error state %d\n", state );
166+
149167
Disconnect();
150168
SetClientState( CLIENT_STATE_ERROR );
151169
}
152170
else if ( state == NETCODE_CLIENT_STATE_DISCONNECTED )
153171
{
172+
// todo
173+
printf( "set disconnected state %d\n", state );
174+
154175
Disconnect();
155176
SetClientState( CLIENT_STATE_DISCONNECTED );
156177
}

source/yojimbo_platform.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ static void default_assert_handler( const char * condition, const char * functio
4040
#endif
4141
}
4242

43-
static int log_level = 0;
43+
// todo
44+
static int log_level = 1000; //0;
4445

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

test.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -1368,8 +1368,16 @@ void test_client_server_messages()
13681368

13691369
for ( int iteration = 0; iteration < 2; ++iteration )
13701370
{
1371+
// connect and wait until connection completes
1372+
1373+
// todo
1374+
printf( "iteration %d\n", iteration );
1375+
13711376
client.InsecureConnect( privateKey, clientId, serverAddress );
13721377

1378+
// todo
1379+
printf( "A\n" );
1380+
13731381
const int NumIterations = 10000;
13741382

13751383
for ( int i = 0; i < NumIterations; ++i )
@@ -1386,12 +1394,19 @@ void test_client_server_messages()
13861394
break;
13871395
}
13881396

1397+
// todo
1398+
printf( "B\n" );
1399+
1400+
// verify connection has completed successfully
1401+
13891402
check( !client.IsConnecting() );
13901403
check( client.IsConnected() );
13911404
check( server.GetNumConnectedClients() == 1 );
13921405
check( client.GetClientIndex() == 0 );
13931406
check( server.IsClientConnected(0) );
13941407

1408+
// send a bunch of messages and pump until they are received
1409+
13951410
const int NumMessagesSent = config.channel[0].messageSendQueueSize;
13961411

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

14041419
for ( int i = 0; i < NumIterations; ++i )
14051420
{
1406-
if ( !client.IsConnected() )
1407-
break;
1408-
14091421
Client * clients[] = { &client };
14101422
Server * servers[] = { &server };
14111423

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

1426+
if ( !client.IsConnected() )
1427+
{
1428+
// todo
1429+
printf( "client is not connected\n" );
1430+
break;
1431+
}
1432+
14141433
ProcessServerToClientMessages( client, numMessagesReceivedFromServer );
14151434

14161435
ProcessClientToServerMessages( server, client.GetClientIndex(), numMessagesReceivedFromClient );
@@ -1424,6 +1443,8 @@ void test_client_server_messages()
14241443
check( numMessagesReceivedFromClient == NumMessagesSent );
14251444
check( numMessagesReceivedFromServer == NumMessagesSent );
14261445

1446+
// disconnect and pump until client disconnects
1447+
14271448
client.Disconnect();
14281449

14291450
for ( int i = 0; i < NumIterations; ++i )

0 commit comments

Comments
 (0)