I thought I should just give a quick update:
After hot-plug support was implemented, development stalled again due to a bug. The bug is an issue with OnLibraryAdded being called to early (not a bug in SourceMod, just a limitation in my implementation). It's called before a library plugin is initialized, and things breaks when the module try to use that uninitialized library.
That's one issue. There's another issue with boilerplate code required in a module to properly wait for all dependencies to be ready. This code may be duplicated between multiple modules, even for the same dependencies. So I decided to make a simple dependency manager.
Dependency Manager
The dependency manager is basically just a wrapper for OnLibraryAdded and OnLibraryRemoved, with some extra features that I need. I try to design this so it will work with these library events in SourceMod.
Modules need two events:
- OnDependenciesReady - Triggered when all its dependencies are ready (not just loaded). In this event, modules should initialize.
- OnDependenciesUnavailable - Triggered when one or more dependencies are no longer available, such as when a library plugin was unloaded. In this event, the module should disable itself and clean up resources.
Using these two events we make it possible to do hot-plugging of modules while reducing the burden of checking dependencies.
Modules use natives in the dependency manager to declare its dependencies, and then simply waits for the ready-event.
The dependency manager will also provide some natives for registering a library, with a name that matches the one sent to RegPluginLibrary. It will keep track of availability of all libraries and notify modules when all their dependencies are met.
To solve my first issue, the manager will provide natives for manually triggering the ready-event, so that modules won't receive OnDependenciesReady until all libraries are loaded
and initialized.
The hot-plugging demo in my previous post works because the module manager doesn't need initialization. Once I started working on other modules, hot-plugging was broken. With the new dependency manager it should be back on track.
It's really cool to see the modules dynamically respond to the changes in the environment. The really tricky part is to make the code simple and elegant, but I'm on to something now.
__________________