Deterministic Battles (LockStep)

Started by
1 comment, last by conq 9 years, 4 months ago

Hello everyone,

I hope this is the right subforum, I am new here.

I am currently programming a RTS with the focus on multiplayer, using both Unity and my own C++ Engine (just core, no graphics, I still don't trust Unity to be deterministic).

After solving basic problems and now being able to do standard stuff which has no interaction between the players (constructing, walking), I am up to implement the "fights".

My Units walk grid-based to get rid of nasty floats (the animation still has them though, so you don't see the "hopps"), so this seems to be deterministic. But now I need to ensure that fights have always the same way to happen. Currently my Unit have a Combat-Script, but I don't know in which order Unity checks them, so I wanted to write myself a combatmanager, doing all the fights all over the map.

Now I am not sure how to handle problems like the "first hit". When two enemy units encounter, how do can I be sure that always one unit gets off the first hit? Or am I missing something very basically here, because I didn't found anything regarding that on the web.

Advertisement

for deterministic multiplayer you don't need to do what you're doing with ints vs floats.

all you really need to do is use the same seed for all random number gens, and standard game architecture takes care of the rest.

update_all takes the form of:

for each entity: update_entity.

as long as you iterate through the entities in the same order each time - using something like for i=0; i<num_entities; i++; - entity n will always attack before entity n+1, and so on.

make sure your net lag prediction and fixup code is deterministic, and that's pretty much it.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

http://www.box2d.org/forum/viewtopic.php?f=3&t=1800#p16480

Check that out about deterministic floats.

In a lockstep approach, those issues shouldn't be a problem. You need to calculate the simulation in advance, and only display what happened in the past. That way you can be 100% sure all clients match (lockstep).

Frame 1

players give input

Frame 2

Server confirms input

Frame 3

Server executes input, and returns to all players

Frame 4

Server waits for additional input.

So at the end of that, the clients are just see'ing the first frame, really. If there's any kind of desync, you've got a problem in your basic structure. Don't execute any simulation without server input, basically.

This topic is closed to new replies.

Advertisement