Link to home
Start Free TrialLog in
Avatar of python_
python_Flag for United Kingdom of Great Britain and Northern Ireland

asked on

J2ME mutiplayer game loop

Hi,
I'm designing multi player java mobile game. I'm just confused about how the game loop should be designed.

In simplest form there could be a infinite while() loop checking network input and some other events, GPS position, for instance, in each iteration. My question is how to avoid pooling information from threads in this while loop, if I have two threads, one taking care of input from network, another reading location information. If i make callback methods from these child threads to parent thread, they would each invoke separate callback method in parent thread.

I think having a loop pooling results from threads is not a good design, especially on resource limited mobile devices, but I'm not sure is there any other reasonable way in this case, it's my first game :)

For instance:

public class Game implements Runnable{

public void run{
while(!quit){
//game should be controlled from here
}
}

public void updatePosition(byte[] location){
// location thread would call this independently from game loop
}

public void updateNetwork(byte[] message){
// network thread would call this independently from game loop
}

}

In this case I loose centralized control of game from while() loop, because of separate methods being called when new events occur.
What would be the best way how to structure the main game class?

Thanks
Avatar of gam3r_3xtr3m3
gam3r_3xtr3m3
Flag of Philippines image

i'm not pretty sure how you meant by 'avoiding the infinite loop' because a game loop is indeed one, but there shouldn't be any problem if you update your game in the part where the function called affects, like for example using booleans to flag if the values from each update functions are ready for reading.

Hope that helps,

Andrew
ASKER CERTIFIED SOLUTION
Avatar of gam3r_3xtr3m3
gam3r_3xtr3m3
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of python_

ASKER

thanks :)