Skip to content

A pooling mechanism for entities, useful for situations where you are creating and deleting many entities with a limited lifespan.

License

Notifications You must be signed in to change notification settings

peter-r-g/Sbox-EntityPools

Repository files navigation

Entity Pools

A pooling mechanism for entities with an API like C# ArrayPool<T>. Useful for situations where you are creating and deleting many entities with a limited lifespan.

Features

  • Generics support. Any type implementing IEntity (any Entity) and contains a parameterless constructor will suffice.
  • Limited capacity pools. This helps you maintain sensible entity counts and prevent excessive creations.
  • Overridable entity rent/return logic. Simply add the IPooledEntity interface to your entity.
  • Timed asynchronous returning of entities. Useful for fire and forget renting.
  • Networkable (All required functionality is implemented but is currently unusable due to S&box issues.)

Installation

You can either download from this repo or you can reference it with gooman.entity_pools using asset.party

Example Usage

// Get yourself an existing or new instance of MyEntity.
var rentedEntity = EntityPool<MyEntity>.Shared.Rent();

// Mess with your rented entity.

// Return the entity back to the pool for reuse.
EntityPool<MyEntity>.Shared.Return( rentedEntity );

License

Distributed under the MIT License. See the license for more information.

About

A pooling mechanism for entities, useful for situations where you are creating and deleting many entities with a limited lifespan.

Topics

Resources

License

Stars

Watchers

Forks

Languages