Skip to content

Feature/rb 110 function receive new enemy#84

Merged
Saverio976 merged 12 commits intodevfrom
feature/RB-110-function-receive-new-enemy
Oct 14, 2023
Merged

Feature/rb 110 function receive new enemy#84
Saverio976 merged 12 commits intodevfrom
feature/RB-110-function-receive-new-enemy

Conversation

@guillaumeAbel
Copy link
Copy Markdown
Collaborator

@guillaumeAbel guillaumeAbel commented Oct 13, 2023

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Norm of the code has been respected
  • In what state is your pull request?
  • Ready to merge / Waiting a reviwer to see my work.
  • Work In Progress (WIP) / My work is not finish but i want daily reviews. (Draft)
  • CI Review / I want to see what the CI thinks of my work.
  • Need feedback / Just to have feedback on what i produced. (May not be merged)
  • What kind of change does this PR introduce? (You can choose multiple)
  • Bug fix
  • Feature request
  • New / Updated documentation
  • Testing CI ( Make the pull request in draft mode)
  • What is the current behavior? (link an issue based on the kind of change this pr introduce)

  • What is the new behavior (if this is a feature change)?

  • Other information:

Summary by CodeRabbit

  • New Feature: Added network system manager to enhance multiplayer capabilities.
  • New Feature: Introduced parallax effect management for improved visual experience.
  • Improvement: Enhanced enemy initialization with additional parameters for better game dynamics.
  • Improvement: Simplified code and improved performance by direct access to enemy type.
  • Improvement: Added logging statements across various functions for better debugging and system tracking.
  • Improvement: Implemented thread safety measures in the client network system to prevent data races.
  • Improvement: Modified enemy struct for clearer and more consistent code.
  • Improvement: Added a function to directly access the last element in an array, improving code efficiency.
  • Improvement: Updated player and missile creation code for better game mechanics.

@guillaumeAbel guillaumeAbel self-assigned this Oct 13, 2023
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 14, 2023

Walkthrough

The changes primarily focus on enhancing the game's networking capabilities, improving the enemy initialization process, and adding extensive logging for debugging. The code now supports a network system manager, and the enemy struct has been refactored for clarity. The initEnemy function has been modified to accept additional parameters, and the SparseArray class now includes a back() function.

Changes

File(s) Summary
src/Client/SceneManager.cpp, src/Client/Systems/Events/EventsSystems.cpp, src/Client/Systems/Graphic/*.cpp Added extensive logging for debugging purposes.
src/Client/SceneManager.hpp Added support for a network system manager.
src/Client/Systems/Network/ClientNetwork.cpp Enhanced concurrent access protection and improved enemy initialization.
src/ECS/ECSCustomTypes.hpp Refactored the Enemy struct for clarity and consistency.
src/ECS/SparseArray.hpp Added a back() function to access the last element of the array directly.
src/ECS/Systems/Systems.cpp, src/ECS/Systems/Systems.hpp Modified the initEnemy function to accept additional parameters and improved enemy and player initialization.
src/Nitwork/NitworkServer.cpp Ensured correct type casting for the addPlayerInitMessage function.
src/Server/Systems/Network/ServerNetwork.cpp Simplified code by directly accessing the type field of arrEnemies[index].

"In the land of code, where logic is king, 🐇
Changes were made, improvements they bring. 🎉
With network enhanced, and enemies refined, 🎮
Debugging's a breeze, with logs well-designed. 📝
So here's to the devs, their efforts we toast, 🥂
For making a game, we all love the most!" 🎊


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 12

Details

Commits Files that changed from the base of the PR and between 73ed3c8 and 54e9706.
Files selected for processing (16)
  • src/Client/SceneManager.cpp (1 hunks)
  • src/Client/SceneManager.hpp (2 hunks)
  • src/Client/Systems/Events/EventsSystems.cpp (1 hunks)
  • src/Client/Systems/Graphic/AudioSystems.cpp (1 hunks)
  • src/Client/Systems/Graphic/DeathSystems.cpp (1 hunks)
  • src/Client/Systems/Graphic/ParallaxSystems.cpp (3 hunks)
  • src/Client/Systems/Graphic/SpriteSystems.cpp (1 hunks)
  • src/Client/Systems/Graphic/TextSystems.cpp (1 hunks)
  • src/Client/Systems/Network/ClientNetwork.cpp (1 hunks)
  • src/ECS/ECSCustomTypes.hpp (2 hunks)
  • src/ECS/SparseArray.hpp (1 hunks)
  • src/ECS/Systems/Managers/SystemManager.cpp (1 hunks)
  • src/ECS/Systems/Systems.cpp (6 hunks)
  • src/ECS/Systems/Systems.hpp (1 hunks)
  • src/Nitwork/NitworkServer.cpp (1 hunks)
  • src/Server/Systems/Network/ServerNetwork.cpp (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/Client/Systems/Graphic/DeathSystems.cpp
  • src/Server/Systems/Network/ServerNetwork.cpp
Additional comments (Suppressed): 15
src/ECS/Systems/Systems.hpp (1)
  • 18-18: The function signature for initEnemy has been changed to include two new parameters: bool setId and struct ::enemy_id_s enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, consider the implications of the default values for these parameters.
src/Client/SceneManager.hpp (2)
  • 21-21: The SystemManagers enum has been extended to include a NETWORK value. Ensure that this new enum value is properly handled in all places where SystemManagers is used.

  • 36-38: The _scenes array has been updated to include SystemManagers::NETWORK in both of its vectors. Make sure that the addition of the NETWORK system manager is properly initialized and managed in the corresponding scenes.

src/Nitwork/NitworkServer.cpp (1)
  • 104-107: The change from implicit to explicit casting of _endpoints.size() - 1 to n_id_t is a good practice for type safety. However, ensure that the value of _endpoints.size() - 1 will always be within the range of n_id_t to prevent any potential overflow or underflow issues.
src/Client/Systems/Network/ClientNetwork.cpp (5)
  • 66-79: The receiveNewEnemy function has been updated to include thread safety with std::lock_guard<std::mutex>. It also now initializes the enemy with an ID and updates the position and health components in the registry. Ensure that the initEnemy function and the registry's insertBack function can handle these changes correctly.

  • 69-69: The use of std::lock_guard is a good practice for thread safety. However, ensure that the Registry::getInstance().mutex is unlocked in all other places where it is locked to avoid deadlocks.

  • 72-72: The initEnemy function now takes additional arguments. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 74-75: The newEnemy.enemyInfos.pos.x and newEnemy.enemyInfos.pos.y are being cast to float. Ensure that this casting does not lead to loss of precision or unexpected behavior.

  • 77-78: The insertBack function is being used to add new components to the registry. Ensure that this function handles the addition of new components correctly and that it does not lead to any issues with the ordering or indexing of components in the registry.

src/ECS/ECSCustomTypes.hpp (3)
  • 97-121: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [98-141]

The Enemy struct has been modified. The constId member variable has been made public and the _type member variable has been renamed to type and also made public. The constructor has been updated to initialize constId and type. The getConstId() function now returns a copy of constId instead of a reference. Ensure that these changes do not break any existing code that uses the Enemy struct. Also, consider if making constId and type public is necessary, as it breaks encapsulation. If external code needs to modify these variables, it might be better to provide setter functions instead.

  • 99-106: The constructor of the Enemy struct is using a mutex to protect the increment of _enemyNb. This is good for thread safety, but it's important to ensure that the mutex is also used wherever _enemyNb is read or written in other parts of the code, to prevent data races.

  • 114-119: The getConstId() function is using a mutex to protect the reading of constId. This is good for thread safety, but it's important to ensure that the mutex is also used wherever constId is read or written in other parts of the code, to prevent data races.

src/ECS/Systems/Systems.cpp (3)
  • 9-20: The new hunk introduces a new include directive for ECSCustomTypes.hpp and moves the include directive for CustomTypes.hpp under the #ifdef CLIENT preprocessor directive. Ensure that this change does not affect the rest of the codebase, especially if CustomTypes.hpp was used outside of the client-specific code.

  • 194-235: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [182-233]

The initEnemy function has been updated to take two additional arguments: bool setId and struct ::enemy_id_s enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, the Types::Enemy enemyComp is now initialized with enemyId instead of an empty initializer. Make sure this change is intended and correctly handled in the rest of the codebase.

  • 378-411: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [358-409]

The initPlayer function now includes a logging statement at the start and end of the function. As with the windowCollision function, consider changing the log level or removing these statements if they're not necessary. Also, the Registry::getInstance().getComponents<Types::PlayerDatas>().insertBack(playerDatas); line has been moved under the #ifdef CLIENT preprocessor directive. Ensure that this change does not affect the server-specific code.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Details

Commits Files that changed from the base of the PR and between 54e9706 and 8178e4e.
Files selected for processing (6)
  • src/Client/Systems/Network/ClientNetwork.cpp (1 hunks)
  • src/ECS/ECSCustomTypes.hpp (2 hunks)
  • src/ECS/Systems/Systems.cpp (6 hunks)
  • src/ECS/Systems/Systems.hpp (1 hunks)
  • src/Nitwork/NitworkServer.cpp (1 hunks)
  • src/Server/Systems/Network/ServerNetwork.cpp (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/Nitwork/NitworkServer.cpp
  • src/Server/Systems/Network/ServerNetwork.cpp
Additional comments (Suppressed): 11
src/ECS/Systems/Systems.hpp (1)
  • 19-19: The function signature for initEnemy has been changed to include two new parameters: setId and enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, consider the implications of the default values for these parameters.
src/Client/Systems/Network/ClientNetwork.cpp (3)
  • 66-79: The receiveNewEnemy function has been updated to include thread safety measures and additional initialization parameters for new enemies. The use of std::lock_guard ensures that the registry is not accessed concurrently, preventing potential data races. The initEnemy function now takes an additional parameter for setting the enemy ID. The position and health of the new enemy are also explicitly set. Ensure that these changes do not conflict with other parts of the codebase that interact with the receiveNewEnemy function or the Registry class.

  • 72-72: The initEnemy function now takes an additional boolean parameter. Ensure that this parameter is correctly set in all calls to initEnemy throughout the codebase.

  • 77-78: The insertBack function is used to add the position and health of the new enemy to the respective component arrays in the registry. Ensure that the order of these insertions does not affect the consistency of the entity-component relationships in the ECS.

src/ECS/ECSCustomTypes.hpp (1)
  • 97-121: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [98-141]

The Enemy struct has been refactored. The constId and type member variables are now public, and the constructor has been overloaded to allow for setting the constId and type upon creation. The getConstId() function now returns a copy of constId instead of a reference. Ensure that these changes do not break any existing code that relies on the old structure and behavior of the Enemy struct. Also, consider making constId and type private and providing getter and setter functions for them to maintain encapsulation.

src/ECS/Systems/Systems.cpp (6)
  • 9-20: The ECSCustomTypes.hpp is included instead of CustomTypes.hpp in the new hunk. If this change is intentional, ensure that all the types used from CustomTypes.hpp are available in ECSCustomTypes.hpp to avoid any compilation errors.

  • 178-184: The function signature of initEnemy has been changed to include two new parameters setId and enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 192-227: The initEnemy function has been refactored to include the enemyId in the enemyComp initialization. This change seems to be part of the effort to improve the management of enemy entities. Ensure that the enemyId is correctly set and used in the game logic.

  • 374-402: The initPlayer function has been refactored to include the playerDatas in the CLIENT conditional compilation block. This change seems to be part of the effort to improve the management of player entities. Ensure that the playerDatas is correctly set and used in the game logic.

  • 405-419: The createMissile function has been refactored to include the entityId in the CLIENT conditional compilation block. This change seems to be part of the effort to improve the management of missile entities. Ensure that the entityId is correctly set and used in the game logic.

  • 438-444: The createMissile function has been refactored to remove the collisionRect1 and only use collisionRect (previously collisionRect2). This change seems to be part of the effort to simplify the collision rectangle management for missile entities. Ensure that the collisionRect is correctly set and used in the game logic.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Details

Commits Files that changed from the base of the PR and between 8178e4e and 4fbf7e2.
Files selected for processing (1)
  • src/ECS/Systems/Systems.cpp (7 hunks)
Additional comments (Suppressed): 4
src/ECS/Systems/Systems.cpp (4)
  • 12-12: The ECSCustomTypes.hpp header file is included instead of CustomTypes.hpp. Ensure that this change is intentional and that the new header file contains all the necessary definitions.

  • 192-226: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [178-226]

The initEnemy function now accepts two additional parameters: setId and enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, the enemyId is now used to initialize the enemyComp which was previously default initialized. Make sure this change doesn't introduce any unintended side effects.

  • 384-402: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [373-402]

The initPlayer function has been modified. The position and collisionRect components are now initialized after the #endif directive, which means they will be initialized regardless of whether the CLIENT macro is defined. Ensure that this change is intentional and doesn't introduce any unintended side effects.

  • 405-419: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [406-444]

The createMissile function has been modified. The entityId is now only defined if the CLIENT macro is defined. Also, the collisionRect1 component is no longer initialized. Ensure that these changes are intentional and don't introduce any unintended side effects.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Details

Commits Files that changed from the base of the PR and between 4fbf7e2 and 3fc9b21.
Files selected for processing (2)
  • src/ECS/ECSCustomTypes.hpp (2 hunks)
  • src/ECS/SparseArray.hpp (1 hunks)
Additional comments (Suppressed): 5
src/ECS/SparseArray.hpp (1)
  • 68-74: The back() function is a good addition to the SparseArray class. It provides a way to directly access the last element of the array, which can be useful in many scenarios. However, it's important to note that this function throws a runtime error when the array is empty. Make sure to handle this exception properly wherever this function is used.
src/ECS/ECSCustomTypes.hpp (4)
  • 98-106: The constructor Enemy(enum enemy_type_e _type = enemy_type_e::CLASSIC_ENEMY) has been modified to directly initialize the type member variable. The constId member variable is now directly initialized using the static _enemyNb variable. The mutex lock ensures thread safety when accessing the static _enemyNb variable.

  • 108-112: A new constructor Enemy(struct enemy_id_s _constId, enum enemy_type_e _type = enemy_type_e::CLASSIC_ENEMY) has been added. This constructor initializes the constId and type member variables directly.

  • 114-117: The getConstId() function has been modified to return the constId member variable directly, without acquiring a mutex lock. This change assumes that the constId member variable is not modified after initialization, and therefore does not require thread safety.

  • 137-138: The static _enemyNb variable and _mutex are now private. This change improves encapsulation by preventing direct access to these variables from outside the Enemy struct.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Details

Commits Files that changed from the base of the PR and between 3fc9b21 and 0a86730.
Files selected for processing (1)
  • src/ECS/Systems/Systems.cpp (7 hunks)
Additional comments (Suppressed): 6
src/ECS/Systems/Systems.cpp (6)
  • 16-20: The ECSCustomTypes.hpp header file is included in the new hunk but not in the old hunk. Ensure that this new inclusion does not introduce any conflicts or redefinitions. Also, verify that the file exists and is accessible from the current file's location.

  • 178-184: The function signature of initEnemy has been changed to include two new parameters: bool setId and struct ::enemy_id_s enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, verify that the new parameters are used correctly within the function.

  • 187-229: The initEnemy function has been significantly refactored. The new code introduces a conditional initialization of the enemyComp variable based on the setId parameter. This change seems to be part of a new feature that allows enemies to be initialized with a specific ID. Ensure that this new feature is implemented correctly and does not introduce any bugs or unexpected behavior.

  • 388-406: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [377-406]

The initPlayer function has been refactored. The new code introduces a conditional initialization of the playerComp variable based on the setId parameter. This change seems to be part of a new feature that allows players to be initialized with a specific ID. Ensure that this new feature is implemented correctly and does not introduce any bugs or unexpected behavior.

  • 410-423: The createMissile function has been refactored. The new code removes the initialization of the collisionRect1 variable and changes the initialization of the collisionRect variable. Ensure that this change does not introduce any bugs or unexpected behavior, especially in the collision detection and resolution logic.

  • 442-448: The createMissile function has been refactored. The new code removes the insertion of the collisionRect1 component and changes the insertion of the collisionRect component. Ensure that this change does not introduce any bugs or unexpected behavior, especially in the collision detection and resolution logic.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Details

Commits Files that changed from the base of the PR and between 0a86730 and eec2c9c.
Files selected for processing (1)
  • src/ECS/Systems/Systems.cpp (7 hunks)
Additional comments (Suppressed): 6
src/ECS/Systems/Systems.cpp (6)
  • 12-20: The ECSCustomTypes.hpp header file has been added and the CustomTypes.hpp header file has been moved under the #ifdef CLIENT directive. Ensure that this change does not affect the rest of the codebase and that all necessary types are still accessible where needed.

  • 178-184: The initEnemy function now takes two additional parameters, setId and enemyId. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 187-229: The initEnemy function has been significantly refactored. The Types::SpriteDatas structure is now used instead of Raylib::Sprite for the enemy variable. The Types::Enemy structure is now initialized conditionally based on the setId parameter. The Types::Rect and Types::AnimRect components are now added to the registry only in the client build. Ensure that these changes are compatible with the rest of the codebase and that the client and server builds behave as expected.

  • 387-405: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [376-405]

The initPlayer function has been refactored. The Types::Rect and Types::AnimRect components are now added to the registry only in the client build. Ensure that this change is compatible with the rest of the codebase and that the client and server builds behave as expected.

  • 408-422: The createMissile function has been refactored. The entityId variable is now only defined in the client build. The collisionRect1 component has been removed from the registry. Ensure that these changes are compatible with the rest of the codebase and that the client and server builds behave as expected.

  • 441-447: The createMissile function has been refactored. The Types::Rect component is now added to the registry only in the client build. The collisionRect1 and collisionRect2 components have been replaced with a single collisionRect component. Ensure that these changes are compatible with the rest of the codebase and that the client and server builds behave as expected.

@Saverio976 Saverio976 merged commit 601c6bc into dev Oct 14, 2023
@Saverio976 Saverio976 deleted the feature/RB-110-function-receive-new-enemy branch October 17, 2023 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants