Introduction
I'm trying to create a tech-demo for an engine based on several concepts. The engine is copying Minetest's structure for mods where the engine is itself a standalone executable and the mods are loaded/run after the engine is executed to add all game content. Mods are written in runtime compiled C++ (main focus and why it is a tech-demo to see if I can get it to work) and Lua/LuaJit. And yes, the tech-demo and possible resulting engine would be under a FOSS license. I haven't put the source up yet as it currently does next to nothing, but I can if someone wants it.
My issue
I'm trying to implement an Entity-Component-System so mods can define systems and components. However, all the ECS libraries I have looked at use C++ templates, which are compile-time only to my understanding, for adding and tracking systems and/or components. This causes an issue since the engine loads mods at runtime which define new systems and components, but since the templates are evaluated when the engine is compiled mods cannot use the ECS library's add system and/or add component functions. Templates also causes my Lua scripting language problems since I cannot use a single wrapper class as mods would overwrite each other when registering different instances of the wrapper class to the ECS library. (if that makes sense, >.< ) Then again maybe I'm just an idiot that doesn't understand templates very well.
I have looked at entityx and artimis-cpp in detail and a half dozen more superficially and they all use templates.
Reference: http://tilemapkit.com/2015/10/entity-co ... x-artemis/
So here is an example of my problem. The following code sets up a component and a system in C++ using entityx.
- {l Code}: {l Select All Code}
#include "entityx.h"
struct PrinterComponent {
std::string text;
PrinterComponent(std::string _text) : text(_text) {}
};
struct PrinterSystem : entityx::System<PrinterSystem> {
public:
PrinterSystem() { }
void update(entityx::EntityManager &es, entityx::EventManager &events, entityx::TimeDelta dt) override {
es.each<PrinterComponent>([dt](entityx::Entity entity, PrinterComponent &printer_data) {
std::cout << printer_data.text << std::endl;
});
}
};
Then the code must call "entity_manager.systems.add<PrinterSystem>();" to add the system. Similarly the code must call "entity.assign<PrinterComponent>("test1");" to add components to an entity. This is fine in a normal game, but with my engine I have both C++ and Lua mods that need to define systems and components during run time.
All the libraries I looked for used c++ templates. The only thing I can think of is to write my own which I really wanted to avoid since I doubt I could make something efficient enough for a game with many entities plus it would take time away from my focus (C++ Runtime Compiled mods).
Basically I'm asking if anyone knows of a decent ECS library that doesn't use templates.
Additional Notes
I'm trying to use ECS because I like the modularity and think it would work really well in a modding environment. Three different mods can define 3 different systems along with their components and then a fourth mod can mix and match them to create several different entities. I'm not really sure how I would do it without ECS.
I'm trying for C++ Runtime Compiled mods/code because I really think it is a way to make your mods 1st class citizens. I'm hoping for little to no overhead with interfacing with the engine since they are both C++ so there should be very little slowdown. Of course c++ mods will still need some sandboxing, which adds overhead, to protect users. There is also several prior attempts, though not for mods more for rapid development, so it isn't an unprecedented idea.
In my project, mods extend the engine in 4 ways: defining and redefining systems and related components (where i'm having an issue with ECS libraries), extending or overriding the engine's API, one time running of configuration API functions, and defining code not associated with a single entity that runs on a timer or the global time step.