diff --git a/engine/network/ClientUDP.cpp b/engine/network/ClientUDP.cpp index 2fd73e3..c951d18 100755 --- a/engine/network/ClientUDP.cpp +++ b/engine/network/ClientUDP.cpp @@ -27,7 +27,7 @@ bool ClientUDP::isWorking() const void ClientUDP::connect(sf::IpAddress ip, sf::Uint16 port) { sf::Packet packet; - packet << MsgType::Connect << NETWORK_VERSION; + packet << MsgType::Connect << Network::VERSION; _working = _socket.bind(0); _socket.addConnection(_socket.serverId(), ip, port); _socket.sendRely(packet, _socket.serverId()); @@ -43,7 +43,7 @@ void ClientUDP::update() while (isWorking() && process()); // Send new client information to server - if (Time::time() - _lastBroadcast > 1.0 / WORLD_UPDATE_RATE && connected()) { + if (Time::time() - _lastBroadcast > 1.0 / Network::WORLD_UPDATE_RATE && connected()) { updatePacket(); _lastBroadcast = Time::time(); } diff --git a/engine/network/ReliableMsg.cpp b/engine/network/ReliableMsg.cpp index 34a2af0..78120f2 100755 --- a/engine/network/ReliableMsg.cpp +++ b/engine/network/ReliableMsg.cpp @@ -12,9 +12,9 @@ ReliableMsg::ReliableMsg(const ReliableMsg& msg) : packet(msg.packet), address(m bool ReliableMsg::trySend(sf::UdpSocket& socket) { - if (Time::time() - firstTry > TIMEOUT_SECONDS) + if (Time::time() - firstTry > Network::TIMEOUT) return false; - if (Time::time() - lastTry > RELIABLE_RETRY_TIME) + if (Time::time() - lastTry > Network::RELIABLE_RETRY_TIME) { lastTry = Time::time(); socket.send(packet, address, port); diff --git a/engine/network/ServerUDP.cpp b/engine/network/ServerUDP.cpp index 1b11052..79cc3f3 100755 --- a/engine/network/ServerUDP.cpp +++ b/engine/network/ServerUDP.cpp @@ -40,7 +40,7 @@ void ServerUDP::update() while (process()); // World state broadcast - if (Time::time() - _lastBroadcast > 1.0 / WORLD_UPDATE_RATE) { + if (Time::time() - _lastBroadcast > 1.0 / Network::WORLD_UPDATE_RATE) { broadcast(); _lastBroadcast = Time::time(); } diff --git a/engine/network/UDPConnection.cpp b/engine/network/UDPConnection.cpp index 22d210b..58e1407 100755 --- a/engine/network/UDPConnection.cpp +++ b/engine/network/UDPConnection.cpp @@ -25,7 +25,7 @@ sf::Uint16 UDPConnection::port() const bool UDPConnection::timeout() const { - return Time::time() - lastMsg > TIMEOUT_SECONDS; + return Time::time() - lastMsg > Network::TIMEOUT; } bool UDPConnection::same(sf::IpAddress& ip, sf::Uint16 port) const diff --git a/engine/network/UDPSocket.cpp b/engine/network/UDPSocket.cpp index 61e1f5e..6f8a1db 100755 --- a/engine/network/UDPSocket.cpp +++ b/engine/network/UDPSocket.cpp @@ -123,7 +123,7 @@ void UDPSocket::update() for (auto it = _confirmTimes.begin(); it != _confirmTimes.end();) { - if (Time::time() - it->second > TIMEOUT_SECONDS) + if (Time::time() - it->second > Network::TIMEOUT) _confirmTimes.erase(it++); else ++it; @@ -160,7 +160,7 @@ MsgType UDPSocket::receive(sf::Packet& packet, sf::Uint16& senderId) if (type == MsgType::Connect) { sf::Uint32 version = 0; - if (!(packet >> version) || version != NETWORK_VERSION) + if (!(packet >> version) || version != Network::VERSION) return MsgType::Error; sf::Uint16 tmp; for (tmp = 64; tmp >= 1; tmp--) diff --git a/engine/network/config.h b/engine/network/config.h index c8d76a9..0a1459f 100755 --- a/engine/network/config.h +++ b/engine/network/config.h @@ -5,9 +5,11 @@ #ifndef ENGINE_CONFIG_H #define ENGINE_CONFIG_H -#define NETWORK_VERSION 1U -#define TIMEOUT_SECONDS 5 -#define WORLD_UPDATE_RATE 30 -#define RELIABLE_RETRY_TIME (1.0/20) +namespace Network { + const unsigned VERSION = 1U; + const int TIMEOUT = 1U; + const int WORLD_UPDATE_RATE = 30; + const double RELIABLE_RETRY_TIME = 1.0/20; +} #endif //INC_3DZAVR_CONFIG_H