Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/TurnManager.h
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
Lint: Inaccurate Copyright Year: Inaccurate Copyright Year | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 37 Lines | |||||
* To ensure a consistent execution of commands, they are each associated with a | * To ensure a consistent execution of commands, they are each associated with a | ||||
* client session ID (which is globally unique and consistent), which is used to sort them. | * client session ID (which is globally unique and consistent), which is used to sort them. | ||||
*/ | */ | ||||
/** | /** | ||||
* Default turn length in SP & MP. | * Default turn length in SP & MP. | ||||
* This value should be as low as possible, while not introducing un-necessary lag. | * This value should be as low as possible, while not introducing un-necessary lag. | ||||
*/ | */ | ||||
inline constexpr u32 DEFAULT_TURN_LENGTH = 200; | inline constexpr u32 DEFAULT_TURN_LENGTH = 250; | ||||
/** | /** | ||||
* In single-player, commands are directly scheduled for the next turn. | * In single-player, commands are directly scheduled for the next turn. | ||||
*/ | */ | ||||
inline constexpr u32 COMMAND_DELAY_SP = 1; | inline constexpr u32 COMMAND_DELAY_SP = 1; | ||||
/** | /** | ||||
* In multi-player, clients can only compute turn N if all clients have finished sending commands for it, | * In multi-player, clients can only compute turn N if all clients have finished sending commands for it, | ||||
* i.e. N < CurrentTurn + COMMAND_DELAY for all clients. | * i.e. N < CurrentTurn + COMMAND_DELAY for all clients. | ||||
* Commands are sent from client to server to client, and both client and network can lag. | * Commands are sent from client to server to client, and both client and network can lag. | ||||
* If a client reaches turn CURRENT_TURN + COMMAND_DELAY - 1, it'll freeze while waiting for commands. | * If a client reaches turn CURRENT_TURN + COMMAND_DELAY - 1, it'll freeze while waiting for commands. | ||||
* To avoid that, we increase the command-delay to make sure that in general players will have received all commands | * To avoid that, we increase the command-delay to make sure that in general players will have received all commands | ||||
* by the time they reach a given turn. Keep in mind the minimum delay is one turn. | * by the time they reach a given turn. Keep in mind the minimum delay is one turn. | ||||
* This value should be as low as possible while avoiding 'freezing' in general usage. | * This value should be as low as possible while avoiding 'freezing' in general usage. | ||||
* TODO: | * TODO: | ||||
* - this command-delay could vary based on server-client pings | * - this command-delay could vary based on server-client pings | ||||
* - it ought be possible to send commands in a P2P fashion (with server verification), which would lower the ping. | * - it ought be possible to send commands in a P2P fashion (with server verification), which would lower the ping. | ||||
*/ | */ | ||||
inline constexpr u32 COMMAND_DELAY_MP = 4; | inline constexpr u32 COMMAND_DELAY_MP = 3; | ||||
/** | /** | ||||
* Common turn system (used by clients and offline games). | * Common turn system (used by clients and offline games). | ||||
*/ | */ | ||||
class CTurnManager | class CTurnManager | ||||
{ | { | ||||
NONCOPYABLE(CTurnManager); | NONCOPYABLE(CTurnManager); | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Inaccurate Copyright Year