Skip to content

Commit

Permalink
Now that the connect is running on a different thread, this code can …
Browse files Browse the repository at this point in the history
…be a bit simpler.
  • Loading branch information
daid committed Oct 5, 2015
1 parent 786acad commit 5798ab3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/menus/mainMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,14 @@ JoinServerScreen::JoinServerScreen(sf::IpAddress ip)
new ServerBrowserMenu();
}))->setPosition(50, -50, ABottomLeft)->setSize(300, 50);

connect_delay = 2;
new GameClient(ip);
}

void JoinServerScreen::update(float delta)
{
//We connect with a slight delay, as the connect call when joining a server will block and thus not update the screen.
if (connect_delay > 0)
if (game_client->isConnecting())
{
connect_delay--;
if (!connect_delay)
new GameClient(ip);
//If we are still trying to connect, do nothing.
}else{
if (!game_client->isConnected())
{
Expand Down Expand Up @@ -228,18 +225,15 @@ void AutoConnectScreen::update(float delta)
{
status_label->setText("Found server " + serverList[0].name);
connect_to_address = serverList[0].address;
connect_delay = 2;
new GameClient(serverList[0].address);
scanner->destroy();
}else{
status_label->setText("Searching for server...");
}
}else{
if (connect_delay > 0)
if (game_client->isConnecting())
{
status_label->setText("Connecting: " + connect_to_address.toString());
connect_delay--;
if (!connect_delay)
new GameClient(connect_to_address);
}else{
if (!game_client->isConnected())
{
Expand Down
2 changes: 0 additions & 2 deletions src/menus/mainMenus.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ServerBrowserMenu : public GuiCanvas
class JoinServerScreen : public GuiCanvas, public Updatable
{
sf::IpAddress ip;
int connect_delay;
public:
JoinServerScreen(sf::IpAddress ip);

Expand All @@ -42,7 +41,6 @@ class AutoConnectScreen : public GuiCanvas, public Updatable
{
P<ServerScanner> scanner;
sf::IpAddress connect_to_address;
int connect_delay;
ECrewPosition crew_position;
bool control_main_screen;

Expand Down

0 comments on commit 5798ab3

Please sign in to comment.