Switch particle engine to static allocation#138
Conversation
WalkthroughThe particle engine was refactored from a dynamically allocated global pointer to a static internal Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Game
participant ParticleEngine as ParticleEngine (static s_engine)
Note over ParticleEngine: s_engine is a static instance (no explicit init)
Game->>ParticleEngine: addParticle(...)
ParticleEngine->>ParticleEngine: push to s_engine.game_particles / s_engine.global_particles
Game->>ParticleEngine: update(dt)
ParticleEngine->>ParticleEngine: iterate s_engine lists and simulate
Game->>ParticleEngine: render(renderer)
ParticleEngine->>ParticleEngine: draw from s_engine lists
Game->>ParticleEngine: clear()/close()
ParticleEngine->>ParticleEngine: release particles inside s_engine
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There's no point allocating it on the heap.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/particle_engine.c(10 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/particle_engine.c (1)
src/linkedlist.c (2)
linkedlist_append(61-77)linkedlist_pop(48-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Ubuntu (GCC)
- GitHub Check: Mac (Clang)
- GitHub Check: Windows (MSVC)
- GitHub Check: Mac (GCC)
- GitHub Check: Ubuntu (mingw)
- GitHub Check: Ubuntu (Clang)
- GitHub Check: Analyze (c-cpp)
🔇 Additional comments (3)
src/particle_engine.c (3)
64-64: LGTM! Static allocation is cleaner here.The transition from heap to static allocation removes unnecessary malloc/free overhead and simplifies lifecycle management. Static storage ensures
s_engineis zero-initialized, with bothglobal_particlesandgame_particlesstarting as NULL—the correct initial state.
121-121: Particle creation functions correctly updated.All
linkedlist_appendcalls properly references_engine.game_particlesands_engine.global_particles. The operations are semantically identical to the previous pointer-based approach.Also applies to: 158-158, 208-208, 242-242, 281-283, 322-322, 365-365
415-416: Update, render, and clear operations correctly transitioned.All operations properly reference
s_enginemembers. Theparticle_engine_clearimplementation correctly frees all particles and exhausts the linked lists, leaving both pointers NULL.Also applies to: 491-491, 497-497, 503-506
There's no point allocating it on the heap.
Summary by CodeRabbit
New Features
Refactor
Chores