Skip to content

Commit

Permalink
Merge branch 'the-merge' of github.com:X-R-G-B/R-Bus into the-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Nov 5, 2023
2 parents 732b1c8 + 7943b2e commit b721464
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 169 deletions.
33 changes: 19 additions & 14 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace Systems {
Registry &registry = Registry::getInstance();
Clock &clock_ = registry.getClock();
Registry::components<Types::Position> arrPosition = registry.getComponents<Types::Position>();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
std::vector<std::size_t> ids =
registry.getEntitiesByComponents({typeid(Types::Player), typeid(Types::Position)});

Expand Down Expand Up @@ -164,10 +164,10 @@ namespace Systems {
{
bool isKeyPressed = false;
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry &registry = Registry::getInstance();
Registry::components<Types::Position> arrPos = registry.getComponents<Types::Position>();
Registry &registry = Registry::getInstance();
Registry::components<Types::Position> arrPos = registry.getComponents<Types::Position>();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
std::vector<std::size_t> ids = registry.getEntitiesByComponents(
std::vector<std::size_t> ids = registry.getEntitiesByComponents(
{typeid(Types::Player), typeid(Types::Position), typeid(Types::Health)});
Clock &clock_ = registry.getClock();
static std::size_t clockId = clock_.create(true);
Expand Down Expand Up @@ -223,9 +223,8 @@ namespace Systems {

static bool isGameWin()
{
Registry &registry = Registry::getInstance();
std::vector<std::size_t> idsPlayer =
registry.getEntitiesByComponents({typeid(Types::Player)});
Registry &registry = Registry::getInstance();
std::vector<std::size_t> idsPlayer = registry.getEntitiesByComponents({typeid(Types::Player)});
std::vector<std::size_t> idsOtherPlayer =
registry.getEntitiesByComponents({typeid(Types::OtherPlayer)});

Expand All @@ -237,15 +236,15 @@ namespace Systems {

static void modifEndGameText(const std::string &endGameMessage)
{
bool found = false;
const Raylib::Vector2 pos = {0, 2};
constexpr std::size_t fontSize = 2;
const std::string textKeywordWaveEnd = "WaveText";
const std::string textKeyWordGameEnd = "endGameText";
bool found = false;
const Raylib::Vector2 pos = {0, 2};
constexpr std::size_t fontSize = 2;
const std::string textKeywordWaveEnd = "WaveText";
const std::string textKeyWordGameEnd = "endGameText";

std::vector<std::size_t> ids =
Registry::getInstance().getEntitiesByComponents({typeid(Raylib::TextShared)});
auto &textArray = Registry::getInstance().getComponents<Raylib::TextShared>();
auto &textArray = Registry::getInstance().getComponents<Raylib::TextShared>();

for (auto &id : ids) {
if (textArray[id]->getKeyword() == textKeyWordGameEnd) {
Expand All @@ -259,7 +258,12 @@ namespace Systems {

if (found == false) {
Registry::getInstance().addEntity();
Raylib::TextShared endGameText = Raylib::Text::fromText(endGameMessage, pos, fontSize, Raylib::Color(Raylib::ColorDef::White), textKeyWordGameEnd);
Raylib::TextShared endGameText = Raylib::Text::fromText(
endGameMessage,
pos,
fontSize,
Raylib::Color(Raylib::ColorDef::White),
textKeyWordGameEnd);
Registry::getInstance().getComponents<Raylib::TextShared>().insertBack(endGameText);
}
}
Expand All @@ -283,6 +287,7 @@ namespace Systems {
modifEndGameText(endGameMessage);

if (Registry::getInstance().getClock().elapsedSecondsSince(clockId) >= secondBeforeEnd) {
Nitwork::NitworkClient::getInstance().disconnectLobby();
Scene::SceneManager::getInstance().changeScene(static_cast<std::size_t>(SELECT_LOBBY));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Client/Systems/Menus/CreateLobby/CreateLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include <algorithm>
#include <string>
// #include "CustomTypes.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga-graphics/Raylib/Raylib.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga/SceneManager.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "Menu.hpp"
#include "MessageTypes.h"
#include "NitworkClient.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "B-luga/SceneManager.hpp"
#include "ResourcesManager.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "init.hpp"

namespace Systems {
Expand Down
12 changes: 5 additions & 7 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
*/

#include "ButtonCallbacks.hpp"
// #include "CustomTypes.hpp"
#include "B-luga/Logger.hpp"
#include "NitworkClient.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "B-luga-graphics/Raylib/Raylib.hpp"
#include "B-luga/Logger.hpp"
#include "B-luga/SceneManager.hpp"
#include "NitworkClient.hpp"
#include "SelectLobbySystems.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "init.hpp"

namespace Menu {
Expand Down Expand Up @@ -157,13 +156,12 @@ namespace Menu {
{
auto idsButton = Registry::getInstance().getEntitiesByComponents({typeid(Types::Button)});

Logger::error("!!!!!!!!!!!sendReadyPacket!!!!!!");
Nitwork::NitworkClient::getInstance().addReadyMsg();
for (auto &id : idsButton) {
Registry::getInstance().removeEntity(id);
}
auto &arrText = Registry::getInstance().getComponents<Raylib::TextShared>();
auto idsText = Registry::getInstance().getEntitiesByComponents({typeid(Raylib::TextShared)});
auto &arrText = Registry::getInstance().getComponents<Raylib::TextShared>();
auto idsText = Registry::getInstance().getEntitiesByComponents({typeid(Raylib::TextShared)});
for (auto &id : idsText) {
if (arrText[id]->getCurrentText() == "READY !") {
Registry::getInstance().removeEntity(id);
Expand Down
17 changes: 9 additions & 8 deletions src/Client/Systems/Menus/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Menu {
? Json::getInstance().getDataFromJson<std::string>(elem, "name")
: "";
Types::FontSize fsz({Json::getInstance().getDataFromJson<float>(elem, "textSize")});
auto textComp = Raylib::Text::fromText(text);
auto textComp = Raylib::Text::fromText(text);
std::size_t maxChar(Json::getInstance().getDataFromJson<std::size_t>(elem, "maxChar"));
Types::InputBox inputBox(text, name, maxChar);
auto search =
Expand Down Expand Up @@ -165,10 +165,10 @@ namespace Menu {

static std::size_t initText(nlohmann::json &elem)
{
std::size_t id = Registry::getInstance().addEntity();
std::string text = Json::isDataExist(elem, "text")
? Json::getInstance().getDataFromJson<std::string>(elem, "text")
: "";
std::size_t id = Registry::getInstance().addEntity();
std::string text = Json::isDataExist(elem, "text")
? Json::getInstance().getDataFromJson<std::string>(elem, "text")
: "";
Raylib::TextShared textComp = Raylib::Text::fromText(text);
if (Json::isDataExist(elem, "size")) {
Types::FontSize fsz({Json::getInstance().getDataFromJson<float>(elem, "size")});
Expand All @@ -177,9 +177,10 @@ namespace Menu {
if (Json::isDataExist(elem, "color")) {
auto search = Types::colorMatchStrings.find(
Json::getInstance().getDataFromJson<std::string>(elem, "color"));
Raylib::Color color = search != Types::colorMatchStrings.end() ? Types::colorMatchStrings.at(
Json::getInstance().getDataFromJson<std::string>(elem, "color"))
: Raylib::Color(Raylib::ColorDef::White);
Raylib::Color color = search != Types::colorMatchStrings.end()
? Types::colorMatchStrings.at(
Json::getInstance().getDataFromJson<std::string>(elem, "color"))
: Raylib::Color(Raylib::ColorDef::White);
Registry::getInstance().getComponents<Raylib::Color>().insertBack(color);
}
if (Json::isDataExist(elem, "position")) {
Expand Down
19 changes: 10 additions & 9 deletions src/Client/Systems/Menus/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
*/

#include "MenuSystems.hpp"
#include "B-luga-graphics/Raylib/Graphics/Graphics.hpp"
#include "B-luga-graphics/AnimRect.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "B-luga-graphics/Raylib/Graphics/Graphics.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga/Maths/Maths.hpp"
#include "B-luga/SceneManager.hpp"
#include "Menu.hpp"
#include "SelectLobbySystems.hpp"
#include "NitworkClient.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "SelectLobbySystems.hpp"
#include "init.hpp"

namespace Systems {
Expand Down Expand Up @@ -194,12 +195,13 @@ namespace Systems {
}
try {
Parallax::initParalax();
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>(ResourcesManager::getPathByJsonType(JsonType::MENU), "menu");
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>(
ResourcesManager::getPathByJsonType(JsonType::MENU),
"menu");
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (std::runtime_error &err) {
Logger::info(err.what());
Logger::warn(err.what());
}
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}
Expand All @@ -212,10 +214,9 @@ namespace Systems {
case CREATE_LOBBY_SCENE:
Scene::SceneManager::getInstance().changeScene(SELECT_LOBBY);
break;
case SELECT_LOBBY:
Scene::SceneManager::getInstance().changeScene(MENU);
break;
case SELECT_LOBBY: Scene::SceneManager::getInstance().changeScene(MENU); break;
case GAME:
Nitwork::NitworkClient::getInstance().disconnectLobby();
Scene::SceneManager::getInstance().changeScene(SELECT_LOBBY);
break;
case LOADING_SCREEN:
Expand Down Expand Up @@ -328,7 +329,7 @@ namespace Systems {
Parallax::initParalax();
initHud();
} catch (std::runtime_error &err) {
Logger::info(err.what());
Logger::warn(err.what());
}
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}
Expand Down
17 changes: 10 additions & 7 deletions src/Client/Systems/Menus/SelectLobby/SelectLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "Menu.hpp"
#include "MessageTypes.h"
#include "Parallax.hpp"
#include "NitworkClient.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "init.hpp"

Expand All @@ -37,8 +37,9 @@ namespace Systems::SelectLobbySystems {
}
try {
Parallax::initParalax();
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>(ResourcesManager::getPathByJsonType(JsonType::SELECT_LOBBY), "lobbyMenu");
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>(
ResourcesManager::getPathByJsonType(JsonType::SELECT_LOBBY),
"lobbyMenu");
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (const std::exception &err) {
Expand Down Expand Up @@ -88,7 +89,9 @@ namespace Systems::SelectLobbySystems {
arrPosition[id].y += offset * static_cast<int>(i);
}
if (arrLobbyText.exist(id)) {
Raylib::Vector2 pos(arrLobbyText[id]->getPosition().x, arrLobbyText[id]->getPosition().y);
Raylib::Vector2 pos(
arrLobbyText[id]->getPosition().x,
arrLobbyText[id]->getPosition().y);
pos.y += Maths::intToFloatConservingDecimals(offset) * i;
arrLobbyText[id]->setPosition(pos);
}
Expand Down Expand Up @@ -120,7 +123,7 @@ namespace Systems::SelectLobbySystems {
+ gameTypeToString(arrLobby[ids[index]].gameType);
arrLobbyStatus[lobbyStatusId].ip = std::string(arrLobby[ids[index]].lobbyInfos.ip);
arrLobbyStatus[lobbyStatusId].port = arrLobby[ids[index]].lobbyInfos.port;
Raylib::TextShared text = Raylib::Text::fromText(text_t);
Raylib::TextShared text = Raylib::Text::fromText(text_t);
if (arrLobbyText.exist(lobbyStatusId)) {
arrLobbyText[lobbyStatusId]->setCurrentText(text_t);
}
Expand All @@ -143,8 +146,8 @@ namespace Systems::SelectLobbySystems {
}
Registry::getInstance().getClock().decreaseSeconds(clockId, 1);
// list of all lobby
auto idsLobbyStatus =
Registry::getInstance().getEntitiesByComponents({typeid(LobbyStatus), typeid(Raylib::TextShared)});
auto idsLobbyStatus = Registry::getInstance().getEntitiesByComponents(
{typeid(LobbyStatus), typeid(Raylib::TextShared)});
auto idsClickableLobbys = Registry::getInstance().getEntitiesByComponents(
{typeid(LobbyStatus), typeid(Raylib::TextShared), typeid(Types::InputBox)});
auto ids = Registry::getInstance().getEntitiesByComponents({typeid(struct lobby_s)});
Expand Down
32 changes: 15 additions & 17 deletions src/Client/Systems/Network/ClientNetwork.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#include "ClientNetwork.hpp"
#include <algorithm>
#include "B-luga-graphics/Raylib/Events/Inputs.hpp"
#include "B-luga-graphics/Raylib/Graphics/Graphics.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga-physics/ECSSystems.hpp"
#include "B-luga/Json.hpp"
#include "B-luga/Maths/Maths.hpp"
#include "B-luga/Registry.hpp"
#include "B-luga/SceneManager.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "B-luga-graphics/Raylib/Events/Inputs.hpp"
#include "B-luga-graphics/Raylib/Graphics/Graphics.hpp"
#include "CreateMissiles.hpp"
#include "EventsSystems.hpp"
#include "GameSystems.hpp"
#include "NitworkClient.hpp"
#include "EventsSystems.hpp"
#include "init.hpp"

namespace Systems {
void receiveLifeUpdate(std::any &any, boost::asio::ip::udp::endpoint & /* unused */)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
auto msg = std::any_cast<struct msgLifeUpdate_s>(any);
Registry &registry = Registry::getInstance();
auto msg = std::any_cast<struct msgLifeUpdate_s>(any);
Registry &registry = Registry::getInstance();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
std::vector<std::size_t> ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::Health), typeid(Types::Player)});
std::vector<std::size_t> ids =
Registry::getInstance().getEntitiesByComponents({typeid(Types::Health), typeid(Types::Player)});

if (ids.empty()) {
return;
Expand All @@ -39,8 +39,8 @@ namespace Systems {
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
const auto enemyDeath = std::any_cast<struct msgEnemyDeath_s>(any);
Registry::components<Types::Enemy> enemies = Registry::getInstance().getComponents<Types::Enemy>();
auto &arrHealth = Registry::getInstance().getComponents<Types::Health>();
std::vector<std::size_t> ids = enemies.getExistingsId();
auto &arrHealth = Registry::getInstance().getComponents<Types::Health>();
std::vector<std::size_t> ids = enemies.getExistingsId();

for (auto id : ids) {
if (enemies[id].getConstId().id == enemyDeath.enemyId.id) {
Expand Down Expand Up @@ -84,8 +84,7 @@ namespace Systems {
const auto wave = std::any_cast<struct msgStartWave_s>(any);
Types::WaveInfos::getInstance().setWaveId(wave.waveId);
Types::WaveInfos::getInstance().setWaitingForNextWave(false);
director.getSystemManager(static_cast<std::size_t>(SystemManagers::GAME_LOGIC))
.addSystem(initWave);
director.getSystemManager(static_cast<std::size_t>(SystemManagers::GAME_LOGIC)).addSystem(initWave);
Logger::info("Wave started");
}

Expand Down Expand Up @@ -268,8 +267,8 @@ namespace Systems {
Logger::error("Error: missile not created");
return;
}
missiles[id].constId = msgNewBullet.id;
health[id].hp = msgNewBullet.life;
missiles[id].constId = msgNewBullet.id;
health[id].hp = msgNewBullet.life;
}

void receiveBroadcastAbsolutePosition(std::any &any, boost::asio::ip::udp::endpoint & /* unused*/)
Expand Down Expand Up @@ -303,8 +302,8 @@ namespace Systems {
auto &arrPlayer = Registry::getInstance().getComponents<Types::Player>();
auto &arrOtherPlayers = Registry::getInstance().getComponents<Types::OtherPlayer>();
auto &arrHealth = Registry::getInstance().getComponents<Types::Health>();
auto playersIds = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::Player), typeid(Types::Health)});
auto playersIds =
Registry::getInstance().getEntitiesByComponents({typeid(Types::Player), typeid(Types::Health)});
auto otherPlayersIds = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::OtherPlayer), typeid(Types::Health)});

Expand All @@ -316,7 +315,6 @@ namespace Systems {
}
for (auto &id : otherPlayersIds) {
if (arrOtherPlayers[id].constId == playerDeath.playerId) {
Logger::fatal("Other player death: " + std::to_string(playerDeath.playerId));
arrHealth[id].hp = 0;
return;
}
Expand Down Expand Up @@ -400,7 +398,7 @@ namespace Systems {
}
}

void receiveEndGame(std::any& /*unused*/, boost::asio::ip::udp::endpoint& /*unused*/)
void receiveEndGame(std::any & /*unused*/, boost::asio::ip::udp::endpoint & /*unused*/)
{
auto &director = SystemManagersDirector::getInstance();
std::lock_guard<std::mutex> lock(director.mutex);
Expand Down
Loading

0 comments on commit b721464

Please sign in to comment.