Where do I put the code in my project for lock-step system using Photon PUN, Unity Engine?

Thanks so much for any 2 cents on this topic. I am working on an RTS game that is 2player, and I am looking to ensure that actions are properly executed at the same server time on both clients (deterministic, lock-step system). I can not afford Photon Quantum, and I am almost 100% convinced that I don't need it for my purposes either, not even close. This is because the population cap (for units) for each player is only about 150 units, and there is NO PATHFINDING in this game. So I figure, with 300 units that simply move in literally one direction and stop when enemies are in sight (yes, this means NO micro either), that this game should in theory be astoundingly network friendly and responsive. PhotonTransformView handles and sync's precise unit position just fine. So what's the problem? Well, still need to ensure that units start firing at the same server time on both clients so that engagements and health end up looking equivalent. So, still need a lockstep system, or at least one that just caches/confirms firing actions from units in the right order.

THE QUESTION: where would this sort of code go in a project using Photon PUN? I fully get what this system needs to do, compare ping and average FPS, cache/buffer firing actions with timestamps, etc... but what am I throwing this kind of script on exactly? Do I have to edit built-in Photon scripts? Do I just throw this 'LockstepManager' script on a singular networked game object in the room that receives and executes commands for both players? In my session obviously there is the host, and one client. Should only the host run this code? How did this work back when TrueSync was around? Any suggestions? Really hope I gave enough info here.

Fun fact: you may think this RTS sounds boring or simplistic with no micro, but the units are actually fully customizable robots built from lists of parts. Using a permutations calculator, there are upwards of 5.4 trillion unique RTS units you can make in this 1v1 multiplayer game.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @NimbleSprite,

    Thank you for choosing Photon!

    where would this sort of code go in a project using Photon PUN?
    anywhere, I think what you are making can be independent from the lower level "networking middleware" which could be considered as a "transport layer". In this case, it's PUN or just Photon Realtime.

    I think it's better to use Photon Realtime (LoadBalancing API) since PUN adds some features that you may not need or could have some limitations for the kind of game you want. I think Photon Realtime is more generic and flexible.

    Do I have to edit built-in Photon scripts?
    No. No need unless absolutely necessary and you could talk to us and maybe we make the changes in the package officially if it's worth it.

    Do I just throw this 'LockstepManager' script on a singular networked game object in the room that receives and executes commands for both players? In my session obviously there is the host, and one client. Should only the host run this code? How did this work back when TrueSync was around? Any suggestions?
    I will ask my colleagues to chime on this. However, I want to clarify that in Photon world, other than Bolt, there is no "host" client per se, all clients connect to dedicated servers.
  • Hi,

    There's a lot more to determinism (even just with simple lock stepping).
    - With both TrueSync and Quantum we maintain a synchronized clock (from the photon server), so clients don't drift even slightly, which would cause lots of issues with more than two people playing (you need somehow to use one of the machines as the clock source, and make sure you can sync the others from it smoothily - this alone is a lot of work);
    - you need to somehow have a "server" to act as input authority (because if you don't manage/coordinate this, a client problem could make all other clients HALT, and this is the most important problem lockstep systems face in the real world). In both TrueSync and Quantum we used the photon server (a server plugin) for that.
    - you need to make sure your simulation is super super fast (if it isn't either the client lags behind and can't play, or everybody lags behind - there's even a solution for this called time dilation - that we have available in quantum - to make the game run slightly slower if one of the game clients can't run at full speed).

    Unfortunately, explaining all it goes to implement a determinsitic framework is out of the scope of a message here. In the end, it took us 3+ years to implement Quantum to it's full potential (and we're still adding features every month) with a team of engineers.

    Certainly you can implement a very very simple lockstepping system on top of PUN (Quantum uses Photon Realtime/PUN as transport layer), and there are good resources about the topic online. However, unless you really know what you are doing (writing and engine, not a game), it will take you more time/resources than necessary.

    Those are my 2 cents.