int main( int argc, char * argv[] ) { // initialize and create transport TransportType type = Transport_LAN; if ( !Transport::Initialize( Transport_LAN ) ) { printf( "failed to initialize transport layer\n" ); return 1; } Transport * transport = Transport::Create(); if ( !transport ) { printf( "could not create transport\n" ); return 1; } // start server (transport specific) switch ( type ) { case Transport_LAN: { TransportLAN * lan_transport = dynamic_cast<TransportLAN*>( transport ); char hostname[64+1] = "hostname"; TransportLAN::GetHostName( hostname, sizeof(hostname) ); lan_transport->StartServer( hostname ); } break; default: break; } // main loop const float DeltaTime = 1.0f / 30.0f; while ( true ) { transport->Update( DeltaTime ); wait_seconds( DeltaTime ); } // shutdown Transport::Destroy( transport ); Transport::Shutdown(); return 0; }
int main( int argc, char * argv[] ) { // initialize and create transport TransportType type = Transport_LAN; if ( !Transport::Initialize( Transport_LAN ) ) { printf( "failed to initialize transport layer\n" ); return 1; } Transport * transport = Transport::Create(); if ( !transport ) { printf( "could not create transport\n" ); return 1; } // connect to server (transport specific) switch ( type ) { case Transport_LAN: { TransportLAN * lan_transport = dynamic_cast<TransportLAN*>( transport ); if ( argc >= 2 ) lan_transport->ConnectClient( argv[1] ); else { char hostname[64+1]; TransportLAN::GetHostName( hostname, sizeof(hostname) ); lan_transport->ConnectClient( hostname ); } } break; default: break; } // main loop const float DeltaTime = 1.0f / 30.0f; bool connected = false; while ( true ) { if ( type == Transport_LAN ) { TransportLAN * lan_transport = dynamic_cast<TransportLAN*>( transport ); if ( !connected && lan_transport->IsConnected() ) connected = true; if ( connected && !lan_transport->IsConnected() ) { printf( "disconnected\n" ); break; } if ( lan_transport->ConnectFailed() ) { printf( "connect failed\n" ); break; } } transport->Update( DeltaTime ); wait_seconds( DeltaTime ); } // shutdown Transport::Destroy( transport ); Transport::Shutdown(); return 0; }
int main( int argc, char * argv[] ) { // initialize and create transport TransportType type = Transport_LAN; if ( !Transport::Initialize( Transport_LAN ) ) { printf( "failed to initialize transport layer\n" ); return 1; } Transport * transport = Transport::Create(); if ( !transport ) { printf( "could not create transport\n" ); return 1; } // enter lobby (transport specific) switch ( type ) { case Transport_LAN: { TransportLAN * lan_transport = dynamic_cast<TransportLAN*>( transport ); lan_transport->EnterLobby(); } break; default: break; } // main loop const float DeltaTime = 1.0f / 30.0f; float accumulator = 0.0f; while ( true ) { accumulator += DeltaTime; while ( accumulator >= 1.5f ) { switch ( type ) { case Transport_LAN: { TransportLAN * lan_transport = dynamic_cast<TransportLAN*>( transport ); printf( "---------------------------------------------\n" ); const int entryCount = lan_transport->GetLobbyEntryCount(); for ( int i = 0; i < entryCount; ++i ) { TransportLAN::LobbyEntry entry; if ( lan_transport->GetLobbyEntryAtIndex( i, entry ) ) printf( "%s -> %s\n", entry.name, entry.address ); } printf( "---------------------------------------------\n" ); } break; default: break; } accumulator -= 1.5f; } transport->Update( DeltaTime ); wait_seconds( DeltaTime ); } // shutdown Transport::Destroy( transport ); Transport::Shutdown(); return 0; }