|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
Spawns bullets from player input on the server. More...
#include <PlayerShootSystem.hpp>
Public Member Functions | |
| PlayerShootSystem (ecs::Registry ®istry, RoomSystem &roomSystem, NetworkSyncSystem &networkSync) | |
| Constructor for PlayerShootSystem. | |
| void | update (float dt) override |
| Update player shoot system logic for one frame. | |
Public Member Functions inherited from rtp::ecs::ISystem | |
| virtual | ~ISystem () noexcept=default |
Private Member Functions | |
| void | spawnBullet (ecs::Entity owner, const ecs::components::Transform &tf, const ecs::components::RoomId &roomId, bool doubleFire=false) |
| Spawn a bullet entity based on the player's transform and room ID. | |
| void | spawnChargedBullet (ecs::Entity owner, const ecs::components::Transform &tf, const ecs::components::RoomId &roomId, float chargeRatio, bool doubleFire=false) |
| Spawn a charged bullet based on the player's transform and room ID. | |
| void | sendAmmoUpdate (uint32_t netId, const ecs::components::Ammo &ammo) |
| Send an ammo update to the client for a specific network ID. | |
| void | spawnDebugPowerup (const Vec2f &position, uint32_t roomId, int dropRoll) |
| Spawn a debug powerup for testing (triggered by P key) | |
Private Attributes | |
| ecs::Registry & | _registry |
| Reference to the entity registry. | |
| RoomSystem & | _roomSystem |
| Reference to the RoomSystem. | |
| NetworkSyncSystem & | _networkSync |
| Reference to the NetworkSyncSystem. | |
| float | _bulletSpeed = 500.0f |
| Speed of the spawned bullets. | |
| float | _chargedBulletSpeed = 280.0f |
| Speed of the charged bullets. | |
| float | _spawnOffsetX = 20.0f |
| X offset for bullet spawn position. | |
| std::unordered_map< uint32_t, float > | _beamTickTimers |
Spawns bullets from player input on the server.
Definition at line 40 of file PlayerShootSystem.hpp.
| rtp::server::PlayerShootSystem::PlayerShootSystem | ( | ecs::Registry & | registry, |
| RoomSystem & | roomSystem, | ||
| NetworkSyncSystem & | networkSync | ||
| ) |
Constructor for PlayerShootSystem.
| registry | Reference to the entity registry |
| roomSystem | Reference to the RoomSystem |
| networkSync | Reference to the NetworkSyncSystem |
Definition at line 46 of file PlayerShootSystem.cpp.
|
private |
Send an ammo update to the client for a specific network ID.
| netId | Network ID of the entity |
| ammo | Ammo component to send |
Definition at line 964 of file PlayerShootSystem.cpp.
References _networkSync, rtp::net::AmmoUpdate, rtp::ecs::components::Ammo::current, rtp::net::AmmoUpdatePayload::current, rtp::ecs::components::Ammo::isReloading, rtp::ecs::components::Ammo::max, rtp::ecs::components::Ammo::reloadCooldown, rtp::ecs::components::Ammo::reloadTimer, rtp::server::NetworkSyncSystem::sendPacketToEntity(), and rtp::net::TCP.
Referenced by update().
|
private |
Spawn a bullet entity based on the player's transform and room ID.
| tf | Transform component of the player |
| roomId | RoomId component of the player |
| doubleFire | Whether to spawn two bullets (double fire power-up) |
Definition at line 492 of file PlayerShootSystem.cpp.
References _bulletSpeed, _networkSync, _registry, _roomSystem, _spawnOffsetX, rtp::ecs::Registry::add(), rtp::net::Bullet, rtp::net::EntitySpawn, rtp::log::error(), rtp::ecs::Registry::get(), rtp::server::RoomSystem::getRoom(), rtp::ecs::components::RoomId::id, rtp::ecs::Entity::index(), rtp::server::Room::InGame, rtp::ecs::components::Boomerang::maxDistance, rtp::ecs::components::Boomerang::ownerIndex, rtp::ecs::components::Transform::position, rtp::ecs::components::Homing::range, rtp::ecs::components::Boomerang::returning, rtp::server::NetworkSyncSystem::sendPacketToSessions(), rtp::ecs::Registry::spawn(), rtp::ecs::components::Boomerang::startPos, rtp::ecs::components::Homing::steering, rtp::net::TCP, rtp::Vec2< T >::x, and rtp::Vec2< T >::y.
Referenced by update().
|
private |
Spawn a charged bullet based on the player's transform and room ID.
| tf | Transform component of the player |
| roomId | RoomId component of the player |
| chargeRatio | Charge ratio in [0, 1] |
| doubleFire | Whether to spawn two bullets (double fire power-up) |
Definition at line 744 of file PlayerShootSystem.cpp.
References _chargedBulletSpeed, _networkSync, _registry, _roomSystem, _spawnOffsetX, rtp::ecs::Registry::add(), rtp::net::ChargedBullet, rtp::net::EntitySpawn, rtp::log::error(), rtp::ecs::Registry::get(), rtp::server::RoomSystem::getRoom(), rtp::ecs::components::RoomId::id, rtp::ecs::Entity::index(), rtp::server::Room::InGame, rtp::ecs::components::Boomerang::maxDistance, rtp::ecs::components::Boomerang::ownerIndex, rtp::ecs::components::Transform::position, rtp::ecs::components::Homing::range, rtp::ecs::components::Boomerang::returning, rtp::server::NetworkSyncSystem::sendPacketToSessions(), rtp::ecs::Registry::spawn(), rtp::ecs::components::Boomerang::startPos, rtp::ecs::components::Homing::steering, rtp::net::TCP, rtp::net::EntitySpawnPayload::weaponKind, rtp::Vec2< T >::x, and rtp::Vec2< T >::y.
Referenced by update().
|
private |
Spawn a debug powerup for testing (triggered by P key)
| position | Position to spawn the powerup |
| roomId | Room ID |
| dropRoll | Random roll to determine powerup type (0-29) |
Definition at line 978 of file PlayerShootSystem.cpp.
References _networkSync, _registry, _roomSystem, rtp::ecs::Registry::add(), rtp::ecs::components::DoubleFire, rtp::net::EntitySpawn, rtp::log::error(), rtp::server::RoomSystem::getRoom(), rtp::ecs::components::Heal, rtp::ecs::Entity::index(), rtp::net::PowerupDoubleFire, rtp::net::PowerupHeal, rtp::net::PowerupShield, rtp::server::NetworkSyncSystem::sendPacketToSessions(), rtp::ecs::components::Shield, rtp::ecs::Registry::spawn(), rtp::net::TCP, rtp::Vec2< T >::x, and rtp::Vec2< T >::y.
Referenced by update().
|
overridevirtual |
Update player shoot system logic for one frame.
| dt | Time elapsed since last update in seconds |
Implements rtp::ecs::ISystem.
Definition at line 53 of file PlayerShootSystem.cpp.
References _beamTickTimers, _networkSync, _registry, _roomSystem, rtp::ecs::components::Beam, rtp::net::BeamState, rtp::net::EntityDeath, rtp::ecs::Registry::get(), rtp::server::RoomSystem::getRoom(), rtp::ecs::Entity::index(), rtp::log::info(), rtp::ecs::Registry::kill(), rtp::net::EntityDeathPayload::netId, rtp::ecs::NullEntity, rtp::net::BeamStatePayload::ownerNetId, rtp::net::Player, rtp::ecs::Registry::remove(), rtp::net::ScoreUpdate, sendAmmoUpdate(), rtp::server::NetworkSyncSystem::sendPacketToSession(), rtp::server::NetworkSyncSystem::sendPacketToSessions(), spawnBullet(), spawnChargedBullet(), spawnDebugPowerup(), rtp::net::TCP, rtp::Vec2< T >::x, rtp::Vec2< T >::y, and rtp::ecs::Registry::zipView().
|
private |
Definition at line 108 of file PlayerShootSystem.hpp.
Referenced by update().
|
private |
Speed of the spawned bullets.
Definition at line 103 of file PlayerShootSystem.hpp.
Referenced by spawnBullet().
|
private |
Speed of the charged bullets.
Definition at line 104 of file PlayerShootSystem.hpp.
Referenced by spawnChargedBullet().
|
private |
Reference to the NetworkSyncSystem.
Definition at line 101 of file PlayerShootSystem.hpp.
Referenced by sendAmmoUpdate(), spawnBullet(), spawnChargedBullet(), spawnDebugPowerup(), and update().
|
private |
Reference to the entity registry.
Definition at line 99 of file PlayerShootSystem.hpp.
Referenced by spawnBullet(), spawnChargedBullet(), spawnDebugPowerup(), and update().
|
private |
Reference to the RoomSystem.
Definition at line 100 of file PlayerShootSystem.hpp.
Referenced by spawnBullet(), spawnChargedBullet(), spawnDebugPowerup(), and update().
|
private |
X offset for bullet spawn position.
Definition at line 105 of file PlayerShootSystem.hpp.
Referenced by spawnBullet(), and spawnChargedBullet().