I'm writing a game for Android to which I want to add a mulitplayer mode (local multiplayer via WiFi/Bluetooth, not online multiplayer via server). I stored the exchange-code between the client devices and the host device in th methods getInput() and pushInput(). I'm currently using a single-threaded gameLoop like this in my singleplayer mode:
public void mainLoopIteration(Canvas c, float deltaTime){
compute(deltaTime);
render(c);
...
}
My question is which of the following ways is the better implementation of the multiplayer "add-ons":
Adding exchange-calls to mainLoopIteration():
public void mainLoopIteration(Canvas c, float deltaTime){ pushInput(); getInput(); compute(deltaTime); render(c); ... }
creating a second thread that handles all the exchange stuff:
public void run(){ while(mainLoopIsRunning){ pushInput(); getInput(); //???Thread.sleep(...); }
}
Which solution you'd suggest or maybe do you suggest a completely other way?
Thx and regards Lisa