5#include "Logger/Logger.hpp"
6#include "inputAction/InputAction.hpp"
8#include "input/action.hpp"
10#include "components/Animator.hpp"
11#include "components/Bullet.hpp"
12#include "components/Controllable.hpp"
13#include "components/NetworkEntity.hpp"
14#include "components/Transform.hpp"
15#include "components/Velocity.hpp"
17#include "NetworkClient.hpp"
18#include "factoryDataDriven/factoryDataDriven.hpp"
20namespace rtk::systems {
36 std::uint32_t _clientTick{0};
38 static constexpr float SQUARE_2_DIVIDE_BY_2 = 0.7071f;
51 : _inputState(inputState), _eventBus(eventBus),
52 _entityFactory(entityFactory), _networkClient(networkClient) {}
59 void onStart(rtk::ecs::Registry &)
override {
60 LOG_INFO(
"Load Player System");
66 void update(rtk::ecs::Registry &,
float)
override {
68 handleShootingAudio();
73 bool _isChargingShoot{
false};
75 void sendInputsToServer() {
98 _networkClient.
sendInput(_clientTick, networkActions);
101 void handleShootingAudio() {
102 bool isShootPressed =
105 if (isShootPressed) {
106 _isChargingShoot =
true;
107 }
else if (_isChargingShoot) {
108 _isChargingShoot =
false;
116 void onStop(rtk::ecs::Registry &)
override {}
Type indexed publish and subscribe event bus.
Definition busEvents.hpp:20
void publish(const E &event)
Calls every handler registered for the event type.
Definition busEvents.hpp:52
Builds entities from JSON blueprints and registered component builders.
Definition factoryDataDriven.hpp:54
Sends the local player actions to the server every frame and triggers the shot sound.
Definition PlayerSystem.hpp:30
void update(rtk::ecs::Registry &, float) override
Sends an Input message and publishes a shot on button release.
Definition PlayerSystem.hpp:66
void onStart(rtk::ecs::Registry &) override
Logs that the system is loaded.
Definition PlayerSystem.hpp:59
PlayerSystem(rtk::InputState &inputState, busEvent &eventBus, rtk::factory::EntityFactory &entityFactory, rtype::client::NetworkClient &networkClient)
Creates the system.
Definition PlayerSystem.hpp:48
UDP client that performs the handshake, sends inputs and decodes server messages.
Definition NetworkClient.hpp:71
bool isConnected() const
Tells whether the server accepted the handshake.
Definition NetworkClient.cpp:332
void sendInput(std::uint32_t clientTick, rtype::protocol::InputAction actions)
Sends an Input message with the next input sequence number.
Definition NetworkClient.cpp:79
constexpr bool hasAction(uint32_t engineMask, Action action)
Tells whether an action is active in a mask.
Definition action.hpp:40
InputAction
Bit flags of the actions held by a player.
Definition InputPayload.hpp:16
@ NoneAction
No action held.
@ Shoot
Shoot button held.
Published when the local player releases the shoot button.
Definition game.hpp:30