Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/optimize the commands calls zappy gui #246

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions gui/include/GameDatas/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ class Gui::Player {
*/
clock_t getAnimationTimeEllapsed() const;

/**
* @brief Set the Last Position Update object.
*
* @param lastPositionUpdate Last position update.
*/
void setLastPositionUpdate(clock_t lastPositionUpdate);

/**
* @brief Get the Last Position Update object.
*
* @return clock_t - Last position update.
*/
clock_t getLastPositionUpdate() const;

/**
* @brief Inventory of the player.
*
Expand All @@ -224,4 +238,5 @@ class Gui::Player {
std::string _broadcast; //!< Broadcast message.
int _currentFrame; //!< Current frame animation.
clock_t _animationTimeEllapsed; //!< Time ellapsed during animation.
clock_t _lastPositionUpdate; //!< Last position update.
};
8 changes: 7 additions & 1 deletion gui/src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ void Gui::Engine::sendMessageUpdate()
_network.get()->sendMessageServer("sgt\n");
for (auto &team : _gameData.get()->getTeams()) {
for (auto &player : team.getPlayers()) {
_network.get()->sendMessageServer("ppo " + std::to_string(player.getId()) + "\n");
Player::PlayerState state = player.getState();
if (state == Player::PlayerState::DEAD || state == Player::PlayerState::INCANTATION)
continue;
if ((float)(currentTick - player.getLastPositionUpdate()) / CLOCKS_PER_SEC > 50 / _gameData->getServerTick()) {
_network.get()->sendMessageServer("ppo " + std::to_string(player.getId()) + "\n");
player.setLastPositionUpdate(clock());
}
}
}
if (_gameData.get()->getTimeUnitFromServer() == GameData::TimeUnitState::INCREASE)
Expand Down
1 change: 1 addition & 0 deletions gui/src/GUIUpdater/GUIUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void Gui::GUIUpdater::updatePlayerPosition(const std::vector<std::string> &data)
player.setState(Gui::Player::IDLE);
player.setPosition(std::make_pair(args[1], args[2]));
player.setOrientation(args[3]);
player.setLastPositionUpdate(clock());
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions gui/src/GameDatas/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gui::Player::Player(std::size_t id, const std::string &team, std::pair<std::size
{
_currentFrame = 0;
_state = IDLE;
setLastPositionUpdate(clock());
}

void Gui::Player::setPosition(std::pair<std::size_t, std::size_t> position)
Expand Down Expand Up @@ -141,3 +142,13 @@ clock_t Gui::Player::getAnimationTimeEllapsed() const
{
return _animationTimeEllapsed;
}

void Gui::Player::setLastPositionUpdate(clock_t lastPositionUpdate)
{
_lastPositionUpdate = lastPositionUpdate;
}

clock_t Gui::Player::getLastPositionUpdate() const
{
return _lastPositionUpdate;
}