small code refactoring
parent
2b01e305f8
commit
612b0feca7
28
Server.cpp
28
Server.cpp
|
@ -138,26 +138,26 @@ void Server::processStop() {
|
|||
}
|
||||
|
||||
void Server::generateBonuses() {
|
||||
_bonuses.insert({"Bonus_gun_1", std::make_shared<BonusInfo>(BonusInfo{Point4D(-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_1", std::make_shared<BonusInfo>(BonusInfo{Vec3D(-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_2", 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{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_2", 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{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_2", 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{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_2", 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{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_2", 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{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_2", 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{Vec3D(-25, 18, 33), -2*_bonusRechargeTime, true})});
|
||||
}
|
||||
|
||||
void Server::updateInfo() {
|
||||
|
|
2
Server.h
2
Server.h
|
@ -10,7 +10,7 @@
|
|||
#include "Bonus.h"
|
||||
|
||||
struct BonusInfo final {
|
||||
const Point4D position{};
|
||||
const Vec3D position{};
|
||||
const double lastTake = std::numeric_limits<double>::min();
|
||||
const bool onTheMap = false;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue