Skip to content

Conversation

Copy link

Copilot AI commented May 21, 2025

This PR implements the particle pooling functionality using the object pool pattern to significantly reduce garbage collection overhead.

Implementation Details

  1. New ParticlePool Class

    • Created a dedicated pool manager for particles
    • Pre-allocates particles during initialization (default: 100)
    • Automatically grows the pool when needed (default: 20 particles at a time)
    • Provides GetParticle() and ReleaseParticle() methods for efficient particle reuse
    • Resets particles to default state when returned to the pool
  2. Modified Emitter2D Class

    • Added ParticlePool as a protected field
    • Updated constructor to initialize the particle pool with configurable capacity
    • Modified CreateNewParticle() to get particles from the pool instead of instantiating new ones
    • Updated UpdateParticles() to return "dead" particles to the pool instead of just removing them
    • Enhanced Trigger() to properly return existing particles to the pool when the emitter is reset
  3. Project Structure

    • Added new Pools directory for object pool implementations
    • Updated project file to include the new directory

Benefits

  • Reduces memory pressure from constant particle allocation/deallocation
  • Minimizes garbage collection pauses which can impact frame rate
  • Maintains the same public API so existing code doesn't need changes
  • Configurable pool sizes to balance memory usage vs. allocation frequency

Fixes #1.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl3.digicert.com
    • Triggering command: dotnet build (dns block)
  • crl4.digicert.com
    • Triggering command: dotnet build (dns block)
  • ocsp.digicert.com
    • Triggering command: dotnet build (dns block)
  • s.symcb.com
    • Triggering command: dotnet build (dns block)
  • s.symcd.com
    • Triggering command: dotnet build (dns block)
  • ts-crl.ws.symantec.com
    • Triggering command: dotnet build (dns block)
  • ts-ocsp.ws.symantec.com
    • Triggering command: dotnet build (dns block)
  • www.nuget.org
    • Triggering command: dotnet build (dns block)
    • Triggering command: dotnet build -p:BuildContentProjects=false (dns block)
    • Triggering command: dotnet build -p:MonoGameMGCB=false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: TimoSalomaki <1816448+TimoSalomaki@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement the particle pooling Implement particle pooling functionality for performance optimization May 21, 2025
Copilot AI requested a review from TimoSalomaki May 21, 2025 19:03
@TimoSalomaki TimoSalomaki marked this pull request as ready for review May 22, 2025 09:41
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.

Implement the particle pooling

2 participants