Skip to content

Commit

Permalink
CLIENT-MENU: Merge the-merge to make this branch up to date
Browse files Browse the repository at this point in the history
MINOR
  • Loading branch information
KitetsuK committed Nov 5, 2023
2 parents fbd83c5 + 4383f6c commit 7daad0e
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 159 deletions.
1 change: 1 addition & 0 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ namespace Menu {
auto idsButton = Registry::getInstance().getEntitiesByComponents({typeid(Types::Button)});
auto arrButton = Registry::getInstance().getComponents<Types::Button>();

Logger::error("!!!!!!!!!!!sendReadyPacket!!!!!!");
Nitwork::NitworkClient::getInstance().addReadyMsg();
for (auto &id : idsButton) {
Registry::getInstance().removeEntity(id);
Expand Down
17 changes: 16 additions & 1 deletion src/Client/Systems/Menus/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,28 @@ namespace Systems {
Json::getInstance().getDatasFromList(jsonData));
}

static void preloadTexture()
{
std::vector<std::string> textures = Json::getInstance().getDatasByKey(
{ResourcesManager::getPathByJsonType(JsonType::ENEMIES),
ResourcesManager::getPathByJsonType(JsonType::DEFAULT_PARALLAX),
ResourcesManager::getPathByJsonType(JsonType::DEFAULT_PLAYER)},
"spritePath");
for (auto elem : textures) {
std::string::iterator end_pos = std::remove(elem.begin(), elem.end(), '"');
elem.erase(end_pos, elem.end());
Raylib::TextureManager::getInstance().preloadTexture(elem);
}
}

void initSceneGame(std::size_t managerId, std::size_t systemId)
{
if (Scene::SceneManager::getInstance().getCurrentScene() != GAME) {
return;
}
try {
Parallax::initParalax();
// Parallax::initParalax();
preloadTexture();
initHud();
} catch (std::runtime_error &err) {
Logger::info(err.what());
Expand Down
15 changes: 8 additions & 7 deletions src/Game/CreateMissiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace Systems {
const std::string bulletPath = json.getDataFromJson<std::string>(bulletData, "spritePath");
Types::Rect spriteRect = json.getDataFromJson<Types::Rect>(bulletData, "spriteRect");
Types::SpriteDatas
bulletDatas(bulletPath, collisionRect.width, collisionRect.height, DEFAULTLAYER, 0);
bulletDatas(bulletPath, collisionRect.width, collisionRect.height, FRONTLAYER, 0);
Registry::getInstance().getComponents<Types::SpriteDatas>().insertBack(bulletDatas);
Registry::getInstance().getComponents<Types::Rect>().insertBack(spriteRect);

Expand All @@ -101,15 +101,15 @@ namespace Systems {

std::size_t createPlayerMissile(Types::Position pos, Types::Missiles &typeOfMissile)
{
Logger::fatal("Create missile");
if (typeOfMissile.type >= MAX_MISSILE_TYPE || typeOfMissile.type < 0) {
throw std::runtime_error("Unknown missile type");
}
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");
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");
Types::CollisionRect collisionRect =
json.getDataFromJson<Types::CollisionRect>(bulletData, "collisionRect");
Types::Velocity velocity = json.getDataFromJson<Types::Velocity>(bulletData, "velocity");
Expand All @@ -126,6 +126,7 @@ 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));
Registry::getInstance().getComponents<Types::Position>().insertBack(pos);
Registry::getInstance().getComponents<Types::CollisionRect>().insertBack(collisionRect);
Registry::getInstance().getComponents<Types::Missiles>().insertBack(missileType);
Expand Down
6 changes: 2 additions & 4 deletions src/Game/GameSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ namespace Systems {
Registry::getInstance().getComponents<Types::Player>();
auto arrHealth = Registry::getInstance().getComponents<Types::Health>();

struct health_s health = {arrHealth[id].hp};
if (arrPlayer.exist(id)) {
Nitwork::NitworkClient::getInstance().addLifeUpdateMsg(
arrPlayer[id].constId,
{arrHealth[id].hp});
Nitwork::NitworkClient::getInstance().addLifeUpdateMsg(arrPlayer[id].constId, health);
}
}

Expand Down Expand Up @@ -148,7 +147,6 @@ namespace Systems {
registry.addEventCallback(Events::ENTITY_DEATH, sendMissileDeath);
#ifdef CLIENT
registry.addEventCallback(Events::ENTITY_DEATH, sendPlayerDeathToServer);

registry.addEventCallback(Events::TAKE_DAMAGE, sendLifeUpdateToServer);
#endif
registry.addAllie(static_cast<std::size_t>(AlliesType::PLAYERS), typeid(Types::Player));
Expand Down
2 changes: 0 additions & 2 deletions src/Nitwork/ANitwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ namespace Nitwork {
});
for (auto &action : _actions) {
try {
Logger::fatal(
"NITWORK: Adding action to queue: " + std::to_string(action.first.id));
action.second(action.first.data, action.first.endpoint);
} catch (std::exception &e) {
Logger::fatal("StartInputHandler:");
Expand Down
7 changes: 7 additions & 0 deletions src/Nitwork/ANitwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "B-luga/Logger.hpp"
#include "INitwork.hpp"
#include "Zstd.hpp"
#include <type_traits>

namespace Nitwork {

Expand Down Expand Up @@ -63,9 +64,15 @@ namespace Nitwork {
HEADER_CODE2};
data.header = newHeader;
}
#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));
}
#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
6 changes: 3 additions & 3 deletions src/Nitwork/MessageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ enum enemy_type_e {

enum missileTypes_e {
CLASSIC = 0,
FAST,
BOUNCE,
PERFORANT,
FAST = 1,
BOUNCE = 2,
PERFORANT = 3,
MAX_MISSILE_TYPE
};

Expand Down
48 changes: 24 additions & 24 deletions src/Nitwork/Nitwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@ typedef unsigned char n_nbAction_t;
*/
enum n_actionType_t {
NO_ACTION = 0,
INIT = 1,
READY = 2,
START_WAVE = 3,
LIFE_UPDATE = 5,
ENEMY_DEATH = 6,
POSITION_RELATIVE = 7,
POSITION_ABSOLUTE = 8,
NEW_MISSILE = 9,
NEW_ENEMY = 10,
NEW_PLAYER = 11,
POSITION_RELATIVE_BROADCAST = 12,
POSITION_ABSOLUTE_BROADCAST = 13,
PLAYER_DEATH = 14,
MISSILE_DEATH = 15,
LIST_LOBBY = 16,
INFO_LOBBY = 17,
CONNECT_MAIN_SERVER = 18,
CONNECT_MAIN_SERVER_RESP = 19,
CONNECT_LOBBY = 20,
CONNECT_LOBBY_RESP = 21,
DISCONNECT_LOBBY = 22,
CREATE_LOBBY = 23,
END_GAME = 24,
N_ACTION_TYPE_MAX,
NITWORK_INIT = 1,
NITWORK_READY = 2,
NITWORK_START_WAVE = 3,
NITWORK_LIFE_UPDATE = 5,
NITWORK_ENEMY_DEATH = 6,
NITWORK_POSITION_RELATIVE = 7,
NITWORK_POSITION_ABSOLUTE = 8,
NITWORK_NEW_MISSILE = 9,
NITWORK_NEW_ENEMY = 10,
NITWORK_NEW_PLAYER = 11,
NITWORK_POSITION_RELATIVE_BROADCAST = 12,
NITWORK_POSITION_ABSOLUTE_BROADCAST = 13,
NITWORK_PLAYER_DEATH = 14,
NITWORK_MISSILE_DEATH = 15,
NITWORK_LIST_LOBBY = 16,
NITWORK_INFO_LOBBY = 17,
NITWORK_CONNECT_MAIN_SERVER = 18,
NITWORK_CONNECT_MAIN_SERVER_RESP = 19,
NITWORK_CONNECT_LOBBY = 20,
NITWORK_CONNECT_LOBBY_RESP = 21,
NITWORK_DISCONNECT_LOBBY = 22,
NITWORK_CREATE_LOBBY = 23,
NITWORK_END_GAME = 24,
NITWORK_N_ACTION_TYPE_MAX,
};

PACK(struct header_s {
Expand Down
37 changes: 23 additions & 14 deletions src/Nitwork/NitworkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = DISCONNECT_LOBBY,
.magick = NITWORK_DISCONNECT_LOBBY,
},
.msg = {.magick = 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 @@ -168,10 +169,11 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = INIT,
.magick = NITWORK_INIT,
},
.msgInit = {.magick = 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 @@ -184,9 +186,10 @@ namespace Nitwork {
std::lock_guard<std::mutex> lock(_receivedPacketsIdsMutex);
struct packetMsgReady_s packetMsgReady = {
.header = {0, 0, 0, 0, 1, 0},
.action = {.magick = READY},
.action = {.magick = NITWORK_READY},
.msgReady = {.magick = 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 All @@ -201,7 +204,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = POSITION_RELATIVE,
.magick = NITWORK_POSITION_RELATIVE,
},
.msg =
{
Expand All @@ -225,7 +228,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = NEW_MISSILE,
.magick = NITWORK_NEW_MISSILE,
},
.msg =
{
Expand All @@ -250,7 +253,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = POSITION_ABSOLUTE,
.magick = NITWORK_POSITION_ABSOLUTE,
},
.msg =
{
Expand All @@ -273,7 +276,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = LIFE_UPDATE,
.magick = NITWORK_LIFE_UPDATE,
},
.msgLifeUpdate =
{
Expand All @@ -282,6 +285,7 @@ namespace Nitwork {
.life = life,
},
};
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 All @@ -297,7 +301,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = ENEMY_DEATH,
.magick = NITWORK_ENEMY_DEATH,
},
.msgEnemyDeath =
{
Expand All @@ -319,7 +323,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = PLAYER_DEATH,
.magick = NITWORK_PLAYER_DEATH,
},
.msg = {.magick = MAGICK_PLAYER_DEATH, .playerId = id},
};
Expand All @@ -337,14 +341,15 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = MISSILE_DEATH,
.magick = NITWORK_MISSILE_DEATH,
},
.msgMissileDeath =
{
.magick = MAGICK_MISSILE_DEATH,
.missileId = id,
},
};
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 @@ -358,10 +363,11 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = LIST_LOBBY,
.magick = NITWORK_LIST_LOBBY,
},
.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));
Packet packet(
packetListLobby.action.magick,
std::make_any<struct packetRequestListLobby_s>(packetListLobby),
Expand All @@ -379,7 +385,7 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = CREATE_LOBBY,
.magick = NITWORK_CREATE_LOBBY,
},
.msg = {
.magick = MAGICK_CREATE_LOBBY,
Expand All @@ -388,6 +394,7 @@ 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));
std::strcpy(packetCreateLobby.msg.name, (name.size() > 32 ? name.substr(0, 32) : name).c_str());
std::strcpy(
packetCreateLobby.msg.ownerInfos.ip,
Expand All @@ -409,10 +416,11 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = CONNECT_MAIN_SERVER,
.magick = NITWORK_CONNECT_MAIN_SERVER,
},
.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));
Packet packet(
packetConnectMainServer.action.magick,
std::make_any<struct packetConnectMainServer_s>(packetConnectMainServer),
Expand Down Expand Up @@ -496,10 +504,11 @@ namespace Nitwork {
.header = {0, 0, 0, 0, 1, 0},
.action =
{
.magick = CONNECT_LOBBY,
.magick = NITWORK_CONNECT_LOBBY,
},
.msg = {.magick = 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
Loading

0 comments on commit 7daad0e

Please sign in to comment.