Skip to content

Add plugin dependency validation and finish lifecycle - #364

Merged
waynemwashuma merged 7 commits into
wimaengine:devfrom
waynemwashuma:plugin-extras
Sep 5, 2026
Merged

waynemwashuma merged 7 commits into
wimaengine:devfrom
waynemwashuma:plugin-extras

Conversation

@waynemwashuma

@waynemwashuma waynemwashuma commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Objective

Introduces explicit plugin dependency declarations and lifecycle validation across the engine. This ensures plugins fail early when required plugins are missing and provides a final initialization stage after all plugins have been registered.

Solution

The plugin system now allows plugins to declare their dependencies through requires() and perform post-registration setup through finish().

App.run() registers all plugins, validates their dependencies, invokes their finish callbacks, and then applies queued hooks, aliases, and resources.

Root Cause

Plugin dependencies were previously implicit. A plugin could be registered without the plugins it relied on, causing failures later during system execution or resource access.

The registry also did not create a stack trace for duplicate plugins or expose a lifecycle stage for initialization that depends on all plugin registrations being complete.

Why This Approach

This solution was chosen because:

  • Dependencies remain colocated with the plugins that require them.
  • Validation occurs after registration, allowing plugins to register additional plugins dynamically.
  • Missing dependencies are reported before systems begin running.
  • Registration traces make duplicate-plugin errors easier to diagnose.
  • The finish stage supports setup that requires the complete plugin graph.

Showcase

Before

class PhysicsPlugin extends Plugin {
  register(app) {
    // Assumes the required plugins are present.
  }
}

Missing dependencies were not detected during application initialization.

After

class PhysicsPlugin extends Plugin {
  requires() {
    return [
      typeid(CorePlugin),
      typeid(ReflectPlugin),
      typeid(MathPlugin)
    ]
  }

  finish(app) {
    // Runs after all plugins are registered and validated.
  }
}

Running an application without a declared dependency now produces an error identifying the requiring plugin and the missing plugin.

Migration Guide

Custom plugins can declare their dependencies by implementing requires():

requires() {
  return [typeid(RequiredPlugin)]
}

Plugins that require post-registration initialization can implement finish(app).

Applications must register every dependency declared by their plugins before calling run(). Duplicate plugin registrations must also be removed because they now throw an error.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 5, 2026
@waynemwashuma waynemwashuma added the type:enhancement New feature or request label Sep 5, 2026
@github-actions github-actions Bot added mod:app mod:command mod:input mod:math mod:render mod:event mod:window mod:physics mod:asset mod:transform mod:movable mod:device mod:audio mod:tween This PR/issue affects the `tween` package mod:hierarchy mod:gizmos Affects the gizmos package. mod:color This affects the color package mod:animation This PR/issue affects the animation system mod:time This PR/issue affect the time package mod:diagnostic This issue/PR affects the diagnostic module mod:geometry This PR/issue affects geometry package labels Sep 5, 2026
@github-actions github-actions Bot added mod:scene This affects the scene package mod:emitter This PR/issue affects emitter package mod:core mod:name mod:profiler mod:storage labels Sep 5, 2026
@waynemwashuma
waynemwashuma merged commit df65f06 into wimaengine:dev Sep 5, 2026
7 checks passed
@waynemwashuma
waynemwashuma deleted the plugin-extras branch September 5, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:animation This PR/issue affects the animation system mod:app mod:asset mod:audio mod:color This affects the color package mod:command mod:core mod:device mod:diagnostic This issue/PR affects the diagnostic module mod:emitter This PR/issue affects emitter package mod:event mod:geometry This PR/issue affects geometry package mod:gizmos Affects the gizmos package. mod:hierarchy mod:input mod:math mod:movable mod:name mod:physics mod:profiler mod:render mod:scene This affects the scene package mod:storage mod:time This PR/issue affect the time package mod:transform mod:tween This PR/issue affects the `tween` package mod:window type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant