Tune "Connecting to server" and "Waiting content" screens

master
Perttu Ahola 2012-03-10 23:28:51 +02:00
parent 967f25461b
commit 2de8f915f8
1 changed files with 40 additions and 34 deletions

View File

@ -709,7 +709,7 @@ void the_game(
server->start(port); server->start(port);
} }
{ // Client scope do{ // Client scope (breakable do-while(0))
/* /*
Create client Create client
@ -738,10 +738,9 @@ void the_game(
catch(ResolveError &e) catch(ResolveError &e)
{ {
errorstream<<"Couldn't resolve address"<<std::endl; errorstream<<"Couldn't resolve address"<<std::endl;
//return 0;
error_message = L"Couldn't resolve address"; error_message = L"Couldn't resolve address";
//gui_loadingtext->remove(); // Break out of client scope
return; break;
} }
/* /*
@ -757,11 +756,12 @@ void the_game(
Wait for server to accept connection Wait for server to accept connection
*/ */
bool could_connect = false; bool could_connect = false;
bool connect_aborted = false;
try{ try{
float frametime = 0.033; float frametime = 0.033;
const float timeout = 10.0;
float time_counter = 0.0; float time_counter = 0.0;
for(;;) input->clear();
while(device->run())
{ {
// Update client and server // Update client and server
client.step(frametime); client.step(frametime);
@ -774,16 +774,21 @@ void the_game(
break; break;
} }
// Break conditions // Break conditions
if(client.accessDenied()) if(client.accessDenied()){
error_message = L"Access denied. Reason: "
+client.accessDeniedReason();
break; break;
if(time_counter >= timeout) }
if(input->wasKeyDown(EscapeKey)){
connect_aborted = true;
break; break;
}
// Display status // Display status
std::wostringstream ss; std::wostringstream ss;
ss<<L"Connecting to server... (timeout in "; ss<<L"Connecting to server... (press Escape to cancel)\n";
ss<<(int)(timeout - time_counter + 1.0); std::wstring animation = L"/-\\|";
ss<<L" seconds)"; ss<<animation[(int)(time_counter/0.2)%4];
draw_load_screen(ss.str(), driver, font); draw_load_screen(ss.str(), driver, font);
// Delay a bit // Delay a bit
@ -797,32 +802,23 @@ void the_game(
/* /*
Handle failure to connect Handle failure to connect
*/ */
if(could_connect == false) if(!could_connect){
{ if(error_message == L"" && !connect_aborted)
if(client.accessDenied()) error_message = L"Connection failed";
{ // Break out of client scope
error_message = L"Access denied. Reason: " break;
+client.accessDeniedReason();
errorstream<<wide_to_narrow(error_message)<<std::endl;
}
else
{
error_message = L"Connection timed out.";
errorstream<<"Timed out."<<std::endl;
}
//gui_loadingtext->remove();
return;
} }
/* /*
Wait until content has been received Wait until content has been received
*/ */
bool got_content = false; bool got_content = false;
bool content_aborted = false;
{ {
float frametime = 0.033; float frametime = 0.033;
const float timeout = 30.0;
float time_counter = 0.0; float time_counter = 0.0;
for(;;) input->clear();
while(device->run())
{ {
// Update client and server // Update client and server
client.step(frametime); client.step(frametime);
@ -837,16 +833,18 @@ void the_game(
break; break;
} }
// Break conditions // Break conditions
if(!client.connectedAndInitialized()) if(!client.connectedAndInitialized()){
error_message = L"Client disconnected";
break; break;
if(time_counter >= timeout) }
if(input->wasKeyDown(EscapeKey)){
content_aborted = true;
break; break;
}
// Display status // Display status
std::wostringstream ss; std::wostringstream ss;
ss<<L"Waiting content... (continuing anyway in "; ss<<L"Waiting content... (press Escape to cancel)\n";
ss<<(int)(timeout - time_counter + 1.0);
ss<<L" seconds)\n";
ss<<(client.itemdefReceived()?L"[X]":L"[ ]"); ss<<(client.itemdefReceived()?L"[X]":L"[ ]");
ss<<L" Item definitions\n"; ss<<L" Item definitions\n";
@ -864,6 +862,13 @@ void the_game(
} }
} }
if(!got_content){
if(error_message == L"" && !content_aborted)
error_message = L"Something failed";
// Break out of client scope
break;
}
/* /*
After all content has been received: After all content has been received:
Update cached textures, meshes and materials Update cached textures, meshes and materials
@ -2585,7 +2590,8 @@ void the_game(
chat_backend.addMessage(L"", L"# Disconnected."); chat_backend.addMessage(L"", L"# Disconnected.");
chat_backend.addMessage(L"", L""); chat_backend.addMessage(L"", L"");
} // Client scope (must be destructed before destructing *def and tsrc // Client scope (client is destructed before destructing *def and tsrc)
}while(0);
delete tsrc; delete tsrc;
delete nodedef; delete nodedef;