Skip to content

Ch 10. Redundant code for local enemy destruction #24

@kyuhyunp

Description

@kyuhyunp

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;
	}
...
}


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions