FLAMEGPU2 icon indicating copy to clipboard operation
FLAMEGPU2 copied to clipboard

Replace String Literals with static/const/constexpr

Open ptheywood opened this issue 4 years ago • 3 comments

String literals for reserved variable names such as _stepCount, _id, _agent_birth etc. are bad.

RTC/Jitify means there is a lot of forward declaration in headers, rather than includes, so we need some sensible way of having constants without having to effectively re declare them.


From #719

Rather than use raw string literals all over, we should try to use cosntexpr's instead, such as the exisitng ModelData::DEFAULT_STATE inplace of "default".

This is used in some places, but not all.

The same will apply for other string literals such as _id etc.

We could do this for "x"/"y"/"z", but this might not be as desirable.

ptheywood avatar May 15 '20 16:05 ptheywood

"_agent_birth" is used in CUDAAgentModel and CUDAAgent. Should be static const "agent_birth_flag" or similar, owned by CUDAAgentModel. Isn't used on device, it's hashed and combined with agent function name before it gets to device.

Robadob avatar May 15 '20 16:05 Robadob

Ownership within CUDAAgentModel is not idea (although logical) for all cases, as others are used in placed where CUDAAgentModel is (and should due to rtc) only forward declared.

ptheywood avatar May 15 '20 16:05 ptheywood

It works for this case, only other class "_agent_birth" is used in already depends on CUDAAgentModel. Special header may only be needed for stuff shared across host/device.

Robadob avatar May 15 '20 16:05 Robadob