Skip to content

Switch particle engine to static allocation#138

Merged
LiquidityC merged 2 commits into
devfrom
static_particle_engine
Oct 10, 2025
Merged

Switch particle engine to static allocation#138
LiquidityC merged 2 commits into
devfrom
static_particle_engine

Conversation

@LiquidityC

@LiquidityC LiquidityC commented Oct 10, 2025

Copy link
Copy Markdown
Member

There's no point allocating it on the heap.

Summary by CodeRabbit

  • New Features

    • Particle system now initializes automatically without manual setup.
  • Refactor

    • Simplified particle engine lifecycle by using a single built-in instance, reducing complexity and null-state handling.
    • Streamlined update and render paths for more consistent behavior.
  • Chores

    • Removed legacy initialization and shutdown paths and related public initialization entry points.

@coderabbitai

coderabbitai Bot commented Oct 10, 2025

Copy link
Copy Markdown

Walkthrough

The particle engine was refactored from a dynamically allocated global pointer to a static internal s_engine. The public particle_engine_init function and NULL-guard checks were removed; callers updated to use the static instance. Shutdown no longer frees a heap engine.

Changes

Cohort / File(s) Summary of Changes
Static engine instance refactor
src/particle_engine.c
Replaced global engine pointer with static s_engine. Removed particle_engine_init and engine-check boilerplate. Switched all engine->... accesses to s_engine.... Removed freeing of engine on shutdown and removed NULL-guard legacy paths.
Callsite removal
src/main.c
Removed call to particle_engine_init() from initGame, reflecting the engine's static initialization change.
Public API cleanup
src/particle_engine.h
Removed the public declaration of void particle_engine_init(void). Other declarations unchanged.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit in code with a hop and a grin,
I tucked my engine safe—no alloc, no din.
Lists snuggle neatly in s_engine's keep,
I update, I render, then drift off to sleep. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change of switching the particle engine to static allocation, matching the refactoring from a dynamically allocated global pointer to a static Engine instance. It is concise, clear, and directly reflects the core modification without extraneous details, ensuring that teammates scanning the history immediately understand the intent and scope of the change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch static_particle_engine

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 45a5aba and 3cdc12b.

📒 Files selected for processing (2)
  • src/main.c (0 hunks)
  • src/particle_engine.h (0 hunks)
💤 Files with no reviewable changes (2)
  • src/main.c
  • src/particle_engine.h
⏰ 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: Windows (MSVC)
  • GitHub Check: Ubuntu (Clang)
  • GitHub Check: Mac (Clang)
  • GitHub Check: Mac (GCC)
  • GitHub Check: Ubuntu (mingw)
  • GitHub Check: Ubuntu (GCC)
  • GitHub Check: Analyze (c-cpp)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

There's no point allocating it on the heap.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2598f1e and 45a5aba.

📒 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_engine is zero-initialized, with both global_particles and game_particles starting as NULL—the correct initial state.


121-121: Particle creation functions correctly updated.

All linkedlist_append calls properly reference s_engine.game_particles and s_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_engine members. The particle_engine_clear implementation correctly frees all particles and exhausts the linked lists, leaving both pointers NULL.

Also applies to: 491-491, 497-497, 503-506

Comment thread src/particle_engine.c
@LiquidityC LiquidityC enabled auto-merge (squash) October 10, 2025 13:10
@LiquidityC LiquidityC merged commit e6dbdf4 into dev Oct 10, 2025
10 checks passed
@LiquidityC LiquidityC deleted the static_particle_engine branch October 10, 2025 13:23
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.

1 participant