-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Description
In MultiplayerGameState, the local planes are not removed from mLocalPlayerIdentifiers. Perhaps because the player might ask for the second player multiple times.
// Remove players whose aircrafts were destroyed
bool foundLocalPlane = false;
for (auto itr = mPlayers.begin(); itr != mPlayers.end(); )
{
// Check if there are no more local planes for remote clients
if (std::find(mLocalPlayerIdentifiers.begin(), mLocalPlayerIdentifiers.end(), itr->first) != mLocalPlayerIdentifiers.end())
{
foundLocalPlane = true;
}
if (!mWorld.getAircraft(itr->first))
{
itr = mPlayers.erase(itr);
// No more players left: Mission failed
if (mPlayers.empty())
requestStackPush(States::GameOver);
}
else
{
++itr;
}
}
if (!foundLocalPlane && mGameStarted)
{
requestStackPush(States::GameOver);
}
However, during the position update, mLocalPlayerIdentifiers.size() is sent even though the for loop checks the existence of each aircraft.
sf::Packet positionUpdatePacket;
positionUpdatePacket << static_cast<sf::Int32>(Client::PositionUpdate);
positionUpdatePacket << static_cast<sf::Int32>(mLocalPlayerIdentifiers.size());
FOREACH(sf::Int32 identifier, mLocalPlayerIdentifiers)
{
if (Aircraft* aircraft = mWorld.getAircraft(identifier))
positionUpdatePacket << identifier << aircraft->getPosition().x << aircraft->getPosition().y << static_cast<sf::Int32>(aircraft->getHitpoints()) << static_cast<sf::Int32>(aircraft->getMissileAmmo());
}
mSocket.send(positionUpdatePacket);
Minor correction:
// Check if there are no more local planes for remote clients
if (std::find(mLocalPlayerIdentifiers.begin(), mLocalPlayerIdentifiers.end(), itr->first) != mLocalPlayerIdentifiers.end())
{
foundLocalPlane = true;
}
could be added inside the else {++itr} block for better performance.
Metadata
Metadata
Assignees
Labels
No labels