diff --git a/Flakkari/Engine/EntityComponentSystem/Components/3D/Control.hpp b/Flakkari/Engine/EntityComponentSystem/Components/3D/Control.hpp index 33c39b34..c9f770c2 100644 --- a/Flakkari/Engine/EntityComponentSystem/Components/3D/Control.hpp +++ b/Flakkari/Engine/EntityComponentSystem/Components/3D/Control.hpp @@ -50,13 +50,12 @@ struct Control { Control(bool m_up, bool m_down, bool m_left, bool m_right, bool m_front, bool m_back, bool l_up, bool l_down, bool l_left, bool l_right, bool s) : _move_up(m_up), _move_down(m_down), _move_left(m_left), _move_right(m_right), _move_front(m_front), - _move_back(m_back), _look_up(l_up), _look_down(l_down), _look_left(l_left), _look_right(l_right), - _shoot(s) {}; + _move_back(m_back), _look_up(l_up), _look_down(l_down), _look_left(l_left), _look_right(l_right), _shoot(s){}; Control(const Control &other) : _move_up(other._move_up), _move_down(other._move_down), _move_left(other._move_left), _move_right(other._move_right), _move_front(other._move_front), _move_back(other._move_back), _look_up(other._look_up), _look_down(other._look_down), _look_left(other._look_left), - _look_right(other._look_right), _shoot(other._shoot) {}; + _look_right(other._look_right), _shoot(other._shoot){}; Control &operator=(const Control &other) { diff --git a/Flakkari/Engine/EntityComponentSystem/Components/3D/Movable.hpp b/Flakkari/Engine/EntityComponentSystem/Components/3D/Movable.hpp index 66187557..fbab4e8f 100644 --- a/Flakkari/Engine/EntityComponentSystem/Components/3D/Movable.hpp +++ b/Flakkari/Engine/EntityComponentSystem/Components/3D/Movable.hpp @@ -24,12 +24,12 @@ struct Movable { float _minSpeed; float _maxSpeed; - Movable() : _velocity(0, 0), _acceleration(0, 0), _minSpeed(0), _maxSpeed(0) {}; + Movable() : _velocity(0, 0), _acceleration(0, 0), _minSpeed(0), _maxSpeed(0){}; Movable(const Math::Vector3f &velocity, const Math::Vector3f &acceleration, float minSpeed, float maxSpeed) - : _velocity(velocity), _acceleration(acceleration), _minSpeed(minSpeed), _maxSpeed(maxSpeed) {}; + : _velocity(velocity), _acceleration(acceleration), _minSpeed(minSpeed), _maxSpeed(maxSpeed){}; Movable(const Movable &other) : _velocity(other._velocity), _acceleration(other._acceleration), _minSpeed(other._minSpeed), - _maxSpeed(other._maxSpeed) {}; + _maxSpeed(other._maxSpeed){}; Movable &operator=(const Movable &other) { diff --git a/Flakkari/Engine/EntityComponentSystem/Components/Common/Timer.hpp b/Flakkari/Engine/EntityComponentSystem/Components/Common/Timer.hpp index 5b13bc62..1d354a56 100644 --- a/Flakkari/Engine/EntityComponentSystem/Components/Common/Timer.hpp +++ b/Flakkari/Engine/EntityComponentSystem/Components/Common/Timer.hpp @@ -10,9 +10,9 @@ #ifndef Timer_HPP_ #define Timer_HPP_ +#include #include #include -#include #include "config.h.in" diff --git a/Flakkari/Engine/EntityComponentSystem/Components/Common/Weapon.hpp b/Flakkari/Engine/EntityComponentSystem/Components/Common/Weapon.hpp index fca03252..197b19d0 100644 --- a/Flakkari/Engine/EntityComponentSystem/Components/Common/Weapon.hpp +++ b/Flakkari/Engine/EntityComponentSystem/Components/Common/Weapon.hpp @@ -47,7 +47,7 @@ struct Weapon { Weapon() = default; Weapon(const Weapon &other) = default; Weapon(std::size_t min_dmg, std::size_t max_dmg, float chargeMax, float rate, std::size_t lvl) - : minDamage(min_dmg), maxDamage(max_dmg), chargeMaxTime(chargeMax), fireRate(rate), level(lvl) {}; + : minDamage(min_dmg), maxDamage(max_dmg), chargeMaxTime(chargeMax), fireRate(rate), level(lvl){}; Weapon &operator=(const Weapon &other) { diff --git a/Flakkari/Engine/EntityComponentSystem/Entity.hpp b/Flakkari/Engine/EntityComponentSystem/Entity.hpp index f3babb1f..263a1fe7 100644 --- a/Flakkari/Engine/EntityComponentSystem/Entity.hpp +++ b/Flakkari/Engine/EntityComponentSystem/Entity.hpp @@ -43,9 +43,7 @@ class Entity { return *this; } - bool operator==(const Entity& other) const { - return _id == other._id; - } + bool operator==(const Entity &other) const { return _id == other._id; } std::size_t getId() const { return _id; } @@ -58,13 +56,12 @@ class Entity { #include namespace std { - template <> - struct hash +template <> struct hash { + size_t operator()(const Flakkari::Engine::ECS::Entity &entity) const noexcept { - size_t operator()(const Flakkari::Engine::ECS::Entity& entity) const noexcept { - return std::hash()(entity.getId()); - } - }; -} + return std::hash()(entity.getId()); + } +}; +} // namespace std #endif /* !FLAKKARI_ENTITY_HPP_ */ diff --git a/Flakkari/Protocol/Header.hpp b/Flakkari/Protocol/Header.hpp index ed24e720..8e31b937 100644 --- a/Flakkari/Protocol/Header.hpp +++ b/Flakkari/Protocol/Header.hpp @@ -29,8 +29,8 @@ namespace Flakkari::Protocol { using ushort = uint16_t; // 16 bits (max: 65535) (2 bytes) -using uint = uint32_t; // 32 bits (max: 4294967295) (4 bytes) -using ulong = uint64_t; // 64 bits (max: 18446744073709551615) (8 bytes) +using uint = uint32_t; // 32 bits (max: 4294967295) (4 bytes) +using ulong = uint64_t; // 64 bits (max: 18446744073709551615) (8 bytes) /** * @brief The version of the protocol used @@ -95,8 +95,8 @@ template struct Header { ApiVersion _apiVersion : 4 = ApiVersion::V_1; Id _commandId; uint16_t _contentLength = 0; - uint64_t _sequenceNumber = - static_cast(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) + uint64_t _sequenceNumber = static_cast( + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) .count()); std::size_t size() const { return sizeof(*this); } diff --git a/Flakkari/Protocol/PacketFactory.hpp b/Flakkari/Protocol/PacketFactory.hpp index b1f4d255..d2da0262 100644 --- a/Flakkari/Protocol/PacketFactory.hpp +++ b/Flakkari/Protocol/PacketFactory.hpp @@ -34,27 +34,30 @@ class PacketFactory { * @param registry Registry to get the components from. * @param entity Entity to get the components from. */ - template - static void addCommonsToPacketByEntity ( - Protocol::Packet &packet, Engine::ECS::Registry ®istry, Engine::ECS::Entity entity - ) { + template + static void addCommonsToPacketByEntity(Protocol::Packet &packet, Engine::ECS::Registry ®istry, + Engine::ECS::Entity entity) + { auto child = registry.getComponents()[entity]; - if (child.has_value()) { + if (child.has_value()) + { packet << Protocol::ComponentId::CHILD; packet.injectString(child->name); } auto evolve = registry.getComponents()[entity]; - if (evolve.has_value()) { + if (evolve.has_value()) + { packet << Protocol::ComponentId::EVOLVE; packet.injectString(evolve->name); } auto health = registry.getComponents()[entity]; - if (health.has_value()) { + if (health.has_value()) + { packet << Protocol::ComponentId::HEALTH; packet << health->currentHealth; packet << health->maxHealth; @@ -64,14 +67,16 @@ class PacketFactory { auto id = registry.getComponents()[entity]; - if (id.has_value()) { + if (id.has_value()) + { packet << Protocol::ComponentId::ID; packet << id->id; } auto level = registry.getComponents()[entity]; - if (level.has_value()) { + if (level.has_value()) + { packet << Protocol::ComponentId::LEVEL; packet << level->level; packet.injectString(level->currentWeapon); @@ -81,28 +86,32 @@ class PacketFactory { auto parent = registry.getComponents()[entity]; - if (parent.has_value()) { + if (parent.has_value()) + { packet << Protocol::ComponentId::PARENT; packet << parent->entity; } auto tag = registry.getComponents()[entity]; - if (tag.has_value()) { + if (tag.has_value()) + { packet << Protocol::ComponentId::TAG; packet.injectString(tag->tag); } auto template_ = registry.getComponents()[entity]; - if (template_.has_value()) { + if (template_.has_value()) + { packet << Protocol::ComponentId::TEMPLATE; packet.injectString(template_->name); } auto timer = registry.getComponents()[entity]; - if (timer.has_value()) { + if (timer.has_value()) + { packet << Protocol::ComponentId::TIMER; packet << timer->lastTime.time_since_epoch().count(); packet << timer->maxTime; @@ -110,7 +119,8 @@ class PacketFactory { auto weapon = registry.getComponents()[entity]; - if (weapon.has_value()) { + if (weapon.has_value()) + { packet << Protocol::ComponentId::WEAPON; packet << weapon->minDamage; packet << weapon->maxDamage; @@ -271,7 +281,7 @@ class PacketFactory { packet << rigidbody->_mass; packet << rigidbody->_drag; packet << rigidbody->_angularDrag; - packet << (byte)rigidbody->_useGravity; + packet << (byte) rigidbody->_useGravity; } } diff --git a/Flakkari/Server/Client/ClientManager.cpp b/Flakkari/Server/Client/ClientManager.cpp index 0ae2c23f..2ef131d5 100644 --- a/Flakkari/Server/Client/ClientManager.cpp +++ b/Flakkari/Server/Client/ClientManager.cpp @@ -78,7 +78,7 @@ void ClientManager::checkInactiveClients() continue; } - ++it; + ++it; } } diff --git a/Flakkari/Server/Game/Game.cpp b/Flakkari/Server/Game/Game.cpp index 694b8433..bed84004 100644 --- a/Flakkari/Server/Game/Game.cpp +++ b/Flakkari/Server/Game/Game.cpp @@ -95,8 +95,8 @@ void Game::loadSystems(Engine::ECS::Registry ®istry, const std::string &scene packet.header._commandId = Protocol::CommandId::REQ_ENTITY_DESTROY; packet << entity.first; this->sendOnSameScene(sceneName, packet); - continue; - } + continue; + } Protocol::Packet packet; packet.header._commandId = Protocol::CommandId::REQ_ENTITY_UPDATE; @@ -105,7 +105,7 @@ void Game::loadSystems(Engine::ECS::Registry ®istry, const std::string &scene Protocol::PacketFactory::addComponentsToPacketByEntity(packet, r, entity.first); this->sendOnSameScene(sceneName, packet); - } + } }); } @@ -114,10 +114,10 @@ void Game::loadEntityFromTemplate(Engine::ECS::Registry ®istry, const nl_enti { Engine::ECS::Entity newEntity = registry.spawn_entity(); - for (auto &templateInfo : templates.items()) - { + for (auto &templateInfo : templates.items()) + { if (entity.value() != templateInfo.value().begin().key()) - continue; + continue; Engine::ECS::Factory::RegistryEntityByTemplate(registry, newEntity, templateInfo.value().begin().value(), templates); } @@ -318,13 +318,14 @@ void Game::handleEvents(std::shared_ptr player, Protocol::Packet_shoot) { - if (event.state == Protocol::EventState::PRESSED) - {} + if (event.state == Protocol::EventState::PRESSED) + { + } else if (event.state == Protocol::EventState::RELEASED) continue; } @@ -338,7 +339,7 @@ void Game::handleEvents(std::shared_ptr player, Protocol::Packet_look_right) - { + { pos->_rotation.vec.y += event.value * 100 * _deltaTime; continue; } @@ -346,9 +347,9 @@ void Game::handleEvents(std::shared_ptr player, Protocol::Packet_rotation.vec.y -= event.value * 100 * _deltaTime; continue; - } + } else if (event.id == Protocol::EventAxisId::LOOK_UP && ctrl->_look_up) - { + { pos->_rotation.vec.x += event.value * 100 * _deltaTime; continue; } @@ -408,7 +409,7 @@ void Game::updateOutcomingPackets(unsigned char maxMessagePerFrame) buffer += packet.serialize(); ClientManager::GetInstance().sendPacketToClient(player->getAddress(), buffer); - ClientManager::UnlockInstance(); + ClientManager::UnlockInstance(); } } } @@ -467,7 +468,6 @@ bool Game::addPlayer(std::shared_ptr player) Engine::ECS::Factory::RegistryEntityByTemplate(registry, newEntity, player_info.value()); ResourceManager::UnlockInstance(); - player->setEntity(newEntity); _players.push_back(player); FLAKKARI_LOG_INFO("client \"" + std::string(*address) + "\" added to game \"" + _name + "\"");