Good day,
So, I'm currently designing a Plugin-in/Module System in a game engine I'm working on, and I hit a small hurdle. So, I got it working, so it's not in regards to that. So, the way it works at the moment is you create a module with an Entry file that contains a LoadModule function:
public class Entry
{
public void LoadModule()
{
// Any code to execute here
}
}
Now than. In the main core library, the dll is dynamically loaded into the executable using Assembly.LoadFrom() method. From there it's added to an API registry and the code is executed using ((dynamic)module.Handle.unwrap()).LoadMoule(). The Handle is the ObjectHandle? created from the Assembly.
So, now that you got a very rough idea on how the module system I created works. I want to be able to add functionality as I please into the engine, so far it does work. For example, the window and the renderer (opengl) are two separate functions, the window gets called and opens, but in order for the glrenderer to work, it has to be referenced in the window project.
Originally I wrote the module system in C99, but I got tired of everything breaking every 5 minutes, because of I'm terrible at C99, so I implemented it in C#. Sorry, I'm bouncing all over the place. The aim I'm trying to do is keep a Global Registry of the Modules and have the modules reference JUST that Core library and use the library to get the instances of the API to implement more features into the engine. But, due to .NET's natures of referencing things, and my habit of not wanting to use unsafe code and Marshalling information back and forth to get the same effect as the C99 version, I'm stumped.
Example:
Class Entry
{
public dynamic SomeModule;
public Entry()
{
SomeModule = ApiRegistry.GetApi("SomeOtherModule");
}
void SomeNewFreature()
{
var something = SomeModule.DoSomething();
var somethingElse = SomeModule.DoSomething(with, args);
}
public void LoadModule()
{
ApiRegistry.RegisterApi(this);
ApiRegistry.AddFeature(this, SomeNewFeature);
}
}
Something along those lines. Of course this works in C99 since all you have to do is include the header, and grab the struct of registry from the core file. But here it's not exactly doing this.
So, should I just reference the modules I need into the other modules I'm creating, example of the window referencing the renderer? Or Should I press forward with a global registry?
My aim is flexibility, to allow functionality to be added without messing with the core internals of the engine. If anyone has any advice in regards to this, I would love to hear it. Even constructive criticism works, but not the “Why are you making an engine when you have X, Y, Z available!” type, that's not constructive. If that's all you're going to ask, please refrain from doing so. I'm doing this for fun, experience, and because I want to say “I did this!"