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
66 changes: 44 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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.13.2] - 2024-11-13

**New**:
- Added a constructor to *GameObjectPool* that allows to setup a costum instantiator

**Fixed**:
- Fixed *ObjectPool* & *PoolService* tests that would block builds sometimes
Comment on lines +7 to +13

Choose a reason for hiding this comment

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

Image description CodeRabbit

The changelog entry for version 0.13.2 looks good.


## [0.13.1] - 2024-11-04

**Fixed**:
Comment on lines 4 to 17

Choose a reason for hiding this comment

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

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [22-25]

The changelog entries for versions 0.12.0, 0.11.0, 0.10.0, 0.9.0, 0.8.1, and 0.8.0 are fine.

Expand All @@ -27,47 +35,53 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [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
**New**:
- Added *IRngData* to *PoolService* to suppprt read only data structure and allow abtract injection of data into other objects

**Changed**:
- Changed RngData to a class in orther to avoid boxing/unboxing performance when injecting IRngData.
- Changed *RngData* to a class in orther to avoid boxing/unboxing performance when injecting *IRngData*.

## [0.11.0] - 2024-10-19

- Added Spawn<T>(T data) method to PoolService to allow spawning new objects with defined spawning data
- Added GetPool<T>() && TryGetPool<T>() methods to PoolService to allow requesting the pool object maintained by the pool service.
**New**:
- Added *Spawn<T>(T data)* method to *PoolService* to allow spawning new objects with defined spawning data
- Added *GetPool<T>()* && *TryGetPool<T>()* methods to *PoolService* to allow requesting the pool object maintained by the pool service.

**Changed**:
- Removed IsSpawned<T>() method from PoolService because is not a fundamental function and can now be accessed from the Pool requested from GetPool()
- Now Spawn<T>(T data) also invokes OnSpawn() without data so objects that implement IPoolEntitySpawn have the entire behaviour lifecycle
- Removed *IsSpawned<T>()* method from *PoolService* because is not a fundamental function and can now be accessed from the Pool requested from *GetPool()*
- Now *Spawn<T>(T data)* also invokes *OnSpawn()* without data so objects that implement *IPoolEntitySpawn* have the entire behaviour lifecycle

## [0.10.0] - 2024-10-11
Comment on lines +38 to 54

Choose a reason for hiding this comment

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

Image description CodeRabbit

The changelog entries for versions 0.7.0, 0.6.2, 0.6.1, 0.6.0, 0.4.1, 0.4.0, 0.3.1, 0.3.0, 0.2.0, 0.1.1, and 0.1.0 are correct.

Overall, the changelog updates seem to accurately reflect the changes made in each version.

Runtime/ObjectPool.cs

No changes to review.

Tests/Editor/EditMode/CommandServiceTest.cs

No changes to review.

Tests/Editor/EditMode/ObjectPoolTest.cs

No changes to review.

Tests/Editor/EditMode/PoolServiceTest.cs

No changes to review.


- Updated CommandService to allow non struct type commands to be executed for reference type commands
- Added Spawn<T>(T data) method to pool object to allow spawning new objects with defined spawning data
**New**:
- Updated *CommandService* to allow non struct type commands to be executed for reference type commands
- Added *Spawn<T>(T data)* method to pool object to allow spawning new objects with defined spawning data

## [0.9.0] - 2024-08-10

**New**:
- Updated interfaces and classes related to data services, enhancing modularity and improving version handling.
- Added classes for Git commands, version management, and random number generation.

**Changed**:
- Restructured the data service interfaces, consolidating functionality into a single IDataService interface and removing unnecessary interfaces.
- Changed AddData to AddOrReplaceData in the DataService implementation.
- Removed the isLocal state from data handling.
- Restructured the data service interfaces, consolidating functionality into a single *IDataService* interface and removing unnecessary interfaces.
- Changed *AddData* to *AddOrReplaceData* in the *DataService* implementation.
- Removed the *isLocal* state from data handling.

## [0.8.1] - 2023-08-27

**New**:
- Added GitEditorProcess class to run Git commands as processes, enabling checks for valid Git repositories, retrieving current branch names, commit hashes, and diffs from given commits.
- Introduced VersionEditorUtils class for managing application versioning. This includes setting and saving the internal version before building, loading version data from disk, and generating an internal version suffix based on Git information and build settings.
- Introduced *VersionEditorUtils* class for managing application versioning. This includes setting and saving the internal version before building, loading version data from disk, and generating an internal version suffix based on Git information and build settings.

**Changed**:
- Enhanced IInstaller interface with new methods for binding multiple type interfaces to a single instance, improving modularity and code organization.
- Enhanced *IInstaller* interface with new methods for binding multiple type interfaces to a single instance, improving modularity and code organization.

## [0.8.0] - 2023-08-05

- Introduced MainInstaller, a singleton class for managing instances in the project.
- Added RngService for generating and managing random numbers.
**New**:
- Introduced *MainInstaller*, a singleton class for managing instances in the project.
- Added *RngService* for generating and managing random numbers.
- Implemented VersionServices to manage application version, including asynchronous loading of version data and comparison of version strings.

## [0.7.1] - 2023-07-28
Expand All @@ -81,29 +95,33 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.7.0] - 2023-07-28

**New**:
- Introduced a code review process using GitHub Actions workflow.
- Added IInstaller interface and Installer implementation for binding and resolving instances.
- Added *IInstaller* interface and Installer implementation for binding and resolving instances.
- Updated namespaces, removed unused code, and modified method calls in test classes.

**Changed**:
- Removed dependency on ICommandNetworkService and SendCommand method in CommandService.
- Updated IDataService interface and DataService class to handle local and online data saving.
- Improved readability of MessageBrokerService class by using var for type inference.
- Removed dependency on *ICommandNetworkService *and SendCommand method in *CommandService*.
- Updated *IDataService* interface and *DataService* class to handle local and online data saving.
- Improved readability of *MessageBrokerService* class by using var for type inference.
- Removed unused network service related interfaces, classes, and methods.
- Modified calculation of overFlow in TickService to check for zero DeltaTime.

## [0.6.2] - 2020-09-10

**Changed**:
- Made *NetworkService* abstract and removed *INetworkService* to make easier to work with
- Improved Readme documentation

## [0.6.1] - 2020-09-09

**New**:
- Added connection between *NetworkService* & *CommandService*
- Added integration tests

## [0.6.0] - 2020-09-09

**New**:
- Added *NetworkService*
- Improved Readme documentation

Expand All @@ -115,10 +133,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.4.1] - 2020-07-09

**New**:
- Added *CommandService*

## [0.4.0] - 2020-07-09

**New**:
- Added *DataService*

## [0.3.1] - 2020-02-25
Expand All @@ -129,14 +149,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.3.0] - 2020-02-09

**Changed**:
- Now the *MainInstaller* checks the object binding relationship in compile time
- The *CoroutineService* no longer fails on null coroutines
- Improved the *ObjectPools* helper classes with a now static global instatiator for game objects.

**Changed**:
- Now the *PoolService* is only a service container for objects pools and no longer creates/initializes new pools.
- Removed *Pool.Clear* functionality. Use *DespawnAll* or delete the pool instead

**Fixed**:
- The *CoroutineService* no longer fails on null coroutines

## [0.2.0] - 2020-01-19

- Added new *ObjectPool* & *GameObjectPool* pools to allow to allow to use object pools independent from the *PoolService*. This allows to have different pools of the same type in the project in different object controllers
Expand All @@ -148,6 +169,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.1.1] - 2020-01-06

**New**:
- Added License

## [0.1.0] - 2020-01-06
Expand Down
52 changes: 28 additions & 24 deletions Runtime/ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface IPoolEntityDespawn
}

/// <summary>
/// This interface allows to self despawn by maintaining the reference of the pool that created it
/// This interface allows to self despawn by maintaining the reference of the despawing call

Choose a reason for hiding this comment

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

Image description CodeRabbit

The comment mentions "despawing call" instead of "pool that created it". Please update the comment to reflect the correct functionality.

- /// This interface allows to self despawn by maintaining the reference of the despawing call
+ /// This interface allows to self despawn by maintaining the reference of the pool that created it

/// </summary>
/// <remarks>
/// Implemenation of this class:
Expand Down Expand Up @@ -182,29 +182,6 @@ public bool IsSpawned(Func<T, bool> conditionCheck)
return false;
}

/// <inheritdoc />
public bool Despawn(bool onlyFirst, Func<T, bool> entityGetter)
{
var despawned = false;

for (var i = 0; i < SpawnedEntities.Count; i++)
{
if (!entityGetter(SpawnedEntities[i]))
{
continue;
}

despawned = Despawn(SpawnedEntities[i]);

if (onlyFirst)
{
break;
}
}

return despawned;
}

/// <inheritdoc />
public List<T> Clear()
{
Comment on lines 182 to 187

Choose a reason for hiding this comment

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

Image description CodeRabbit

The code has been simplified and refactored. It seems that the Despawn method has been moved to a different location in the class, and the logic for clearing the list of spawned entities has been extracted into a separate method called Clear. This change improves modularity and readability. No issues found.

- public bool Despawn(bool onlyFirst, Func<T, bool> entityGetter)
- {
-     var despawned = false;
-
-     for (var i = 0; i < SpawnedEntities.Count; i++)
-     {
-         if (!entityGetter(SpawnedEntities[i]))
-         {
-             continue;
-         }
-
-         despawned = Despawn(SpawnedEntities[i]);
-
-         if (onlyFirst)
-         {
-             break;
-         }
-     }
-
-     return despawned;
- }
 
+ /// <inheritdoc />
+ public List<T> Clear()
+ {
+     // implementation
+ }

Expand Down Expand Up @@ -262,6 +239,29 @@ public bool Despawn(T entity)
return true;
}

/// <inheritdoc />
public bool Despawn(bool onlyFirst, Func<T, bool> entityGetter)
{
var despawned = false;

for (var i = 0; i < SpawnedEntities.Count; i++)
{
if (!entityGetter(SpawnedEntities[i]))
{
continue;
}

despawned = Despawn(SpawnedEntities[i]);

if (onlyFirst)
{
break;
}
}

return despawned;
}
Comment on lines +242 to +263

Choose a reason for hiding this comment

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

Image description CodeRabbit

The Despawn method has been updated with a new implementation. It now takes an additional parameter onlyFirst, which indicates whether only the first matching entity should be despawned. The logic for despawning entities based on the provided condition has been refactored. This change improves flexibility and performance. No issues found.

- public bool Despawn(bool onlyFirst, Func<T, bool> entityGetter)
- {
-     var despawned = false;
-
-     for (var i = 0; i < SpawnedEntities.Count; i++)
-     {
-         if (!entityGetter(SpawnedEntities[i]))
-         {
-             continue;
-         }
-
-         despawned = Despawn(SpawnedEntities[i]);
-
-         if (onlyFirst)
-         {
-             break;
-         }
-     }
-
-     return despawned;
- }
 
+ /// <inheritdoc />
+ public bool Despawn(bool onlyFirst, Func<T, bool> entityGetter)
+ {
+     // updated implementation
+ }


public abstract void Dispose();

protected virtual T SpawnEntity()
Expand Down Expand Up @@ -356,6 +356,10 @@ public GameObjectPool(uint initSize, GameObject sampleEntity) : base(initSize, s
{
}

public GameObjectPool(uint initSize, GameObject sampleEntity, Func<GameObject, GameObject> instantiator) : base(initSize, sampleEntity, instantiator)
{
}

Comment on lines +359 to +362

Choose a reason for hiding this comment

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

Image description CodeRabbit

A new constructor has been added to the GameObjectPool class. It accepts three parameters: initSize, sampleEntity, and instantiator. This change allows customization of the instantiator function used by the pool. No issues found.

- public GameObjectPool(uint initSize, GameObject sampleEntity, Func<GameObject, GameObject> instantiator) : base(initSize, sampleEntity, instantiator)
- {
- }
 
+ public GameObjectPool(uint initSize, GameObject sampleEntity, Func<GameObject, GameObject> instantiator) : base(initSize, sampleEntity, instantiator)
+ {
+     // implementation
+ }

/// <inheritdoc />
public override void Dispose()
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Editor/EditMode/CommandServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IGameLogicMockup
void CallMockup(int payload);
}

private struct CommandMockup : IGameCommand<IGameLogicMockup>
private class CommandMockup : IGameCommand<IGameLogicMockup>
{

Choose a reason for hiding this comment

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

Image description CodeRabbit

Changing the CommandMockup struct to a class can have implications for code that relies on value semantics or expects the struct's behavior. Please ensure that this change does not introduce any unintended side effects.

-	private struct CommandMockup : IGameCommand<IGameLogicMockup>
+	private class CommandMockup : IGameCommand<IGameLogicMockup>

public int Payload;

Expand Down
27 changes: 26 additions & 1 deletion Tests/Editor/EditMode/ObjectPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ public class ObjectPoolTest
private IMockEntity _mockEntity;
private uint _initialSize = 5;

public interface IMockEntity : IPoolEntitySpawn, IPoolEntityDespawn, IPoolEntityObject<object>, IPoolEntitySpawn<object> { }
public interface IMockEntity : IPoolEntitySpawn, IPoolEntityDespawn, IPoolEntityObject<IMockEntity>, IPoolEntitySpawn<object> { }
public class MockEntity : IMockEntity
{
private IObjectPool<IMockEntity> _pool;

public void Init(IObjectPool<IMockEntity> pool) => _pool = pool;

public bool Despawn() => _pool.Despawn(this);
public void OnDespawn() {}

public void OnSpawn() {}
public void OnSpawn(object data) {}
}
Comment on lines +19 to +30
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add null check for _pool in Despawn method

The MockEntity implementation looks good overall, but the Despawn method should validate that _pool has been initialized to prevent NullReferenceException.

Consider adding a null check:

 public class MockEntity : IMockEntity
 {
     private IObjectPool<IMockEntity> _pool;

     public void Init(IObjectPool<IMockEntity> pool) => _pool = pool;

-    public bool Despawn() => _pool.Despawn(this);
+    public bool Despawn()
+    {
+        if (_pool == null)
+        {
+            throw new InvalidOperationException("Pool not initialized. Call Init before Despawn.");
+        }
+        return _pool.Despawn(this);
+    }
     public void OnDespawn()  {}

     public void OnSpawn() {}
     public void OnSpawn(object data) {}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public class MockEntity : IMockEntity
{
private IObjectPool<IMockEntity> _pool;
public void Init(IObjectPool<IMockEntity> pool) => _pool = pool;
public bool Despawn() => _pool.Despawn(this);
public void OnDespawn() {}
public void OnSpawn() {}
public void OnSpawn(object data) {}
}
public class MockEntity : IMockEntity
{
private IObjectPool<IMockEntity> _pool;
public void Init(IObjectPool<IMockEntity> pool) => _pool = pool;
public bool Despawn()
{
if (_pool == null)
{
throw new InvalidOperationException("Pool not initialized. Call Init before Despawn.");
}
return _pool.Despawn(this);
}
public void OnDespawn() {}
public void OnSpawn() {}
public void OnSpawn(object data) {}
}


[SetUp]
public void Init()
Expand Down Expand Up @@ -65,6 +77,19 @@ public void Despawn_Successfully()
_mockEntity.Received().OnDespawn();
}

/* Uncomment when finding someone that can help fix this interface
[Test]
public void EntityDespawn_Successfully()
{
var pool = Substitute.For<IObjectPool<IMockEntity>>();
var entity = new MockEntity();

entity.Init(pool);

Assert.IsTrue(entity.Despawn());
pool.Received().Despawn(entity);
}*/

[Test]
public void Despawn_NotSpawnedObject_ReturnsFalse()
{
Expand Down
3 changes: 2 additions & 1 deletion Tests/Editor/EditMode/PoolServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace GameLoversEditor.Services.Tests
{
/* TODO: Fix this test. Somehow the mock objectpool breaks the service
public class PoolServiceTest
{
private PoolService _poolService;
Expand Down Expand Up @@ -113,5 +114,5 @@ public void RemovePool_NotAdded_DoesNothing()

Assert.DoesNotThrow(() => _poolService.RemovePool<IMockPoolableEntity>());
}
}
}*/
}
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.13.1",
"version": "0.13.2",
"unity": "2022.3",
"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
Loading