In Aircraft's updateCurrent, when an enemy is destroyed, pickup spawn and network command are handled. However, the network command is unnecessary for local games, and pickup spawn can also be moved to World's handleCollisions to avoid duplicate createPickup. Additionally, it is more consistent to remove mDropPickupCommand and directly use the World's function, as multiplayer relies on server authority.
void Aircraft::updateCurrent(sf::Time dt, CommandQueue& commands)
{
...
// Entity has been destroyed: Possibly drop pickup, mark for removal
if (isDestroyed())
{
checkPickupDrop(commands);
mExplosion.update(dt);
// Play explosion sound only once
if (!mExplosionBegan)
{
// Play sound effect
SoundEffect::ID soundEffect = (randomInt(2) == 0) ? SoundEffect::Explosion1 : SoundEffect::Explosion2;
playLocalSound(commands, soundEffect);
// Emit network game action for enemy explosions
if (!isAllied())
{
sf::Vector2f position = getWorldPosition();
Command command;
command.category = Category::Network;
command.action = derivedAction<NetworkNode>([position] (NetworkNode& node, sf::Time)
{
node.notifyGameAction(GameActions::EnemyExplode, position);
});
commands.push(command);
}
mExplosionBegan = true;
}
return;
}
...
}
In Aircraft's
updateCurrent, when an enemy is destroyed, pickup spawn and network command are handled. However, the network command is unnecessary for local games, and pickup spawn can also be moved to World'shandleCollisionsto avoid duplicatecreatePickup. Additionally, it is more consistent to removemDropPickupCommandand directly use the World's function, as multiplayer relies on server authority.