Skip to content

Commit

Permalink
refactor: update event handling to use size_t and unsigned short for …
Browse files Browse the repository at this point in the history
…better type safety
  • Loading branch information
MasterLaplace committed Nov 7, 2024
1 parent 6e2c1d6 commit 0358f10
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions Flakkari/Server/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ void Game::handleEvent(std::shared_ptr<Client> player, Protocol::Packet<Protocol
Protocol::Event event = *(Protocol::Event *) packet.payload.data();
if (event.id == Protocol::EventId::MOVE_UP && ctrl->up)
{
if (netEvent->events.size() < int(event.id))
netEvent->events.resize(int(event.id) + 1);
netEvent->events[int(event.id)] = int(event.state);
if (netEvent->events.size() < size_t(event.id))
netEvent->events.resize(size_t(event.id) + 1);
netEvent->events[size_t(event.id)] = unsigned short(event.state);

FLAKKARI_LOG_INFO("event: " + std::to_string(int(event.id)) + " " + std::to_string(int(event.state)));

Expand All @@ -322,9 +322,9 @@ void Game::handleEvent(std::shared_ptr<Client> player, Protocol::Packet<Protocol
}
if (event.id == Protocol::EventId::MOVE_DOWN && ctrl->down)
{
if (netEvent->events.size() < int(event.id))
netEvent->events.resize(int(event.id) + 1);
netEvent->events[int(event.id)] = int(event.state);
if (netEvent->events.size() < size_t(event.id))
netEvent->events.resize(size_t(event.id) + 1);
netEvent->events[size_t(event.id)] = unsigned short(event.state);

FLAKKARI_LOG_INFO("event: " + std::to_string(int(event.id)) + " " + std::to_string(int(event.state)));

Expand All @@ -337,9 +337,9 @@ void Game::handleEvent(std::shared_ptr<Client> player, Protocol::Packet<Protocol
}
if (event.id == Protocol::EventId::MOVE_LEFT && ctrl->left)
{
if (netEvent->events.size() < int(event.id))
netEvent->events.resize(int(event.id) + 1);
netEvent->events[int(event.id)] = int(event.state);
if (netEvent->events.size() < size_t(event.id))
netEvent->events.resize(size_t(event.id) + 1);
netEvent->events[size_t(event.id)] = unsigned short(event.state);

FLAKKARI_LOG_INFO("event: " + std::to_string(int(event.id)) + " " + std::to_string(int(event.state)));

Expand All @@ -352,9 +352,9 @@ void Game::handleEvent(std::shared_ptr<Client> player, Protocol::Packet<Protocol
}
if (event.id == Protocol::EventId::MOVE_RIGHT && ctrl->right)
{
if (netEvent->events.size() < int(event.id))
netEvent->events.resize(int(event.id) + 1);
netEvent->events[int(event.id)] = int(event.state);
if (netEvent->events.size() < size_t(event.id))
netEvent->events.resize(size_t(event.id) + 1);
netEvent->events[size_t(event.id)] = unsigned short(event.state);

FLAKKARI_LOG_INFO("event: " + std::to_string(int(event.id)) + " " + std::to_string(int(event.state)));

Expand All @@ -367,9 +367,9 @@ void Game::handleEvent(std::shared_ptr<Client> player, Protocol::Packet<Protocol
}
if (event.id == Protocol::EventId::SHOOT && ctrl->shoot)
{
if (netEvent->events.size() < int(event.id))
netEvent->events.resize(int(event.id) + 1);
netEvent->events[int(event.id)] = int(event.state);
if (netEvent->events.size() < size_t(event.id))
netEvent->events.resize(size_t(event.id) + 1);
netEvent->events[size_t(event.id)] = unsigned short(event.state);

FLAKKARI_LOG_INFO("event: " + std::to_string(int(event.id)) + " " + std::to_string(int(event.state)));

Expand Down

0 comments on commit 0358f10

Please sign in to comment.