From 612b0feca729d274317cd680ddfb1865ee2c9edd Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Mon, 25 Oct 2021 08:09:45 +0700 Subject: [PATCH] small code refactoring --- Server.cpp | 28 ++++++++++++++-------------- Server.h | 2 +- Source.cpp | 4 ++-- engine/network/ClientUDP.cpp | 12 ++++++------ engine/network/ServerUDP.cpp | 12 ++++++------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Server.cpp b/Server.cpp index 8c1fdcd..8d500cd 100644 --- a/Server.cpp +++ b/Server.cpp @@ -138,26 +138,26 @@ void Server::processStop() { } void Server::generateBonuses() { - _bonuses.insert({"Bonus_gun_1", std::make_shared(BonusInfo{Point4D(-10, -2, -15), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_gun_2", std::make_shared(BonusInfo{Point4D(10, -2, 15), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_gun_1", std::make_shared(BonusInfo{Vec3D(-10, -2, -15), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_gun_2", std::make_shared(BonusInfo{Vec3D(10, -2, 15), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_shotgun_1", std::make_shared(BonusInfo{Point4D(-10, 13, -24), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_shotgun_2", std::make_shared(BonusInfo{Point4D(10, 13, 24), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_shotgun_1", std::make_shared(BonusInfo{Vec3D(-10, 13, -24), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_shotgun_2", std::make_shared(BonusInfo{Vec3D(10, 13, 24), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_ak47_1", std::make_shared(BonusInfo{Point4D(-25, 30, 50), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_ak47_2", std::make_shared(BonusInfo{Point4D(25, 30, -50), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_ak47_1", std::make_shared(BonusInfo{Vec3D(-25, 30, 50), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_ak47_2", std::make_shared(BonusInfo{Vec3D(25, 30, -50), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_gold_ak47_1", std::make_shared(BonusInfo{Point4D(-35, 80, 25), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_gold_ak47_2", std::make_shared(BonusInfo{Point4D(35, 80, -25), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_gold_ak47_1", std::make_shared(BonusInfo{Vec3D(-35, 80, 25), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_gold_ak47_2", std::make_shared(BonusInfo{Vec3D(35, 80, -25), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_rifle_1", std::make_shared(BonusInfo{Point4D(40, -2, 45), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_rifle_2", std::make_shared(BonusInfo{Point4D(-40, -2, -45), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_rifle_1", std::make_shared(BonusInfo{Vec3D(40, -2, 45), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_rifle_2", std::make_shared(BonusInfo{Vec3D(-40, -2, -45), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_hill_1", std::make_shared(BonusInfo{Point4D(-40, -2, 45), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_hill_2", std::make_shared(BonusInfo{Point4D(40, -2, -45), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_hill_1", std::make_shared(BonusInfo{Vec3D(-40, -2, 45), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_hill_2", std::make_shared(BonusInfo{Vec3D(40, -2, -45), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_ability_1", std::make_shared(BonusInfo{Point4D(25, 18, -33), -2*_bonusRechargeTime, true})}); - _bonuses.insert({"Bonus_ability_2", std::make_shared(BonusInfo{Point4D(-25, 18, 33), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_ability_1", std::make_shared(BonusInfo{Vec3D(25, 18, -33), -2*_bonusRechargeTime, true})}); + _bonuses.insert({"Bonus_ability_2", std::make_shared(BonusInfo{Vec3D(-25, 18, 33), -2*_bonusRechargeTime, true})}); } void Server::updateInfo() { diff --git a/Server.h b/Server.h index 91a6728..952d94c 100644 --- a/Server.h +++ b/Server.h @@ -10,7 +10,7 @@ #include "Bonus.h" struct BonusInfo final { - const Point4D position{}; + const Vec3D position{}; const double lastTake = std::numeric_limits::min(); const bool onTheMap = false; }; diff --git a/Source.cpp b/Source.cpp index e225a1d..97d24ce 100644 --- a/Source.cpp +++ b/Source.cpp @@ -9,11 +9,11 @@ using namespace std; int main() { Shooter game; - game.create(1280, 720, ShooterConsts::PROJECT_NAME); + //game.create(1280, 720, ShooterConsts::PROJECT_NAME); //game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); //game.create(2048, 1152, ShooterConsts::PROJECT_NAME); - //game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); + game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); return 0; } \ No newline at end of file diff --git a/engine/network/ClientUDP.cpp b/engine/network/ClientUDP.cpp index b00ba65..46a22a7 100644 --- a/engine/network/ClientUDP.cpp +++ b/engine/network/ClientUDP.cpp @@ -33,7 +33,7 @@ void ClientUDP::connect(sf::IpAddress ip, sf::Uint16 port) _socket.addConnection(_socket.serverId(), ip, port); _socket.sendRely(packet, _socket.serverId()); - Log::log("ClientUDP: connecting to the server..."); + Log::log("ClientUDP::connect(): connecting to the server..."); } void ClientUDP::update() @@ -61,13 +61,13 @@ void ClientUDP::disconnect() _socket.unbind(); _working = false; - Log::log("ClientUDP: disconnected from the server."); + Log::log("ClientUDP::disconnect(): disconnected from the server."); processDisconnected(); } bool ClientUDP::timeout(sf::Uint16 id) { - Log::log("ClientUDP: timeout from the server."); + Log::log("ClientUDP::timeout(): timeout from the server."); if (id != _socket.serverId()) return true; @@ -97,7 +97,7 @@ bool ClientUDP::process() packet >> targetId; _socket.setId(targetId); - Log::log("ClientUDP: client Id = " + std::to_string(targetId) + " connected."); + Log::log("ClientUDP::process(): client Id = " + std::to_string(targetId) + " connected."); processInit(packet); break; @@ -107,7 +107,7 @@ bool ClientUDP::process() break; case MsgType::NewClient: - Log::log("ClientUDP: new client init..."); + Log::log("ClientUDP::process(): new client init..."); processNewClient(packet); break; @@ -116,7 +116,7 @@ bool ClientUDP::process() if (targetId == _socket.ownId()) disconnect(); - Log::log("ClientUDP: client Id = " + std::to_string(targetId) + " disconnected from the server"); + Log::log("ClientUDP::process(): client Id = " + std::to_string(targetId) + " disconnected from the server"); processDisconnect(targetId); break; diff --git a/engine/network/ServerUDP.cpp b/engine/network/ServerUDP.cpp index c3abfdf..976c6c1 100644 --- a/engine/network/ServerUDP.cpp +++ b/engine/network/ServerUDP.cpp @@ -22,9 +22,9 @@ bool ServerUDP::start(sf::Uint16 port) _working = _socket.bind(port); if(_working) - Log::log("ServerUDP: server successfully started."); + Log::log("ServerUDP::start(): server successfully started."); else - Log::log("ServerUDP: failed to start the server."); + Log::log("ServerUDP::start(): failed to start the server."); return _working; } @@ -63,7 +63,7 @@ void ServerUDP::stop() processStop(); - Log::log("ServerUDP: the server was killed."); + Log::log("ServerUDP::stop(): the server was killed."); } bool ServerUDP::timeout(sf::Uint16 playerId) @@ -76,7 +76,7 @@ bool ServerUDP::timeout(sf::Uint16 playerId) for (auto client : _clients) _socket.sendRely(packet, client); - Log::log("ServerUDP: client Id = " + std::to_string(playerId) + " disconnected due to timeout."); + Log::log("ServerUDP::timeout(): client Id = " + std::to_string(playerId) + " disconnected due to timeout."); processDisconnect(playerId); return true; @@ -99,7 +99,7 @@ bool ServerUDP::process() // here we process any operations based on msg type case MsgType::Connect: - Log::log("ServerUDP: client Id = " + std::to_string(senderId) + " connecting..."); + Log::log("ServerUDP::process(): client Id = " + std::to_string(senderId) + " connecting..."); processConnect(senderId); break; @@ -108,7 +108,7 @@ bool ServerUDP::process() processClientUpdate(senderId, packet); break; case MsgType::Disconnect: - Log::log("ServerUDP: client Id = " + std::to_string(senderId) + " disconnected."); + Log::log("ServerUDP::process(): client Id = " + std::to_string(senderId) + " disconnected."); sendPacket << MsgType::Disconnect << senderId; _clients.erase(senderId);