Skip to content

Commit

Permalink
FORMAT-AUTO: automatic format on pull request #142
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 5, 2023
1 parent 7daad0e commit 2c7a154
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 54 deletions.
33 changes: 18 additions & 15 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -71,18 +71,21 @@ namespace Menu {
void createServer();

const std::unordered_map<CallbackType, std::function<void()>> 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
5 changes: 3 additions & 2 deletions src/Client/Systems/Menus/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ namespace Menu {

static std::size_t initButtonFromSprite(nlohmann::json &elem, std::function<void()> &callback)
{

std::size_t id = Registry::getInstance().addEntity();
initFromSprite(elem);
std::string name = Json::isDataExist(elem, "name") ? Json::getInstance().getDataFromJson<std::string>(elem, "name") : "";
std::string name = Json::isDataExist(elem, "name")
? Json::getInstance().getDataFromJson<std::string>(elem, "name")
: "";
Types::Button button(callback, name);
Types::Position position = {
Types::Position(Json::getInstance().getDataFromJson<Types::Position>(elem, "position"))};
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Systems/Menus/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace Systems {
return;
}
try {
// Parallax::initParalax();
// Parallax::initParalax();
preloadTexture();
initHud();
} catch (std::runtime_error &err) {
Expand Down
14 changes: 9 additions & 5 deletions src/Game/CreateMissiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(ResourcesManager::getPathByJsonType(JsonType::BULLETS), getMissileIdFromType(typeOfMissile.type), "bullets");
Json &json = Json::getInstance();
std::size_t id = Registry::getInstance().addEntity();
nlohmann::json bulletData = json.getJsonObjectById<std::string>(
ResourcesManager::getPathByJsonType(JsonType::BULLETS),
getMissileIdFromType(typeOfMissile.type),
"bullets");
Types::CollisionRect collisionRect =
json.getDataFromJson<Types::CollisionRect>(bulletData, "collisionRect");
Types::Velocity velocity = json.getDataFromJson<Types::Velocity>(bulletData, "velocity");
Expand All @@ -126,7 +128,9 @@ namespace Systems {

Registry::getInstance().getComponents<Types::PlayerAllies>().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<Types::Position>().insertBack(pos);
Registry::getInstance().getComponents<Types::CollisionRect>().insertBack(collisionRect);
Registry::getInstance().getComponents<Types::Missiles>().insertBack(missileType);
Expand Down
7 changes: 4 additions & 3 deletions src/Nitwork/ANitwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include <list>
#include <memory>
#include <mutex>
#include <type_traits>
#include <unordered_map>
#include "B-luga/Logger.hpp"
#include "INitwork.hpp"
#include "Zstd.hpp"
#include <type_traits>

namespace Nitwork {

Expand Down Expand Up @@ -66,13 +66,14 @@ namespace Nitwork {
}
#ifdef DEBUG
if constexpr (!std::is_same_v<T, struct packetListLobby_s>) {
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<std::vector<char>> compressedPacket =
std::make_shared<std::vector<char>>(Zstd::compress(data));


_socket.async_send_to(
boost::asio::buffer(*compressedPacket),
packet.endpoint,
Expand Down
37 changes: 28 additions & 9 deletions src/Nitwork/NitworkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<struct packetDisconnectLobby_s>(packetDisconnectLobby),
Expand All @@ -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<struct packetMsgInit_s>(packetMsgInit),
Expand All @@ -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<struct packetMsgReady_s>(packetMsgReady),
Expand Down Expand Up @@ -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<struct packetLifeUpdate_s>(packetLifeUpdate),
Expand Down Expand Up @@ -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<struct packetMissileDeath_s>(packetMissileDeath),
Expand All @@ -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<struct packetRequestListLobby_s>(packetListLobby),
Expand All @@ -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,
Expand All @@ -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<struct packetConnectMainServer_s>(packetConnectMainServer),
Expand Down Expand Up @@ -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<struct packetConnectLobby_s>(packetConnectLobby),
Expand Down
8 changes: 5 additions & 3 deletions src/Nitwork/NitworkServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -265,7 +266,8 @@ namespace Nitwork {
_isGameStarted = true;
auto &director = Systems::SystemManagersDirector::getInstance();
std::lock_guard<std::mutex> lock(director.mutex);
director.getSystemManager(static_cast<std::size_t>(SystemManagers::GAME_LOGIC)).addSystem(Systems::waveHandler);
director.getSystemManager(static_cast<std::size_t>(SystemManagers::GAME_LOGIC))
.addSystem(Systems::waveHandler);
}

void
Expand Down
27 changes: 14 additions & 13 deletions src/Nitwork/NitworkServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,52 +356,53 @@ namespace Nitwork {
{NITWORK_CONNECT_LOBBY_RESP,
[this](Packet &packet) {
sendData<struct packetConnectLobbyResp_s>(packet);
} },
}},
{NITWORK_INIT,
[this](Packet &packet) {
sendData<struct packetCreatePlayer_s>(packet);
} },
}},
{NITWORK_LIFE_UPDATE,
[this](Packet &packet) {
sendData<struct packetLifeUpdate_s>(packet);
} },
}},
{NITWORK_START_WAVE,
[this](Packet &packet) {
sendData<struct packetMsgStartWave_s>(packet);
} },
}},
{NITWORK_ENEMY_DEATH,
[this](Packet &packet) {
sendData<struct packetEnemyDeath_s>(packet);
} },
}},
{NITWORK_NEW_ENEMY,
[this](Packet &packet) {
sendData<struct packetNewEnemy_s>(packet);
} },
}},
{NITWORK_NEW_MISSILE,
[this](Packet &packet) {
sendData<struct packetNewBullet_s>(packet);
} },
}},
{NITWORK_NEW_PLAYER,
[this](Packet &packet) {
sendData<struct packetCreatePlayer_s>(packet);
} },
}},
{NITWORK_POSITION_RELATIVE_BROADCAST,
[this](Packet &packet) {
sendData<struct packetPositionRelativeBroadcast_s>(packet);
} },
}},
{NITWORK_POSITION_ABSOLUTE_BROADCAST,
[this](Packet &packet) {
sendData<struct packetPositionAbsoluteBroadcast_s>(packet);
} },
}},
{NITWORK_PLAYER_DEATH,
[this](Packet &packet) {
sendData<struct packetPlayerDeath_s>(packet);
} },
}},
{NITWORK_MISSILE_DEATH,
[this](Packet &packet) {
sendData<struct packetMissileDeath_s>(packet);
} },
{NITWORK_INFO_LOBBY, [this](Packet &packet) {
}},
{NITWORK_INFO_LOBBY,
[this](Packet &packet) {
sendData<struct packetInfoLobby_s>(packet);
}},
{NITWORK_END_GAME,
Expand Down
6 changes: 3 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2c7a154

Please sign in to comment.