small code refactoring

master
Vectozavr 2021-10-25 08:09:45 +07:00
parent 2b01e305f8
commit 612b0feca7
5 changed files with 29 additions and 29 deletions

View File

@ -138,26 +138,26 @@ void Server::processStop() {
} }
void Server::generateBonuses() { void Server::generateBonuses() {
_bonuses.insert({"Bonus_gun_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(-10, -2, -15), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_gun_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-10, -2, -15), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_gun_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(10, -2, 15), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_gun_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(10, -2, 15), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_shotgun_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(-10, 13, -24), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_shotgun_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-10, 13, -24), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_shotgun_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(10, 13, 24), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_shotgun_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(10, 13, 24), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_ak47_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(-25, 30, 50), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_ak47_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-25, 30, 50), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_ak47_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(25, 30, -50), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_ak47_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(25, 30, -50), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_gold_ak47_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(-35, 80, 25), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_gold_ak47_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-35, 80, 25), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_gold_ak47_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(35, 80, -25), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_gold_ak47_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(35, 80, -25), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_rifle_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(40, -2, 45), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_rifle_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(40, -2, 45), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_rifle_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(-40, -2, -45), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_rifle_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-40, -2, -45), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_hill_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(-40, -2, 45), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_hill_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-40, -2, 45), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_hill_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(40, -2, -45), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_hill_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(40, -2, -45), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_ability_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(25, 18, -33), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_ability_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(25, 18, -33), -2*_bonusRechargeTime, true})});
_bonuses.insert({"Bonus_ability_2", std::make_shared<BonusInfo>(BonusInfo{Point4D(-25, 18, 33), -2*_bonusRechargeTime, true})}); _bonuses.insert({"Bonus_ability_2", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-25, 18, 33), -2*_bonusRechargeTime, true})});
} }
void Server::updateInfo() { void Server::updateInfo() {

View File

@ -10,7 +10,7 @@
#include "Bonus.h" #include "Bonus.h"
struct BonusInfo final { struct BonusInfo final {
const Point4D position{}; const Vec3D position{};
const double lastTake = std::numeric_limits<double>::min(); const double lastTake = std::numeric_limits<double>::min();
const bool onTheMap = false; const bool onTheMap = false;
}; };

View File

@ -9,11 +9,11 @@ using namespace std;
int main() { int main() {
Shooter game; 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(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen);
//game.create(2048, 1152, ShooterConsts::PROJECT_NAME); //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; return 0;
} }

View File

@ -33,7 +33,7 @@ void ClientUDP::connect(sf::IpAddress ip, sf::Uint16 port)
_socket.addConnection(_socket.serverId(), ip, port); _socket.addConnection(_socket.serverId(), ip, port);
_socket.sendRely(packet, _socket.serverId()); _socket.sendRely(packet, _socket.serverId());
Log::log("ClientUDP: connecting to the server..."); Log::log("ClientUDP::connect(): connecting to the server...");
} }
void ClientUDP::update() void ClientUDP::update()
@ -61,13 +61,13 @@ void ClientUDP::disconnect()
_socket.unbind(); _socket.unbind();
_working = false; _working = false;
Log::log("ClientUDP: disconnected from the server."); Log::log("ClientUDP::disconnect(): disconnected from the server.");
processDisconnected(); processDisconnected();
} }
bool ClientUDP::timeout(sf::Uint16 id) 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()) if (id != _socket.serverId())
return true; return true;
@ -97,7 +97,7 @@ bool ClientUDP::process()
packet >> targetId; packet >> targetId;
_socket.setId(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); processInit(packet);
break; break;
@ -107,7 +107,7 @@ bool ClientUDP::process()
break; break;
case MsgType::NewClient: case MsgType::NewClient:
Log::log("ClientUDP: new client init..."); Log::log("ClientUDP::process(): new client init...");
processNewClient(packet); processNewClient(packet);
break; break;
@ -116,7 +116,7 @@ bool ClientUDP::process()
if (targetId == _socket.ownId()) if (targetId == _socket.ownId())
disconnect(); 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); processDisconnect(targetId);
break; break;

View File

@ -22,9 +22,9 @@ bool ServerUDP::start(sf::Uint16 port)
_working = _socket.bind(port); _working = _socket.bind(port);
if(_working) if(_working)
Log::log("ServerUDP: server successfully started."); Log::log("ServerUDP::start(): server successfully started.");
else else
Log::log("ServerUDP: failed to start the server."); Log::log("ServerUDP::start(): failed to start the server.");
return _working; return _working;
} }
@ -63,7 +63,7 @@ void ServerUDP::stop()
processStop(); processStop();
Log::log("ServerUDP: the server was killed."); Log::log("ServerUDP::stop(): the server was killed.");
} }
bool ServerUDP::timeout(sf::Uint16 playerId) bool ServerUDP::timeout(sf::Uint16 playerId)
@ -76,7 +76,7 @@ bool ServerUDP::timeout(sf::Uint16 playerId)
for (auto client : _clients) for (auto client : _clients)
_socket.sendRely(packet, client); _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); processDisconnect(playerId);
return true; return true;
@ -99,7 +99,7 @@ bool ServerUDP::process()
// here we process any operations based on msg type // here we process any operations based on msg type
case MsgType::Connect: 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); processConnect(senderId);
break; break;
@ -108,7 +108,7 @@ bool ServerUDP::process()
processClientUpdate(senderId, packet); processClientUpdate(senderId, packet);
break; break;
case MsgType::Disconnect: 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; sendPacket << MsgType::Disconnect << senderId;
_clients.erase(senderId); _clients.erase(senderId);