Modding support and moving scripts to C++

I read a long time ago somewhere (probably on our wiki) that the original plan for using Lua was for just quick prototyping that should be moved to C++.

I found the old discussion:

So, indeed, it’s been planned for a long time to reduce the script usage amount to improve performance etc. The situation is a bit better now with AngelScript as it doesn’t let you dynamically dump properties on anything any time you like, so maybe we can in the long term tolerate some part of the game being permanently in script form. Also there’s things like AngelScript JIT we can add here to help things along, it’s also much less of a performance issue to call C++ code from AngelScript as it was designed to integrate very closely with it. But I think it will be better in the long term if we move “finished” systems / parts of the game into C++ to get every bit of performance we can get.

The problems with this approach, as correctly identified in that older thread are that modding will be a lot more involved and if we want to support it well we need to spend a lot of time exposing hooks for mods to use. Of course this will make it possible to have multiple mods on at once, which isn’t very possible with the current approach of “just edit the script files and copy them over the old ones”, so I think we’ll need to do this anyway. And I haven’t seen very many involved mods, yet. I think part of the issue here is that if someone has the skills to make an excellent mod they should join the dev team.

The other is that tweaking the code is more time consuming as compiling takes some time. But this isn’t a big concern with any of the mostly finished systems and when we want something to be tweakable it should load its values from json to allow that easy testing.

All in all I think we should finally aim for having the core microbe systems moved to C++ for maybe 0.4.3 or 0.5.0. Any opinions on this before I make a Github issue?

1 Like

Two questions I have about this. Is performance suffering at the moment, is that a problem we need to solve or is it just generally preferable to be faster?

How long would it take to move the scripts across, as it sounds like that could be quite a lot of work for a very small payoff if we don’t need the performance? If all that work is done and the player doesn’t even notice the difference is it really worth it?

I think the performance is not optimal at the moment. I’m not sure if it is caused by the scripts or what, but the game should be limited to 120 FPS but at least on my system it rarely hits that. I think probably the AI or the Microbe system is the culprit and both of those are in scripts.

It’s definitely much easier than moving from Lua as AngelScript syntax is heavily inspired by C++. So many blocks of the script code could literally be copy-pasted to a C++ source file and they would work perfectly. There are some differences as well with the names of specific size types, the standard container method names. But the biggest problem is that the AngelScript handle type doesn’t have a 1-to-1 conversion to C++ so the person doing the converting needs to determine if it should be a raw pointer or a reference counted pointer.

Overall it shouldn’t be that time consuming.

1 Like

Seeing as this discussion ended and no strong opposing points came up I’ve made this an issue for Github:

We can decide later which release should aim to have it complete.

1 Like

Yeah i see no reason to oppose this

1 Like

I found some discussions about moddability (basically all are: use a bunch of data files and have a scripting language that can be hooked into specific parts of the game)

Some more advanced modding techniques is basically compiling a new module to be added to the game. But as we are open source I think such mods should be made directly as forks of the game. No reason to need to have separate binaries.

https://forum.unity.com/threads/making-a-moddable-game.312490/

And some example games:

https://stellaris.paradoxwikis.com/Modding

https://www.torchlightfansite.com/torchlight-2-forums/torchlight-2-modding/torchlight-2-modding-guide-threads/

So we can do all of these recommended things if we add hook points in the C++ code that allows mods to register scripts to run at specific points, but that needs a bit of work for us to add a bunch of such points to make complex mods feasible. Or we can wait for community members to add hooks as they need, though that’s a bit difficult as most modders so far have confirmed my suspicion that people who don’t think they yet have the skills to actually develop the game make mods.

1 Like