So, I was making my game (a dungeon and dragons magic heartstone diablo might and magic kind of game) and I met my nemesis: I can’t stay focused. This is what came out:
Behold the moving box:
Which is not that interesting, even to me, but there’s a catch. This is the script that makes it move:
var scene;
var cube;
function start(engine) {
scene = bge.api.findSceneByName("Scene");
cube = bge.api.findObjectByName(scene, "Cube");
}
function update(engine) {
var buffer = new bge.mathutils.Tuple3f();
bge.api.getObjectLocalPosition(cube, buffer.values);
buffer.add(0.01, 0, 0);
bge.api.setObjectLocalPosition(cube, buffer.getX(), buffer.getY(), buffer.getZ());
}
function stop(engine) {
}
Web developers should recognized it on the fly. Javascript.
What is this madness.
Basically this is how the thing works: I took the codebase and added a second script system. Ok, it is intended as a complete replacement of the current one because I think the current one is godawful but I digress.
This new “LogicEngine” adds a couple of tiny classes in the bge codebase that define a plugin interface for external script engines (aka load a shared library).
It is, imho, a good start because you can take the bge code and remove from it all the “script” stuff. The pluggable system allows updates to the script api without having to rebuild the entire engine.
It also allows the engine to have multiple script modules: one might still be based on python3, one might be using Mono, mine will use the OpenJDK.
There’s a big pro in this variety. If you want to deploy the game on multiple platform, scripting is an issue because you can’t tell if the host platform will support. I’m thinking about webgl here: if the engine supports javascript as a “logic” language, you still need a webgl renderer but the logic is already done.
I’d like to stress out that having a plugin system allows the separate development of the script engine from the rest of the bge: the modified engine has no external dependencies, at runtime it looks up for the requested shared library, if there is one that satisfies the need of the scripts used for the game, it uses it, otherwise it starts and executes with no problem. It just doesn’t execute the logic defined with the new engine.
Issues.
None, on the technical side. I’ve not designed the ui panel that will allow the user to associate a script to an object or a scene or the entire game.
I’m using linux, so it’s currently working on linux but there are no reason whatsoever for it not to be translatable to windows or osx (in fact one only needs to add the dynamic library managament for windows, the rest is cross platform).
It adds the openjdk as an external dependency, meaning that the game engine is fully compilable and executable without it, but you need to have one to compile the script engine that uses the jvm and to run a game.
What’s the next step.
I know that a particle system is not feasible with the current python script system because the vm can’t keep up with the math. It’s not its fault, python does what it does with the magic of dynamic binding, which is wonderful until you start to have a gazillion calls per frame.
I’ll make a particle system with the current script api and then I’ll make another one for the jvm and this new script engine.
Will it be faster? If the answer will be “vastly” then the pro will be so many that I might start pestering the blender foundation about it. If the answer will be “a bit, but not too much” then it won’t be enough to force me having to deal with the blender irc channel.