Skip to content

Commit

Permalink
player_pool fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ISPlatonov committed Jan 19, 2024
1 parent ae35626 commit 65517e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/Controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ class Controls
static sf::RectangleShape inventory_rect;
static inline std::unordered_map<sf::FloatRect, Object::ObjectName> inventory;
static inline Object::Object selected_object;
static std::map<SocketInfo, Actor::Player> player_pool;
static std::unordered_map<PlayerId, Actor::Player> player_pool;
static inline sf::Font font;
};
10 changes: 5 additions & 5 deletions src/common/Controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sf::RectangleShape Controls::inventory_rect = sf::RectangleShape(sf::Vector2f(Co
WorldMap::ObjectMap Controls::object_map{};
Multiplayer::UdpManager Controls::udp_manager(sf::IpAddress::getLocalAddress(), sf::IpAddress(Constants::getSERVER_IP()));
Actor::User Controls::user(sf::Vector2f(0, 0), Controls::udp_manager.getLocalPort());
std::map<SocketInfo, Actor::Player> Controls::player_pool{};
std::unordered_map<PlayerId, Actor::Player> Controls::player_pool{};


void Controls::applyWindowSettings()
Expand Down Expand Up @@ -232,21 +232,21 @@ void Controls::handleFrameStep()
auto time = iter->second.getTime();
Time::Time time_now = Time::getTimeNow();
int ping = static_cast<int>(time_now) - static_cast<int>(time);
if (!player_pool.count(iter->second.getSocketInfo()))
if (!player_pool.count(iter->first))
{
player_pool[iter->second.getSocketInfo()] = Actor::Player(iter->second);
player_pool[iter->first] = Actor::Player(iter->second);
++iter;
continue;
}
else if (ping > Constants::getMAX_PING())
{
player_pool.erase(iter->second.getSocketInfo());
player_pool.erase(iter->first);
udp_manager.removePlayerByPlayerId(iter++->second.getId());
continue;
}
else
{
player_pool[iter->second.getSocketInfo()] << iter->second;
player_pool[iter->first] << iter->second;
++iter;
continue;
}
Expand Down

0 comments on commit 65517e5

Please sign in to comment.