In the game I'm making I'd like to be able to override specific C++ functions with a python functions, as seamlessly as possible. The idea would be to allow quick coding of some functions in an interpreted language for prototyping / modding etc
Ideally I'd like to have a structure behaving like this:
In my C++ source code:
class WorldActions
{
public:
//example of a method with a default implementation:
virtual Coordinates respawnLocation(int event) const
{
if(event == 0)
return Coordinates(0,0);
else
return Coordinates(1,0);
}
}
Within a python file:
def respawnLocationOverride(worldActionInstance, event):
coords = Coordinates()
coords.x = 1
return coords
At some point in the C++ engine I dynamically load the python method "respawnLocationOverride" which will effectively replace WorldActions::respawnLocation, this could be done through a special derived class like this :
class WorldActionsFromPy : public WorldActions
{
public:
virtual Coordinates respawnLocation(int event) const
{
if(_something == NULL)
{
return WorldActions::respawnLocation(event);
}
else
{
return _something->callPythonMethod("respawnLocationOverride", this, event);
}
}
}
What kind of architecture would you recommend for me to be able to do that as simply as possible? I know I can use swig to generate all the python classes, but I have no idea how I would be able to re-import the python code within a .py file into C++ code
thanks!