Hey guys, I’m pretty far into making a networked top-down shooter but I feel that my code has begun to suffer from crude code done by myself to keep the code working together on different threads. In simple terms, here’s the main concern: I have a thread (clientListener) that receives messages from the server and that will thus have to interpret those messages. I have a main class called Main (clever eh?) that contains the main game loop and the menu system for connecting to the desired server. My problem is that I need to find out on the main thread if the client was accepted by the server which would be on the main thread to figure if it should then prepare the screen for running the game. What is a good way to do so?
Here’s the current code running on the main thread
clientListener.setupForWait(); // Resets the waitingForResponse, acceptedByServer, etc...
statusLabel.setText("Contacting server....");
while(clientListener.waitingForResponse) { Thread.yield(); }
if(clientListener.acceptedByServer) {
// Removes all of the connect components
// Will load map instructed to by server and display that
this.removeAll();
} else {
statusLabel.setText("Rejected from Server: "+clientListener.reason);
}
It works, but it seems ugly. Any suggestions?