-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(ShootSystem): Send packet create shoot
I've send the packet from the system who create the shoot to communicate with other client
- Loading branch information
Showing
9 changed files
with
179 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
R-TypeGame/SystemNetworkUpdate/UpdateShootSystem/updateShootSystem.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** UpdateShootComponent | ||
** File description: | ||
** UpdateShootComponent | ||
*/ | ||
|
||
#include "ShootSystem.hpp" | ||
#include "ShootInitSystem.hpp" | ||
#include "PlayerComponent.hpp" | ||
#include "updateShootSystem.hpp" | ||
#include "Position2DComponent.hpp" | ||
|
||
void UpdateShootSystem::_updateShootSystem(Network::UDPPacket packet, ECS::Registry& reg) | ||
{ | ||
try { | ||
uint32_t componentTypeLength = static_cast<size_t>(packet.getPayload()[0]); | ||
|
||
if (packet.getPayload().size() < 1 + componentTypeLength + 1 * sizeof(int)) { | ||
std::cerr << "Payload is too small." << std::endl; | ||
return; | ||
} | ||
|
||
std::string componentType(packet.getPayload().begin() + 1, packet.getPayload().begin() + 1 + componentTypeLength); | ||
|
||
int idxPacketEntities = (packet.getPayload()[1 + componentTypeLength] << 24) | | ||
(packet.getPayload()[2 + componentTypeLength] << 16) | | ||
(packet.getPayload()[3 + componentTypeLength] << 8) | | ||
packet.getPayload()[4 + componentTypeLength]; | ||
|
||
ECS::entity_t shoot = reg.spawn_entity(); | ||
ShootInitSystem().getFunction()(reg, shoot); | ||
|
||
ECS::SparseArray<IComponent> positions = reg.get_components<IComponent>("Position2DComponent"); | ||
|
||
if (positions.size() > shoot && positions.size() > idxPacketEntities) { | ||
std::shared_ptr<Position2DComponent> position = std::dynamic_pointer_cast<Position2DComponent>(positions[shoot]); | ||
std::shared_ptr<Position2DComponent> positionPlayer = std::dynamic_pointer_cast<Position2DComponent>(positions[idxPacketEntities]); | ||
|
||
if (position && positionPlayer) { | ||
position->x = positionPlayer->x + POS_PLAYER_X; | ||
position->y = positionPlayer->y + POS_PLAYER_Y; | ||
} | ||
} | ||
|
||
} catch (std::exception e){ | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
} | ||
} | ||
|
||
extern "C" ISystemNetworkUpdate* loadUpdateInstance() | ||
{ | ||
return new UpdateShootSystem(); | ||
} |
49 changes: 49 additions & 0 deletions
49
R-TypeGame/SystemNetworkUpdate/UpdateShootSystem/updateShootSystem.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** UpdateShootSystem | ||
** File description: | ||
** UpdateShootSystem | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <iostream> | ||
|
||
#include "ISystemNetworkUpdate.hpp" | ||
|
||
/** | ||
* @brief Update shoot system. | ||
* | ||
*/ | ||
class UpdateShootSystem : public ISystemNetworkUpdate { | ||
|
||
public: | ||
|
||
/** | ||
* @brief Construct a new UpdateShootSystem System object. | ||
* | ||
*/ | ||
UpdateShootSystem() = default; | ||
|
||
/** | ||
* @brief Destroy the UpdateShootSystem System object. | ||
* | ||
*/ | ||
~UpdateShootSystem() = default; | ||
|
||
/** | ||
* @brief Get the Function object. | ||
* | ||
* @return std::function<void(ECS::Registry& reg, int idxPacketEntities)> | ||
*/ | ||
std::function<void(Network::UDPPacket, ECS::Registry&)> getFunction() | ||
{ | ||
return [this](Network::UDPPacket packet, ECS::Registry& reg) { | ||
_updateShootSystem(packet, reg); | ||
}; | ||
} | ||
|
||
private: | ||
|
||
void _updateShootSystem(Network::UDPPacket packet, ECS::Registry& reg); //The system to update shoot. | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters