Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently in the planning stages for a 2D game for mobile devices which I will be making in C++ using cocos2d-x. The game will be turn based and each turn will have a phase in which the physics simulations will take place. It will also be cross-platform.

I am new to multiplayer networking and am wondering what the best way to synch the physics would be since Box2d does not behave exactly the same on different devices.

The simulation does not have to occur simultaneously on each device but I do need the results to be exactly the same. Ideally the players will be able to witness, on their own device, the same physics simulation( i.e. motion, bouncing, collisions ) and result that occurred during their opponents turn whenever they decide to start their own turn.

What would be the best way to do this? From my research I've come up with a couple of solutions. Should I write some server code on which I would take user input and handle all of the physics simulation, then send the results to each device? or is there a way I could handle the simulation on one device and send all of the information to the other?

Also how exactly does one send everything that happens during a simulation through the network since I can not run the simulation on each device and be guaranteed the same results? Would I just update the server( or device ) with information of what occurs during every few TimeSteps?

share|improve this question
    
Also I would consider setting up my own collision detection/physics if that is a better method –  ash Feb 28 '12 at 4:02
add comment

1 Answer 1

If you want to simulate everything on a server then you better have lots of resources, but you can use a peer model with mobile devices if you have a way to exchange connection information.

I created a multiplayer flash game using Box2D and Cirrus. It was a turn based game as well. Cirrus is a peer-peer model but I wrote some server code for bookkeeping - determining who playing in which 'room', scoreboards etc. The peers would decide who plays which turn by randomly 'drawing straws' and comparing. The client who's turn was the current turn would broadcast its 'move' to the other clients. Simulation would then happen in each client seperately.

The main problem I faced was client disconnections and inaccuracies in simulation in each of the clients. Once in five times there would be slight variations in simulation and the position of one player would be different in the different clients. I tried to solve it by making the clients broadcast their own positions to its peers after each turn was done simulating, but it did not look great since in some clients the position was so dramatically different that it looked jerky. Worse case was when one player was 'dead' in some clients but not on some others.

Simulating in a client whose turn is now and then broadcasting to others the results of simulation might work, if there are no strict time constraints. You should always consider disconnections at every stage.

share|improve this answer
    
Because it is a turn-based game, buffering may be used to reduce network issues and smooth the playback of the physics simulation in other devices. –  SkimFlux Feb 28 '12 at 12:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.