-
I just started to experiment with FlameGPU. I like it very much, but at the same time Cuda is a real pain. I would like to have a helper function for agent functions to scale uniform range from [0, 1] to any interval. So my code looks like: float rndRange(DeviceAPI<message_in, message_out> *FLAMEGPU, float min, float max) { return FLAMEGPU->random.uniform<float>() * (max - min) + min; }
FLAMEGPU_AGENT_FUNCTION(weather_update, flamegpu::MessageNone, flamegpu::MessageBruteForce) {
const flamegpu::id_t id = FLAMEGPU->getID();
const float temperature = rndUniformRange(FLAMEGPU, 0.0f, 30.0f);
FLAMEGPU->setVariable<float>("temp", temperature);
FLAMEGPU->message_out.setVariable<int>("id", id);
FLAMEGPU->setVariable<float>("temp", temperature);
return flamegpu::ALIVE;
} But I am getting the following errors: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Followup: I found a hack, but I am not in favour of macros at all. Any proper way to do that? #define rndUniformRange(flgpu, min, max) flgpu->random.uniform<float>() * (max - min) + min; |
Beta Was this translation helpful? Give feedback.
-
e.g. template<typename MessageIn, typename MessageOut>
float rndRange(flamegpu::DeviceAPI<MessageIn, MessageOut> *FLAMEGPU, float min, float max) {
return FLAMEGPU->random.uniform<float>() * (max - min) + min;
} Or specify the matching template arguments. e.g.: float rndRange(flamegpu::DeviceAPI<flamegpu::MessageNone, flamegpu::MessageBruteForce> *FLAMEGPU, float min, float max) {
return FLAMEGPU->random.uniform<float>() * (max - min) + min;
} This definitely isn't simple for users unfamilar with C++, we will need to have a good think about how can improve this (however the heavy template usage is required for optimisation, as it means alot of things can be processed at compilation time, so it's not as simple as removing the need for templates). In terms of providing a |
Beta Was this translation helpful? Give feedback.
DeviceApi
is a templated object. So you would either need to define the function as a template itself.e.g.
Or specify the matching template arguments.
e.g.:
This definitely isn't simple for users unfamilar with C++, we will need to have a good think about how can improve this (however the heavy…