Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.12.1] - 2024-10-25

**Fixed**:
- The endless loop when calling *RngService.Range()*
- The endless loop *GameObjectPool* when spawning new entities
Comment on lines +10 to +11

Choose a reason for hiding this comment

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

Image description CodeRabbit

The description of the fixed issues is not clear. Please provide more specific details about the endless loop problems in RngService.Range() and GameObjectPool when spawning new entities.

0.7.1 - 2023-07-28


## [0.12.0] - 2024-10-22

- Added IRngData to PoolService to suppprt read only data structure and allow abtract injection of data into other objects
Expand Down Expand Up @@ -51,13 +57,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.7.1] - 2023-07-28

**Fixed**:
- Compilation errors in various test files and the PoolService class have been fixed.

**Changed**:
- Tests have been moved to proper folders, and the package number has been updated.
- An unused namespace import has been removed from the InstallerTest class.
Comment on lines 61 to 62

Choose a reason for hiding this comment

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

Image description CodeRabbit

The summary of changes is not accurate. The changes mentioned here are actually part of the previous version (0.7.0). Please update the summary to reflect the correct changes made in this version.


**Fixed**:
- Compilation errors in various test files and the PoolService class have been fixed.

Comment on lines +65 to +66

Choose a reason for hiding this comment

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

Image description CodeRabbit

Please provide more information about the compilation errors that were fixed in various test files and the PoolService class.

## [0.7.0] - 2023-07-28

- Introduced a code review process using GitHub Actions workflow.
Expand Down
21 changes: 12 additions & 9 deletions Runtime/ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public class GameObjectPool : ObjectPoolBase<GameObject>
/// If true then when the object is despawned back to the pool will be parented to the same as the sample entity
/// parent transform
/// </summary>
public bool DespawnToSampleParent { get; set; }
public bool DespawnToSampleParent { get; set; } = true;

Choose a reason for hiding this comment

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

Image description CodeRabbit

The addition of the default value for the DespawnToSampleParent property is a good improvement. It provides a sensible default behavior and makes the code more self-explanatory.


public GameObjectPool(uint initSize, GameObject sampleEntity) : base(initSize, sampleEntity, Instantiator)
{
Expand Down Expand Up @@ -375,7 +375,7 @@ public static GameObject Instantiator(GameObject entityRef)

protected override GameObject SpawnEntity()
{
var entity = SpawnEntity();
var entity = base.SpawnEntity();

Choose a reason for hiding this comment

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

Image description CodeRabbit

The change in line 378 looks fine. It calls the base class's SpawnEntity() method and assigns the result to the entity variable.


entity.SetActive(true);

Expand Down Expand Up @@ -403,7 +403,7 @@ public class GameObjectPool<T> : ObjectPoolBase<T> where T : Behaviour
/// If true then when the object is despawned back to the pool will be parented to the same as the sample entity
/// parent transform
/// </summary>
public bool DespawnToSampleParent { get; set; }
public bool DespawnToSampleParent { get; set; } = true;

Choose a reason for hiding this comment

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

Image description CodeRabbit

Similar to the previous change, adding a default value for the DespawnToSampleParent property is a good improvement.


public GameObjectPool(uint initSize, T sampleEntity) : base(initSize, sampleEntity, Instantiator)
{
Expand Down Expand Up @@ -442,14 +442,17 @@ protected override T SpawnEntity()
{
T entity = null;

do
while(entity == null)
{
entity = SpawnEntity();
entity = base.SpawnEntity();

if(entity.gameObject == null)
{
SpawnedEntities.Remove(entity);

entity = null;
}
}
Comment on lines +445 to 455

Choose a reason for hiding this comment

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

Image description CodeRabbit

The changes made in this section address a potential issue with spawning entities. The new implementation uses a while loop to ensure that a valid entity is obtained from the base class's SpawnEntity() method. If the spawned entity's gameObject is null, it is removed from the SpawnedEntities list and the loop continues until a valid entity is obtained.

Overall, the changes in Runtime/ObjectPool.cs seem reasonable and address potential issues related to spawning and despawning entities.

Suggestions

  1. Consider adding error handling and logging for exceptional cases where the SpawnEntity() method returns null or the spawned entity's gameObject is null. This can help with debugging and identifying any unexpected issues during runtime.

  2. It would be beneficial to add unit tests to cover the different scenarios related to spawning and despawning entities, including cases where the SpawnEntity() method returns null or the spawned entity's gameObject is null.

  3. Ensure that the Instantiator used in the constructor of GameObjectPool is properly implemented and handles the instantiation of new entities correctly.

  4. Consider documenting the purpose and behavior of the DespawnToSampleParent property in the code comments to provide better clarity for future developers.

  5. Verify that the changes made in other parts of the codebase, such as Runtime/RngService.cs, are consistent with the changes made in Runtime/ObjectPool.cs to ensure a cohesive and unified implementation.

  6. Review the overall design and usage of the GameObjectPool class to ensure it aligns with the requirements and goals of the project. Consider if there are any additional improvements or optimizations that can be made to enhance its functionality and performance.

Testing

Here are some potential test cases to consider for testing the GameObjectPool class:

  1. Test spawning entities from an empty pool and verify that the correct number of entities are spawned.
  2. Test despawning entities back to the pool and verify that they are correctly deactivated and available for reuse.
  3. Test spawning and despawning entities multiple times to ensure the pool behaves as expected under different usage patterns.
  4. Test setting the DespawnToSampleParent property to both true and false and verify that the despawned entities are parented correctly.
  5. Test edge cases, such as trying to spawn more entities than the initial pool size allows or despawning entities that are not part of the pool.

These tests can be automated using Unity's testing framework and executed in both EditMode and RuntimeMode to ensure the correctness and reliability of the GameObjectPool class.

// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// Need to do while loop and check as parent objects could have destroyed the entity/gameobject before it could
// be properly disposed by pool service
while (entity == null || entity.gameObject == null);

entity.gameObject.SetActive(true);

Expand Down
4 changes: 2 additions & 2 deletions Runtime/RngService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ public static int[] Restore(int count, int seed)
/// </summary>
public static int Range(int min, int max, int[] rndState, bool maxInclusive)
{
var floatMin = min;
var floatMax = max;
floatP floatMin = min;
floatP floatMax = max;
Comment on lines +208 to +209

Choose a reason for hiding this comment

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

Image description CodeRabbit

The variable declarations in the Range method of RngService.cs have been changed from var to floatP. However, it seems that floatP is not a valid type in C#. It's likely that this change was made to explicitly specify the variable types as float.

To fix this issue, you can replace floatP with float in the variable declarations. Here's the suggested fix:

- floatP floatMin = min;
- floatP floatMax = max;
+ float floatMin = min;
+ float floatMax = max;

This will ensure that the variables are correctly declared as float and resolve the syntax error.

Please note that if floatP is a custom type defined elsewhere in the codebase, you should use the appropriate type instead of float.


return Range(floatMin, floatMax, rndState, maxInclusive);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.gamelovers.services",
"displayName": "Services",
"author": "Miguel Tomas",
"version": "0.12.0",
"version": "0.12.1",
"unity": "2022.4",
"license": "MIT",
"description": "The purpose of this package is to provide a set of services to ease the development of a basic game architecture",
Expand Down