diff --git a/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp b/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp index 4e625d79..6657caba 100644 --- a/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp +++ b/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp @@ -41,9 +41,9 @@ namespace Menu { {GO_SELECT_LOBBY, "goToSelectLobby" }, {CREATE_NORMAL, "onButtonCreateLobbyNormalClicked"}, {SEND_READY, "sendReadyPacket" }, - {GO_CREATE_SERVER, "goCreateServer" }, - {CREATE_SERVER, "createServer" }, - {GO_MENU, "goToMenu" }, + {GO_CREATE_SERVER, "goCreateServer" }, + {CREATE_SERVER, "createServer" }, + {GO_MENU, "goToMenu" }, }); void initConnection(); @@ -71,18 +71,21 @@ namespace Menu { void createServer(); const std::unordered_map> callbacks = { - {CallbackType::DEFAULT_CALLBACK, &defaultCallBack }, - {CallbackType::INIT_CONNECTION, &initConnection }, - {CallbackType::CONNECT, &connectLobbySelected }, - {CallbackType::CREATE, &onButtonGotoCreateLobbyClicked }, - {CallbackType::GO_SELECT_LOBBY, &gotToSelectLobby }, - {CallbackType::GO_BACK, &goBackPage }, - {CallbackType::GO_NEXT, &goNextPage }, - {CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked}, - {CallbackType::SEND_READY, &sendReadyPacket }, - {CallbackType::GO_CREATE_SERVER, &goCreateServer }, - {CallbackType::CREATE_SERVER, &createServer }, - {CallbackType::GO_MENU, &goMenu, } + {CallbackType::DEFAULT_CALLBACK, &defaultCallBack}, + {CallbackType::INIT_CONNECTION, &initConnection}, + {CallbackType::CONNECT, &connectLobbySelected}, + {CallbackType::CREATE, &onButtonGotoCreateLobbyClicked}, + {CallbackType::GO_SELECT_LOBBY, &gotToSelectLobby}, + {CallbackType::GO_BACK, &goBackPage}, + {CallbackType::GO_NEXT, &goNextPage}, + {CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked}, + {CallbackType::SEND_READY, &sendReadyPacket}, + {CallbackType::GO_CREATE_SERVER, &goCreateServer}, + {CallbackType::CREATE_SERVER, &createServer}, + { + CallbackType::GO_MENU, + &goMenu, + } }; } // namespace Callback } // namespace Menu diff --git a/src/Client/Systems/Menus/Menu/Menu.cpp b/src/Client/Systems/Menus/Menu/Menu.cpp index 3a91a5f6..2e676237 100644 --- a/src/Client/Systems/Menus/Menu/Menu.cpp +++ b/src/Client/Systems/Menus/Menu/Menu.cpp @@ -128,10 +128,11 @@ namespace Menu { static std::size_t initButtonFromSprite(nlohmann::json &elem, std::function &callback) { - std::size_t id = Registry::getInstance().addEntity(); initFromSprite(elem); - std::string name = Json::isDataExist(elem, "name") ? Json::getInstance().getDataFromJson(elem, "name") : ""; + std::string name = Json::isDataExist(elem, "name") + ? Json::getInstance().getDataFromJson(elem, "name") + : ""; Types::Button button(callback, name); Types::Position position = { Types::Position(Json::getInstance().getDataFromJson(elem, "position"))}; diff --git a/src/Client/Systems/Menus/Menu/MenuSystems.cpp b/src/Client/Systems/Menus/Menu/MenuSystems.cpp index 93a7c1c6..5f107b1f 100644 --- a/src/Client/Systems/Menus/Menu/MenuSystems.cpp +++ b/src/Client/Systems/Menus/Menu/MenuSystems.cpp @@ -250,7 +250,7 @@ namespace Systems { return; } try { -// Parallax::initParalax(); + // Parallax::initParalax(); preloadTexture(); initHud(); } catch (std::runtime_error &err) { diff --git a/src/Game/CreateMissiles.cpp b/src/Game/CreateMissiles.cpp index a629fd3e..5d140189 100644 --- a/src/Game/CreateMissiles.cpp +++ b/src/Game/CreateMissiles.cpp @@ -106,10 +106,12 @@ namespace Systems { throw std::runtime_error("Unknown missile type"); } Logger::fatal("Create missile2"); - Json &json = Json::getInstance(); - std::size_t id = Registry::getInstance().addEntity(); - nlohmann::json bulletData = - json.getJsonObjectById(ResourcesManager::getPathByJsonType(JsonType::BULLETS), getMissileIdFromType(typeOfMissile.type), "bullets"); + Json &json = Json::getInstance(); + std::size_t id = Registry::getInstance().addEntity(); + nlohmann::json bulletData = json.getJsonObjectById( + ResourcesManager::getPathByJsonType(JsonType::BULLETS), + getMissileIdFromType(typeOfMissile.type), + "bullets"); Types::CollisionRect collisionRect = json.getDataFromJson(bulletData, "collisionRect"); Types::Velocity velocity = json.getDataFromJson(bulletData, "velocity"); @@ -126,7 +128,9 @@ namespace Systems { Registry::getInstance().getComponents().insertBack(playerAlliesComp); addPhysicsToEntity(bulletData, pos); - Logger::fatal("type of missile = " + std::to_string(typeOfMissile.type) + " pos = " + std::to_string(pos.x) + " " + std::to_string(pos.y)); + Logger::fatal( + "type of missile = " + std::to_string(typeOfMissile.type) + " pos = " + std::to_string(pos.x) + + " " + std::to_string(pos.y)); Registry::getInstance().getComponents().insertBack(pos); Registry::getInstance().getComponents().insertBack(collisionRect); Registry::getInstance().getComponents().insertBack(missileType); diff --git a/src/Nitwork/ANitwork.hpp b/src/Nitwork/ANitwork.hpp index cc1dfba7..9475feb8 100644 --- a/src/Nitwork/ANitwork.hpp +++ b/src/Nitwork/ANitwork.hpp @@ -12,11 +12,11 @@ #include #include #include +#include #include #include "B-luga/Logger.hpp" #include "INitwork.hpp" #include "Zstd.hpp" -#include namespace Nitwork { @@ -66,13 +66,14 @@ namespace Nitwork { } #ifdef DEBUG if constexpr (!std::is_same_v) { - Logger::fatal("id of packet = " + std::to_string(id) + " action type = " + std::to_string(data.action.magick)); + Logger::fatal( + "id of packet = " + std::to_string(id) + + " action type = " + std::to_string(data.action.magick)); } #endif std::shared_ptr> compressedPacket = std::make_shared>(Zstd::compress(data)); - _socket.async_send_to( boost::asio::buffer(*compressedPacket), packet.endpoint, diff --git a/src/Nitwork/NitworkClient.cpp b/src/Nitwork/NitworkClient.cpp index f158b5be..37fcd20f 100644 --- a/src/Nitwork/NitworkClient.cpp +++ b/src/Nitwork/NitworkClient.cpp @@ -153,7 +153,9 @@ namespace Nitwork { }, .msg = {.magick = MAGICK_DISCONNECT_LOBBY}, }; - Logger::error("------------------------------------ Sending disconnect lobby msg: " + std::to_string(NITWORK_DISCONNECT_LOBBY) + " " + std::to_string(MAGICK_DISCONNECT_LOBBY)); + Logger::error( + "------------------------------------ Sending disconnect lobby msg: " + + std::to_string(NITWORK_DISCONNECT_LOBBY) + " " + std::to_string(MAGICK_DISCONNECT_LOBBY)); Packet packet( packetDisconnectLobby.action.magick, std::make_any(packetDisconnectLobby), @@ -173,7 +175,9 @@ namespace Nitwork { }, .msgInit = {.magick = MAGICK_INIT} }; - Logger::error("------------------------------------ Sending init msg: " + std::to_string(NITWORK_INIT) + " " + std::to_string(MAGICK_INIT)); + Logger::error( + "------------------------------------ Sending init msg: " + std::to_string(NITWORK_INIT) + " " + + std::to_string(MAGICK_INIT)); Packet packet( packetMsgInit.action.magick, std::make_any(packetMsgInit), @@ -189,7 +193,9 @@ namespace Nitwork { .action = {.magick = NITWORK_READY}, .msgReady = {.magick = MAGICK_READY} }; - Logger::error("------------------------------------ Sending ready msg: " + std::to_string(NITWORK_READY) + " " + std::to_string(MAGICK_READY)); + Logger::error( + "------------------------------------ Sending ready msg: " + std::to_string(NITWORK_READY) + " " + + std::to_string(MAGICK_READY)); Packet packet( packetMsgReady.action.magick, std::make_any(packetMsgReady), @@ -285,7 +291,9 @@ namespace Nitwork { .life = life, }, }; - Logger::error("------------------------------------ Sending life update msg: " + std::to_string(playerId) + " " + std::to_string(MAGICK_LIFE_UPDATE)); + Logger::error( + "------------------------------------ Sending life update msg: " + std::to_string(playerId) + + " " + std::to_string(MAGICK_LIFE_UPDATE)); Packet packet( packetLifeUpdate.action.magick, std::make_any(packetLifeUpdate), @@ -349,7 +357,9 @@ namespace Nitwork { .missileId = id, }, }; - Logger::error("------------------------------------ Sending missile death msg: " + std::to_string(NITWORK_MISSILE_DEATH) + " " + std::to_string(MAGICK_MISSILE_DEATH)); + Logger::error( + "------------------------------------ Sending missile death msg: " + + std::to_string(NITWORK_MISSILE_DEATH) + " " + std::to_string(MAGICK_MISSILE_DEATH)); Packet packet( packetMissileDeath.action.magick, std::make_any(packetMissileDeath), @@ -367,7 +377,9 @@ namespace Nitwork { }, .msg = {.magick = MAGICK_REQUEST_LIST_LOBBY}, }; - Logger::error("------------------------------------ Sending list lobby msg: " + std::to_string(NITWORK_LIST_LOBBY) + " " + std::to_string(MAGICK_REQUEST_LIST_LOBBY)); + Logger::error( + "------------------------------------ Sending list lobby msg: " + + std::to_string(NITWORK_LIST_LOBBY) + " " + std::to_string(MAGICK_REQUEST_LIST_LOBBY)); Packet packet( packetListLobby.action.magick, std::make_any(packetListLobby), @@ -394,7 +406,9 @@ namespace Nitwork { .maxNbPlayer = maxNbPlayer, .ownerInfos = {.ip = "", .port = _mainServerEndpoint.port()}} }; - Logger::error("------------------------------------ Sending create lobby msg: " + std::to_string(NITWORK_CREATE_LOBBY) + " " + std::to_string(MAGICK_CREATE_LOBBY)); + Logger::error( + "------------------------------------ Sending create lobby msg: " + + std::to_string(NITWORK_CREATE_LOBBY) + " " + std::to_string(MAGICK_CREATE_LOBBY)); std::strcpy(packetCreateLobby.msg.name, (name.size() > 32 ? name.substr(0, 32) : name).c_str()); std::strcpy( packetCreateLobby.msg.ownerInfos.ip, @@ -420,7 +434,10 @@ namespace Nitwork { }, .msg = {.magick = MAGICK_CONNECT_MAIN_SERVER}, }; - Logger::error("------------------------------------ Sending connect main server msg: " + std::to_string(NITWORK_CONNECT_MAIN_SERVER) + " " + std::to_string(MAGICK_CONNECT_MAIN_SERVER)); + Logger::error( + "------------------------------------ Sending connect main server msg: " + + std::to_string(NITWORK_CONNECT_MAIN_SERVER) + " " + + std::to_string(MAGICK_CONNECT_MAIN_SERVER)); Packet packet( packetConnectMainServer.action.magick, std::make_any(packetConnectMainServer), @@ -508,7 +525,9 @@ namespace Nitwork { }, .msg = {.magick = MAGICK_CONNECT_LOBBY}, }; - Logger::error("------------------------------------ Sending connect lobby msg: " + std::to_string(NITWORK_CONNECT_LOBBY) + " " + std::to_string(MAGICK_CONNECT_LOBBY)); + Logger::error( + "------------------------------------ Sending connect lobby msg: " + + std::to_string(NITWORK_CONNECT_LOBBY) + " " + std::to_string(MAGICK_CONNECT_LOBBY)); Packet packet( packetConnectLobby.action.magick, std::make_any(packetConnectLobby), diff --git a/src/Nitwork/NitworkServer.cpp b/src/Nitwork/NitworkServer.cpp index e707f94f..95730f4f 100644 --- a/src/Nitwork/NitworkServer.cpp +++ b/src/Nitwork/NitworkServer.cpp @@ -88,7 +88,7 @@ namespace Nitwork { // cppcoreguidelines-pro-bounds-pointer-arithmetic) auto action = *actionPtr; - auto it = _actionsHandlers.find(action.magick); + auto it = _actionsHandlers.find(action.magick); std::memmove( _receiveBuffer.data(), _receiveBuffer.data() + sizeof(struct action_s), @@ -188,7 +188,8 @@ namespace Nitwork { Logger::error("Error: magick not matching"); return; } - Logger::error("magick connect lobby = " + std::to_string(msgData.magick) + " (" + MAGICK_CONNECT_LOBBY + ")"); + Logger::error( + "magick connect lobby = " + std::to_string(msgData.magick) + " (" + MAGICK_CONNECT_LOBBY + ")"); if (_endpoints.size() >= _serverInfos.maxNbPlayer) { Logger::error("Too many clients, can't add an other one"); canConnect = false; @@ -265,7 +266,8 @@ namespace Nitwork { _isGameStarted = true; auto &director = Systems::SystemManagersDirector::getInstance(); std::lock_guard lock(director.mutex); - director.getSystemManager(static_cast(SystemManagers::GAME_LOGIC)).addSystem(Systems::waveHandler); + director.getSystemManager(static_cast(SystemManagers::GAME_LOGIC)) + .addSystem(Systems::waveHandler); } void diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index 39641a61..1b55f285 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -356,52 +356,53 @@ namespace Nitwork { {NITWORK_CONNECT_LOBBY_RESP, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_INIT, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_LIFE_UPDATE, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_START_WAVE, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_ENEMY_DEATH, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_NEW_ENEMY, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_NEW_MISSILE, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_NEW_PLAYER, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_POSITION_RELATIVE_BROADCAST, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_POSITION_ABSOLUTE_BROADCAST, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_PLAYER_DEATH, [this](Packet &packet) { sendData(packet); - } }, + }}, {NITWORK_MISSILE_DEATH, [this](Packet &packet) { sendData(packet); - } }, - {NITWORK_INFO_LOBBY, [this](Packet &packet) { + }}, + {NITWORK_INFO_LOBBY, + [this](Packet &packet) { sendData(packet); }}, {NITWORK_END_GAME, diff --git a/src/init.cpp b/src/init.cpp index aef876a2..2997dac6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -65,9 +65,9 @@ void initScenes() }); auto selectLobby = enumListTosizet( {SystemManagers::MENU_SYSTEMS, - SystemManagers::NETWORK_MENU, - SystemManagers::ECSSYSTEMS, - SystemManagers::GRAPHICS}); + SystemManagers::NETWORK_MENU, + SystemManagers::ECSSYSTEMS, + SystemManagers::GRAPHICS}); auto createLobby = enumListTosizet( {SystemManagers::MENU_SYSTEMS, SystemManagers::NETWORK_CREATE_LOBBY,