FLAMEGPU/FLAMEGPU2

Access/Check agent state inside an agent function

Robadob opened this issue · 2 comments

Discussed in #1107

Originally posted by daniele-baccega September 18, 2023
Hi,
is it possible to access to the agent state inside an agent function?

Thank you


Need to decide a suitable API, but otherwise should be a simple PR.

Can we make the agent state comparison compile time? aka free?

Within an invocation of a kernel, all agents participating will be in the same state.

So presumably the use-case here is where the same agent function is reused, and somethign different needs to occur?

Agent state strings are only known at runtime, so dont' think we could make it a template value / constexpr if (for non-RTC).
RTC we could embed it within the kernel source, and hope the optimiser realises it can optimize out the branching, but would need to ensure the kernel is recompiled per agent fn launch, not just per agent fn source? (I'm not sure if this is the case or not). Would presumably still cost some registers though (or "local" memory)).

During execution, there would be no divergent branching atleast, so the string comparison(s) would be the only epxensive bit. So makeing state names that have different early characters would be a gross way to minimize the run time cost...

mondus commented

Seems sensible. Also add for agent name. Docs need to make sure that performance of this is mentioned for non RTC.