Move state frequency to ServerConfig which clients can adapt
This commit is contained in:
parent
c46a5eafdb
commit
e38edaae2c
@ -57,6 +57,7 @@ NetworkConfig::NetworkConfig()
|
||||
0 : stk_config->m_client_port;
|
||||
m_joined_server_version = 0;
|
||||
m_network_ai_tester = false;
|
||||
m_state_frequency = 10;
|
||||
} // NetworkConfig
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -90,6 +90,9 @@ private:
|
||||
|
||||
uint32_t m_joined_server_version;
|
||||
|
||||
/** Set by client or server which is required to be the same. */
|
||||
int m_state_frequency;
|
||||
|
||||
public:
|
||||
/** Singleton get, which creates this object if necessary. */
|
||||
static NetworkConfig *get()
|
||||
@ -222,6 +225,10 @@ public:
|
||||
uint32_t getJoinedServerVersion() const { return m_joined_server_version; }
|
||||
// ------------------------------------------------------------------------
|
||||
void clearActivePlayersForClient() const;
|
||||
// ------------------------------------------------------------------------
|
||||
void setStateFrequency(int frequency) { m_state_frequency = frequency; }
|
||||
// ------------------------------------------------------------------------
|
||||
int getStateFrequency() const { return m_state_frequency; }
|
||||
}; // class NetworkConfig
|
||||
|
||||
#endif // HEADER_NETWORK_CONFIG
|
||||
|
@ -268,7 +268,6 @@ void ClientLobby::addAllPlayers(Event* event)
|
||||
float time_limit = data.getFloat();
|
||||
m_game_setup->setHitCaptureTime(hit_capture_limit, time_limit);
|
||||
}
|
||||
|
||||
configRemoteKart(players);
|
||||
loadWorld();
|
||||
// Disable until render gui during loading is bug free
|
||||
@ -523,6 +522,8 @@ void ClientLobby::connectionAccepted(Event* event)
|
||||
m_auto_started = false;
|
||||
m_state.store(CONNECTED);
|
||||
float auto_start_timer = data.getFloat();
|
||||
int state_frequency_in_server = data.getUInt32();
|
||||
NetworkConfig::get()->setStateFrequency(state_frequency_in_server);
|
||||
if (auto_start_timer != std::numeric_limits<float>::max())
|
||||
NetworkingLobby::getInstance()->setStartingTimerTo(auto_start_timer);
|
||||
} // connectionAccepted
|
||||
|
@ -1812,7 +1812,8 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
|
||||
(m_timeout.load() - (int64_t)StkTime::getRealTimeMs()) / 1000.0f;
|
||||
}
|
||||
message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId())
|
||||
.addUInt32(ServerConfig::m_server_version).addFloat(auto_start_timer);
|
||||
.addUInt32(ServerConfig::m_server_version).addFloat(auto_start_timer)
|
||||
.addUInt32(ServerConfig::m_state_frequency);
|
||||
|
||||
if (game_started)
|
||||
{
|
||||
|
@ -80,8 +80,8 @@ void RewindManager::reset()
|
||||
m_not_rewound_ticks.store(0);
|
||||
m_overall_state_size = 0;
|
||||
m_last_saved_state = -1; // forces initial state save
|
||||
m_state_frequency =
|
||||
stk_config->getPhysicsFPS() / stk_config->m_network_state_frequeny;
|
||||
m_state_frequency = stk_config->getPhysicsFPS() /
|
||||
NetworkConfig::get()->getStateFrequency();
|
||||
|
||||
if (!m_enable_rewind_manager) return;
|
||||
|
||||
|
@ -34,6 +34,7 @@ static std::vector<UserConfigParam*> g_server_params;
|
||||
#include "config/stk_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/protocols/lobby_protocol.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
@ -256,6 +257,16 @@ void loadServerLobbyFromConfig()
|
||||
if (unsupportedGameMode())
|
||||
Log::fatal("ServerConfig", "Unsupported game mode");
|
||||
|
||||
int frequency_in_config = m_state_frequency;
|
||||
if (frequency_in_config > stk_config->getPhysicsFPS())
|
||||
{
|
||||
Log::warn("ServerConfig", "Invalid %d state frequency which is larger "
|
||||
"than physics FPS %d, use default value.",
|
||||
frequency_in_config, stk_config->getPhysicsFPS());
|
||||
m_state_frequency.revertToDefaults();
|
||||
}
|
||||
NetworkConfig::get()->setStateFrequency(m_state_frequency);
|
||||
|
||||
if (m_server_difficulty > RaceManager::DIFFICULTY_LAST)
|
||||
m_server_difficulty = RaceManager::DIFFICULTY_LAST;
|
||||
if (m_server_mode > 8)
|
||||
|
@ -295,6 +295,14 @@ namespace ServerConfig
|
||||
"Negative value to disable, and this option will always be disabled "
|
||||
"for LAN server."));
|
||||
|
||||
SERVER_CFG_PREFIX IntServerConfigParam m_state_frequency
|
||||
SERVER_CFG_DEFAULT(IntServerConfigParam(10,
|
||||
"state-frequency",
|
||||
"Set how many states the server will send per second, the higher this "
|
||||
"value, the more bandwidth requires, also each client will trigger "
|
||||
"more rewind, which clients with slow device may have problem playing "
|
||||
"this server, use the default value is recommended."));
|
||||
|
||||
SERVER_CFG_PREFIX StringToUIntServerConfigParam m_server_ip_ban_list
|
||||
SERVER_CFG_DEFAULT(StringToUIntServerConfigParam("server-ip-ban-list",
|
||||
"ip: IP in X.X.X.X/Y (CIDR) format for banning, use Y of 32 for a "
|
||||
|
Loading…
x
Reference in New Issue
Block a user