Introduce script wrapping classes
Right now many of the components accessible from the scripting language are made available through the following pattern:
- Store a pointer to script instance in the object
ScriptInstance *script_instance; - A method that can be overridden by a script is constructed using this template:
return_type ClassName::method(int argument) {
if (get_script_instance() && get_script_instance()->has_method(StringNames(method)))
return get_script_instance()->call(StringName(_estimate_cost), argument).as<return_type>();
This causes all of those methods to provide sub-optimal performance, since all calls have to perform those checks, even if the object itself was not created from the script-side.
I think this is a thing that was solved much more elegantly by SWIG's Director classes, where every class that has methods overrideable from script-side has a companion Director class that handles script langue calls, thus the main c++ code doesn't have to carry so much script-side baggage :)
To be honest, I'd much prefer if we were using SWIG to generate all bindings and had all of those things automated for us, but that'd require some work on the SWIG generator for Gdscript + maybe changing the way c# swig generator works.