Skip to content

Commit

Permalink
style: apply linter
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 22, 2024
1 parent 109be24 commit c16f3fa
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#ifndef Timer_HPP_
#define Timer_HPP_

#include <chrono>
#include <cstring>
#include <string>
#include <chrono>

#include "config.h.in"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
17 changes: 7 additions & 10 deletions Flakkari/Engine/EntityComponentSystem/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -58,13 +56,12 @@ class Entity {
#include <unordered_map>

namespace std {
template <>
struct hash<Flakkari::Engine::ECS::Entity>
template <> struct hash<Flakkari::Engine::ECS::Entity> {
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<std::size_t>()(entity.getId());
}
};
}
return std::hash<std::size_t>()(entity.getId());
}
};
} // namespace std

#endif /* !FLAKKARI_ENTITY_HPP_ */
8 changes: 4 additions & 4 deletions Flakkari/Protocol/Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,8 +95,8 @@ template <typename Id> struct Header {
ApiVersion _apiVersion : 4 = ApiVersion::V_1;
Id _commandId;
uint16_t _contentLength = 0;
uint64_t _sequenceNumber =
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
uint64_t _sequenceNumber = static_cast<uint64_t>(
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
.count());

std::size_t size() const { return sizeof(*this); }
Expand Down
40 changes: 25 additions & 15 deletions Flakkari/Protocol/PacketFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,30 @@ class PacketFactory {
* @param registry Registry to get the components from.
* @param entity Entity to get the components from.
*/
template<typename Id>
static void addCommonsToPacketByEntity (
Protocol::Packet<Id> &packet, Engine::ECS::Registry &registry, Engine::ECS::Entity entity
) {
template <typename Id>
static void addCommonsToPacketByEntity(Protocol::Packet<Id> &packet, Engine::ECS::Registry &registry,
Engine::ECS::Entity entity)
{
auto child = registry.getComponents<Engine::ECS::Components::Common::Child>()[entity];

if (child.has_value()) {
if (child.has_value())
{
packet << Protocol::ComponentId::CHILD;
packet.injectString(child->name);
}

auto evolve = registry.getComponents<Engine::ECS::Components::Common::Evolve>()[entity];

if (evolve.has_value()) {
if (evolve.has_value())
{
packet << Protocol::ComponentId::EVOLVE;
packet.injectString(evolve->name);
}

auto health = registry.getComponents<Engine::ECS::Components::Common::Health>()[entity];

if (health.has_value()) {
if (health.has_value())
{
packet << Protocol::ComponentId::HEALTH;
packet << health->currentHealth;
packet << health->maxHealth;
Expand All @@ -64,14 +67,16 @@ class PacketFactory {

auto id = registry.getComponents<Engine::ECS::Components::Common::Id>()[entity];

if (id.has_value()) {
if (id.has_value())
{
packet << Protocol::ComponentId::ID;
packet << id->id;
}

auto level = registry.getComponents<Engine::ECS::Components::Common::Level>()[entity];

if (level.has_value()) {
if (level.has_value())
{
packet << Protocol::ComponentId::LEVEL;
packet << level->level;
packet.injectString(level->currentWeapon);
Expand All @@ -81,36 +86,41 @@ class PacketFactory {

auto parent = registry.getComponents<Engine::ECS::Components::Common::Parent>()[entity];

if (parent.has_value()) {
if (parent.has_value())
{
packet << Protocol::ComponentId::PARENT;
packet << parent->entity;
}

auto tag = registry.getComponents<Engine::ECS::Components::Common::Tag>()[entity];

if (tag.has_value()) {
if (tag.has_value())
{
packet << Protocol::ComponentId::TAG;
packet.injectString(tag->tag);
}

auto template_ = registry.getComponents<Engine::ECS::Components::Common::Template>()[entity];

if (template_.has_value()) {
if (template_.has_value())
{
packet << Protocol::ComponentId::TEMPLATE;
packet.injectString(template_->name);
}

auto timer = registry.getComponents<Engine::ECS::Components::Common::Timer>()[entity];

if (timer.has_value()) {
if (timer.has_value())
{
packet << Protocol::ComponentId::TIMER;
packet << timer->lastTime.time_since_epoch().count();
packet << timer->maxTime;
}

auto weapon = registry.getComponents<Engine::ECS::Components::Common::Weapon>()[entity];

if (weapon.has_value()) {
if (weapon.has_value())
{
packet << Protocol::ComponentId::WEAPON;
packet << weapon->minDamage;
packet << weapon->maxDamage;
Expand Down Expand Up @@ -271,7 +281,7 @@ class PacketFactory {
packet << rigidbody->_mass;
packet << rigidbody->_drag;
packet << rigidbody->_angularDrag;
packet << (byte)rigidbody->_useGravity;
packet << (byte) rigidbody->_useGravity;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Flakkari/Server/Client/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void ClientManager::checkInactiveClients()
continue;
}

++it;
++it;
}
}

Expand Down
30 changes: 15 additions & 15 deletions Flakkari/Server/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void Game::loadSystems(Engine::ECS::Registry &registry, const std::string &scene
packet.header._commandId = Protocol::CommandId::REQ_ENTITY_DESTROY;
packet << entity.first;
this->sendOnSameScene(sceneName, packet);
continue;
}
continue;
}

Protocol::Packet<Protocol::CommandId> packet;
packet.header._commandId = Protocol::CommandId::REQ_ENTITY_UPDATE;
Expand All @@ -105,7 +105,7 @@ void Game::loadSystems(Engine::ECS::Registry &registry, const std::string &scene
Protocol::PacketFactory::addComponentsToPacketByEntity(packet, r, entity.first);

this->sendOnSameScene(sceneName, packet);
}
}
});
}

Expand All @@ -114,10 +114,10 @@ void Game::loadEntityFromTemplate(Engine::ECS::Registry &registry, 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);
}
Expand Down Expand Up @@ -318,13 +318,14 @@ void Game::handleEvents(std::shared_ptr<Client> player, Protocol::Packet<Protoco
if (handleMoveEvent(event, ctrl.value(), vel.value(), pos.value()))
{
FLAKKARI_LOG_DEBUG("event: " + std::to_string(int(event.id)) + " " + std::to_string(int(event.state)));
sendUpdatePosition(player, pos.value(), vel.value());
sendUpdatePosition(player, pos.value(), vel.value());
continue;
}
}
else if (event.id == Protocol::EventId::SHOOT && ctrl->_shoot)
{
if (event.state == Protocol::EventState::PRESSED)
{}
if (event.state == Protocol::EventState::PRESSED)
{
}
else if (event.state == Protocol::EventState::RELEASED)
continue;
}
Expand All @@ -338,17 +339,17 @@ void Game::handleEvents(std::shared_ptr<Client> player, Protocol::Packet<Protoco
Protocol::EventAxis event = *(Protocol::EventAxis *) (data + i * sizeof(Protocol::EventAxis));

if (event.id == Protocol::EventAxisId::LOOK_RIGHT && ctrl->_look_right)
{
{
pos->_rotation.vec.y += event.value * 100 * _deltaTime;
continue;
}
else if (event.id == Protocol::EventAxisId::LOOK_LEFT && ctrl->_look_left)
{
pos->_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;
}
Expand Down Expand Up @@ -408,7 +409,7 @@ void Game::updateOutcomingPackets(unsigned char maxMessagePerFrame)

buffer += packet.serialize();
ClientManager::GetInstance().sendPacketToClient(player->getAddress(), buffer);
ClientManager::UnlockInstance();
ClientManager::UnlockInstance();
}
}
}
Expand Down Expand Up @@ -467,7 +468,6 @@ bool Game::addPlayer(std::shared_ptr<Client> 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 + "\"");
Expand Down

0 comments on commit c16f3fa

Please sign in to comment.