define -> namespace::const
parent
720b2e0ddd
commit
c4b9bd0e35
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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--)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue