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

Function NetworkExecuteLocalCommandQueue

src/network/network_command.cpp:256–285  ·  view source on GitHub ↗

* Execute all commands on the local command queue that ought to be executed this frame. */

Source from the content-addressed store, hash-verified

254 * Execute all commands on the local command queue that ought to be executed this frame.
255 */
256void NetworkExecuteLocalCommandQueue()
257{
258 assert(IsLocalCompany());
259
260 CommandQueue &queue = (_network_server ? _local_execution_queue : ClientNetworkGameSocketHandler::my_client->incoming_queue);
261
262 auto cp = queue.begin();
263 for (; cp != queue.end(); cp++) {
264 /* The queue is always in order, which means
265 * that the first element will be executed first. */
266 if (_frame_counter < cp->frame) break;
267
268 if (_frame_counter > cp->frame) {
269 /* If we reach here, it means for whatever reason, we've already executed
270 * past the command we need to execute. */
271 FatalError("[net] Trying to execute a packet in the past!");
272 }
273
274 /* We can execute this command */
275 _current_company = cp->company;
276 size_t cb_index = FindCallbackIndex(cp->callback);
277 assert(cb_index < _callback_tuple_size);
278 assert(_cmd_dispatch[cp->cmd].Unpack[cb_index] != nullptr);
279 _cmd_dispatch[cp->cmd].Unpack[cb_index](*cp);
280 }
281 queue.erase(queue.begin(), cp);
282
283 /* Local company may have changed, so we should not restore the old value */
284 _current_company = _local_company;
285}
286
287/**
288 * Free the local command queues.

Callers 2

NetworkGameLoopFunction · 0.85
network_client.cppFile · 0.85

Calls 5

IsLocalCompanyFunction · 0.85
FindCallbackIndexFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected