python_
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks :)
Hope that helps,
Andrew