MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DistributeQueue

Function DistributeQueue

src/network/network_command.cpp:326–354  ·  view source on GitHub ↗

* "Send" a particular CommandQueue to all clients. * @param queue The queue of commands that has to be distributed. * @param owner The client that owns the commands, */

Source from the content-addressed store, hash-verified

324 * @param owner The client that owns the commands,
325 */
326static void DistributeQueue(CommandQueue &queue, const NetworkClientSocket *owner)
327{
328#ifdef DEBUG_DUMP_COMMANDS
329 /* When replaying we do not want this limitation. */
330 int to_go = UINT16_MAX;
331#else
332 int to_go = _settings_client.network.commands_per_frame;
333 if (owner == nullptr) {
334 /* This is the server, use the commands_per_frame_server setting if higher */
335 to_go = std::max<int>(to_go, _settings_client.network.commands_per_frame_server);
336 }
337#endif
338
339 /* Not technically the most performant way, but consider clients rarely click more than once per tick. */
340 for (auto cp = queue.begin(); cp != queue.end(); /* removing some items */) {
341 /* Do not distribute commands when paused and the command is not allowed while paused. */
342 if (_pause_mode.Any() && !IsCommandAllowedWhilePaused(cp->cmd)) {
343 ++cp;
344 continue;
345 }
346
347 /* Limit the number of commands per client per tick. */
348 if (--to_go < 0) break;
349
350 DistributeCommandPacket(*cp, owner);
351 NetworkAdminCmdLogging(owner, *cp);
352 cp = queue.erase(cp);
353 }
354}
355
356/** Distribute the commands of ourself and the clients. */
357void NetworkDistributeCommands()

Callers 1

Calls 7

DistributeCommandPacketFunction · 0.85
NetworkAdminCmdLoggingFunction · 0.85
AnyMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected