Skip to content

feat(core): return SystemIDs in plugin abstract RegisterSystems#421

Merged
ripel2 merged 8 commits into
mainfrom
get-plugin-and-system-ids
Jan 10, 2026
Merged

feat(core): return SystemIDs in plugin abstract RegisterSystems#421
ripel2 merged 8 commits into
mainfrom
get-plugin-and-system-ids

Conversation

@ripel2

@ripel2 ripel2 commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Not related to any issues.

Small ECS feature yet very useful: while trying to disable a system, I encountered an issue where it was impossible to get the SystemID from a system registered with Plugin::Bind, because APlugin::RegisterSystems returned void.

Usually plugins should stay untouched by end users, and enabling/disabling something should be done with a resource.
But if we want to provide them a way to disable a specific system, it would be the following:

  • Store the specific FunctionID that got added when binding the plugin in the plugin struct itself
  • User adds a system that gets the plugin to access the FunctionID
  • User do what they want with the SystemID, including calling Scheduler::Disable

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for missing plugins.
  • Refactor

    • Updated plugin registration system API.
  • Tests

    • Added plugin system tests.

✏️ Tip: You can customize this high-level summary in your review settings.

@ripel2 ripel2 requested a review from Miou-zora January 10, 2026 16:37
@ripel2 ripel2 self-assigned this Jan 10, 2026
@coderabbitai

coderabbitai Bot commented Jan 10, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes introduce a new MissingPluginError exception type and modify the RegisterSystems method in APlugin to return the underlying RegisterSystem call result instead of void. A test plugin class is added to exercise the enhanced functionality.

Changes

Cohort / File(s) Summary
Exception Infrastructure
src/engine/src/exception/MissingPluginError.hpp, src/engine/src/core/Core.inl
New MissingPluginError exception class introduced, inheriting from std::runtime_error. Header included in Core.inl to make it available within the engine core.
Plugin API Enhancement
src/engine/src/plugin/APlugin.hpp
RegisterSystems method signature updated to return inline decltype(auto) instead of void, forwarding the result of _core.RegisterSystem<TScheduler>(systems...).
Test Coverage
src/engine/tests/engine/PluginTest.cpp
New test plugin class PluginTestC added with a Bind() method registering an Update lambda system and exposing a public systemId member for verification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A plugin's error now has a name so bright,
RegisterSystems returns what feels so right,
No more void voids where values could be,
The rabbit hops forward in harmony! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately captures the main objective: enabling RegisterSystems to return SystemIDs instead of void, which is the core functionality change across the modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/engine/tests/engine/PluginTest.cpp (1)

5-5: Consider removing unused include.

The scheduler/Startup.hpp include doesn't appear to be used in this test file. The tests only reference Engine::Scheduler::Update, which is already available through core/Core.hpp.

🧹 Proposed cleanup
 #include "core/Core.hpp"
 #include "plugin/APlugin.hpp"
-#include "scheduler/Startup.hpp"
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 941a351 and 02f5927.

📒 Files selected for processing (5)
  • src/engine/src/core/Core.hpp
  • src/engine/src/core/Core.inl
  • src/engine/src/exception/MissingPluginError.hpp
  • src/engine/src/plugin/APlugin.hpp
  • src/engine/tests/engine/PluginTest.cpp
🧰 Additional context used
🧬 Code graph analysis (1)
src/engine/tests/engine/PluginTest.cpp (1)
src/engine/src/plugin/APlugin.hpp (2)
  • RegisterSystems (12-15)
  • RegisterSystems (12-12)
🔇 Additional comments (8)
src/engine/src/core/Core.hpp (1)

272-279: LGTM! Clean API addition.

The GetPlugin<TPlugin>() method follows the established pattern of the existing HasPlugin() and resource management APIs. The documentation clearly specifies the exception behavior, and the signature is consistent with similar retrieval methods in the codebase.

src/engine/src/exception/MissingPluginError.hpp (1)

1-11: LGTM! Proper exception design.

The exception class follows standard C++ patterns by inheriting from std::runtime_error and using constructor inheritance. This provides a type-safe way to distinguish plugin-related errors from other runtime errors.

src/engine/tests/engine/PluginTest.cpp (3)

80-88: LGTM! Test correctly verifies plugin retrieval.

The test properly validates that:

  1. A plugin can be retrieved after being added
  2. The systemId is populated during the Bind() call (which happens immediately in AddPlugins)

90-109: LGTM! Comprehensive test for the PR's main use case.

This test effectively validates the primary motivation for the PR: retrieving systemIds to enable/disable specific systems. The test flow correctly:

  1. Registers the plugin and its system
  2. Runs systems once to verify execution
  3. Disables the system using the retrieved systemId
  4. Confirms the system no longer executes on subsequent runs

55-62: Verify the return type structure from RegisterSystems.

The code assumes RegisterSystems returns a tuple-like structure and uses std::get<0> to extract the systemId. While this works if the underlying scheduler's AddSystems returns a tuple, consider verifying this assumption holds across all scheduler types used in the codebase.

#!/bin/bash
# Description: Search for AddSystems method implementations in scheduler classes to verify return types

# Find scheduler implementations and their AddSystems method signatures
rg -n -A5 -B2 "AddSystems\s*\(" --type=cpp -g "*Scheduler*" -g "!test*"
src/engine/src/plugin/APlugin.hpp (1)

12-14: LGTM! Proper forwarding of return value.

The change from void to decltype(auto) correctly forwards the return value from RegisterSystem, enabling plugins to capture and expose system IDs. The use of inline is appropriate for this template method.

This change is essential for the PR's goal of allowing users to retrieve and manage system IDs.

src/engine/src/core/Core.inl (2)

3-3: LGTM! Proper dependency inclusion.

The include for MissingPluginError.hpp is correctly placed alongside the existing exception includes.


91-100: LGTM! Implementation follows established patterns.

The GetPlugin implementation correctly mirrors the GetResource pattern:

  • Type-safe lookup using std::type_index
  • Throws descriptive exception if not found
  • Returns reference via static_cast (safe due to type_index guarantees)
  • Consistent formatting and error handling

@ripel2 ripel2 changed the title feat(core): add GetPlugin function and return SystemIDs feat(core): return SystemIDs in plugin abstract RegisterSystems Jan 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/engine/tests/engine/PluginTest.cpp (1)

64-65: Consider using a getter method instead of a public member variable.

While the public systemId is acceptable for test code, production plugins should use a getter method (e.g., GetSystemId()) to maintain encapsulation. This would follow C++ best practices and prevent unintended modifications to the stored ID.

♻️ Proposed refactor using a getter method
-    // For testing purposes, the systemId is exposed in public. Don't know if it's a good idea in production code.
-    FunctionUtils::FunctionID systemId;
+    FunctionUtils::FunctionID GetSystemId() const { return _systemId; }
+
+  private:
+    FunctionUtils::FunctionID _systemId;

Then update line 61:

-        systemId = std::get<0>(systemIdTuple);
+        _systemId = std::get<0>(systemIdTuple);
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02f5927 and 2522272.

📒 Files selected for processing (2)
  • src/engine/src/core/Core.inl
  • src/engine/tests/engine/PluginTest.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/engine/src/core/Core.inl
🧰 Additional context used
🧬 Code graph analysis (1)
src/engine/tests/engine/PluginTest.cpp (1)
src/engine/src/plugin/APlugin.hpp (2)
  • RegisterSystems (12-15)
  • RegisterSystems (12-12)
🔇 Additional comments (2)
src/engine/tests/engine/PluginTest.cpp (2)

55-62: LGTM! This correctly demonstrates the new SystemID capture feature.

The Bind() method properly demonstrates the PR's objective: capturing the FunctionID returned by RegisterSystems so it can be stored and later used to enable/disable specific systems.


5-5: Remove the unnecessary include "scheduler/Startup.hpp".

The Engine::Scheduler::Update type is already available through the existing include chain: APlugin.hppCore.hppscheduler/Update.hpp. The newly added #include "scheduler/Startup.hpp" is redundant and does not provide the Update scheduler type. Unless the code explicitly uses Engine::Scheduler::Startup (which is not evident from the review context), this include should be removed.

Likely an incorrect or invalid review comment.

Comment thread src/engine/tests/engine/PluginTest.cpp Outdated
@ripel2 ripel2 enabled auto-merge (squash) January 10, 2026 17:48
@sonarqubecloud

Copy link
Copy Markdown

Miou-zora
Miou-zora approved these changes Jan 10, 2026
@ripel2 ripel2 merged commit 24940c2 into main Jan 10, 2026
16 checks passed
@ripel2 ripel2 deleted the get-plugin-and-system-ids branch January 10, 2026 18:05
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.

2 participants