Author Topic: Code tips for Multiplayer (Skirmish and Co-Op Campaign) + Single + HotSeat  (Read 2593 times)

ArtemKoval

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 10
    • View Profile
Hi!

Do you have any code tips based on your experience with TNet to achieve more or less robust architecture without tons of if Hotseat, if Single, etc. to achieve such different play modes in one code base:

1) single player classic campaign;

2) hotseat skirmish;

3) multiplayer 2-4 players skirmish;

4) multiplayer 2-players campaign

?

For example, if I understand correctly, for hotseat and single I don't need to do any RPC call or network view synchronizations. So Instead of RPC("CalcDamage", player1, player2) it should be just plain CalcDamage(player1, player2). From classic architecture patterns it should be wrapped inside somekind of resolver, which will calculate whether it's single player with AI, hotseat, co-op or general multiplayer (maybe not required to check last pair as separate entities).

Best regards, Artem.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
It's not a good idea to diverge your game paths like that. Stick to doing everything through tno.Send("FuncName", ...);

This way whether you're single player or multi-player, it will work exactly the same. TNet 3 also has an offline mode where it fakes a server in all its functionality, just doesn't use sockets to communicate. It's a bit more efficient than connecting to your own server.

That said, if you are really worried about performance, you can do stuff like:
  1. if (TNManager.isConnected) MyFunc(123);
  2. else tno.Send("MyFunc", Target.All, 123);
... as long as you understand that calling the function directly will not save it on the server. It will only set the local flag. If you don't want to worry, stick to using tno.Send everywhere. The overhead is minimal.