Advertisement

Author Topic: Executing lots of global commands only on server vs. executing them on clients  (Read 588 times)

0 Members and 1 Guest are viewing this topic.

Offline RKurtzDmitriyev

  • Former Staff
  • ****
I didn't know how to search for this, so I'm sorry if this is covered somewhere. I really, really, really hate desync, and I'm trying to optimize my mission for multiplayer.

To illustrate my dilemma, let's start with a simple example. Suppose I want to teleport someone with setPos, using the following code:

Code: [Select]
bob setPos getpos boblogic

I could run that either only on the server or on every computer. Theoretically, both options should give the same result. But I'm not sure which option would be laggier.

On the one hand, if I execute the command only on the server, for a few milliseconds the clients are going to disagree with the server on where bob is. The server is going to have to send out messages to each client to synchronize the location of bob, thus increasing traffic.

On the other hand, if every computer executes that setpos command, it may be that every computer will now send messages to everyone else telling them to update the position, causing even more traffic. And these messages won't be needed because every computer set bob to the same location, anyway.

I don't really know how OFP's netcode works though (except that it often doesn't work well  ;) ). So, can anyone weigh in on whether it would be better to execute such code only on the server or on server and clients? Obviously some global commands (such as createvehicle) should only be run on server, but what about others like setPos?

To be more specific about what I'm facing:

As described in my previous thread, I'm trying to have players start in random locations, and to do this I'm going to need setPos. (Simply grouping to markers or using the placement radius won't work because I want to limit the possible locations, and because I don't want two groups to end up at the same position).

And to make things even more confusing, setPos commands run on one computer during briefing seem to be completely disregarded when they attempt to move other computers' players. (Anti-cheating measure, maybe?) Therefore, either all computers must execute the same setPos commands during initialization or none at all.* I could execute the setPos commands on the server after initialization (say during a titlecut black-out), that seems to work. I'm just not sure which option will lead to the best performance.

I'm also looking at setting a large number of units to a certain skill level, depending on parameters selected by the players during the multiplayer setup screen. I can only suppose that setSkill is global, so once again, I wonder whether it is better to run such commands only on the server or on every client as well. I may want to use other global commands, as well.

Thanks for any help. :cool2:

* Or I suppose I could have each player's computer setpos only their own player, but that would take a lot of brainwork. I'd rather try one of the other options if either is less laggy.
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline faguss

  • Members
  • *
    • Faguss' Website
Setpos, like any other command that affects the world, is global. It is send to all computers so executing on every machine is a waste of bandwidth. It's better to launch it on one machine. In theory, it's best if it would be the server machine (because info doesn't need to be send to server in the first place) but the difference is really tiny.

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Thanks Faguss. I can't remember what I did in the end, but the mission seems reasonably stable (for its size) so whatever I did was at least adequate. :D

Your advice is noted for future reference, though. :good:
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline j0e

  • Members
  • *
    • j0e's home
Very old topic, but still valid.

As fair as I know, there is an important point you must consider with these kind of commands.
They have effect only if the unit, to which is applied, is local to the machine that raises them.

If the server tries to move "Bob" in another location, but he is a teammate of a player, I'm afraid that the player's machine doesn't let him to change pos, restoring his x/y on the network.

This behaviour should be the famous locality.

In the end, not only minimize the number of machines that call functions, but also identify the right ones.