Python version of FLAME GPU 2 #1034
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Transpiling is the process of taking source code written in one language and transforming it into another language that has a similar level of abstraction. In this case FLAMEGPU2's Python transpiler takes an agent function expressed in a pythonic syntax e.g. @pyflamegpu.agent_function
def add_func(message_in: pyflamegpu.MessageNone, message_out: pyflamegpu.MessageNone):
x = pyflamegpu.getVariableInt("x")
pyflamegpu.setVariableInt("x", x + 20)
return pyflamegpu.ALIVE You pass it to the transpiler func_translated = pyflamegpu.codegen.translate(add_func) This will store a string with the C++ equivalent agent function inside e.g. FLAMEGPU_AGENT_FUNCTION(add_func, flamegpu::MessageNone, flamegpu::MessageNone) {
int x = FLAMEGPU->getVariable<int>("x");
FLAMEGPU->setVariable<int>(x + 20);
return flamegpu::ALIVE;
} Which can then be passed to FLAMEGPU as a runtime compiled (RTC) function for use in a model. Or you could just look at the generated string, if you want to understand how the C++ equivalent would be structured. func = a.newRTCFunction("add_func", func_translated) There are some limitations to this, e.g. you can't start using Hope that helps. In drafting this reply, I spotted a mistake in one of the related code examples in the documentation, I will get that fixed ASAP. |
Beta Was this translation helpful? Give feedback.
Transpiling is the process of taking source code written in one language and transforming it into another language that has a similar level of abstraction.
In this case FLAMEGPU2's Python transpiler takes an agent function expressed in a pythonic syntax e.g.
You pass it to the transpiler
This will store a string with the C++ equivalent agent function inside
func_translated
e.g.
FLAMEGPU_AGENT_FUNCTION(add…