Max entry limit on bitwise enums?

Can I add and reorder entries in eSculptFlags in file DNA_scene_types.h, for this:

    /* If set, dynamic-topology detail size will be constant in object space */
    SCULPT_DYNTOPO_DETAIL_CONSTANT = (1 << 13),
    SCULPT_DYNTOPO_DETAIL_BRUSH = (1 << 14),
    SCULPT_DYNTOPO_DETAIL_MANUAL = (1 << 15),

    /* Don't display mask in viewport, but still use it for strokes. */
    SCULPT_HIDE_MASK = (1 << 16),

I have added a 4th detail mode for dinamic topology, that doesn’t update the dynotopo on each stroke only on Flood Fill.
Re-topoing on each stroke seems like an overkill, this manual mode is how Zbrush operates by default using dynamesh.
Screenshot%20from%202018-06-27%2010-08-06

You should not change the number values, this will break backwards compatibility. But since enum items do not need to have consecutive values, you can do this:

/* Don't display mask in viewport, but still use it for strokes. */
SCULPT_HIDE_MASK = (1 << 15),

/* If set, dynamic-topology detail size will be constant in object space */
SCULPT_DYNTOPO_DETAIL_CONSTANT = (1 << 13),
SCULPT_DYNTOPO_DETAIL_BRUSH = (1 << 14),
SCULPT_DYNTOPO_DETAIL_MANUAL = (1 << 16),

Was thinking of it, still for the record 1 << 63 max value ?

It’s 1 << 31 in this case, because the flags are defined as a 32 bit int.

1 Like

From a coding perspective, I was wondering what inspired this design decision, rather than having plain integer values for enums.

Bit-wise operations are faster

1 Like

They’re not faster, but it saves some memory. In case like this it’s pointless though and there really is no good reason to store the enum this way, but the code just happens to be written that way. Only for data structures where there will be potentially many copies in memory does it really help.

1 Like