@@ -153,8 +153,6 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
153
153
" waiting for server" , " default" , fge::Vector2f{}, 15 );
154
154
latencyText->setFillColor (fge::Color::Black);
155
155
156
- bool connectionValid = false ;
157
-
158
156
// Lambda that create a GUI window for connection
159
157
auto createConnectionWindow = [&]() {
160
158
// First check if the window already exists
@@ -203,27 +201,6 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
203
201
204
202
isConnecting = true ;
205
203
futureConnect = server.connect ();
206
- futureConnect.wait (); // TODO: remove this wait
207
- isConnecting = false ;
208
-
209
- if (!futureConnect.get ())
210
- {
211
- server.stop ();
212
- std::cout << " can't connect to the server !" << std::endl;
213
- return ;
214
- }
215
-
216
- std::cout << " connection ok" << std::endl;
217
-
218
- server.enableReturnPacket (true );
219
-
220
- auto transmissionPacket = fge::net::CreatePacket (ls::LS_PROTOCOL_C_PLEASE_CONNECT_ME);
221
- transmissionPacket->doNotDiscard ().doNotReorder () << LIFESIM_CONNECTION_TEXT1 << LIFESIM_CONNECTION_TEXT2;
222
-
223
- // Ask the server thread to automatically update the timestamp just before sending it
224
- server._client ._latencyPlanner .pack (transmissionPacket);
225
-
226
- server._client .pushPacket (std::move (transmissionPacket));
227
204
});
228
205
};
229
206
@@ -240,8 +217,6 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
240
217
server._onClientTimeout .addLambda ([&]([[maybe_unused]] fge::net::ClientSideNetUdp& client) {
241
218
std::cout << " connection lost ! (timeout)" << std::endl;
242
219
243
- connectionValid = false ;
244
-
245
220
server.stop ();
246
221
mainScene->delAllObject (true );
247
222
createConnectionWindow ();
@@ -275,17 +250,30 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
275
250
// Check if the connection is unsuccessful
276
251
if (isConnecting && futureConnect.wait_for (std::chrono::milliseconds::zero ()) == std::future_status::ready)
277
252
{
253
+ isConnecting = false ;
254
+
278
255
if (!futureConnect.get ())
279
256
{
280
- std::cout << " no response (timeout) !" << std::endl;
281
-
282
- connectionValid = false ;
257
+ std::cout << " can't connect to the server !" << std::endl;
283
258
284
259
server.stop ();
285
260
mainScene->delAllObject (true );
286
261
createConnectionWindow ();
262
+ }
263
+ else
264
+ {
265
+ std::cout << " connection ok" << std::endl;
266
+
267
+ server.enableReturnPacket (true );
287
268
288
- isConnecting = false ;
269
+ auto transmissionPacket = fge::net::CreatePacket (ls::LS_PROTOCOL_C_PLEASE_CONNECT_ME);
270
+ transmissionPacket->doNotDiscard ().doNotReorder ()
271
+ << LIFESIM_CONNECTION_TEXT1 << LIFESIM_CONNECTION_TEXT2;
272
+
273
+ // Ask the server thread to automatically update the timestamp just before sending it
274
+ server._client ._latencyPlanner .pack (transmissionPacket);
275
+
276
+ server._client .pushPacket (std::move (transmissionPacket));
289
277
}
290
278
}
291
279
@@ -330,8 +318,6 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
330
318
{
331
319
mainScene->delObject (windowObject->getSid ());
332
320
}
333
- connectionValid = true ;
334
-
335
321
std::cout << " connected to server !" << std::endl;
336
322
}
337
323
else
0 commit comments