[Bf-committers] Re: Re: [Bf-blender-cvs] CVS commit: blender/release/scripts image_billboard.py blender/release/scripts/bpymodules BPyRender.py blender/source/blender/python/api2_2x Scene.c

GSR gsr.b3d at infernal-iceberg.com
Mon Oct 9 22:44:33 CEST 2006


Hi,
cbarton at metavr.com (2006-10-09 at 1603.49 +1000):
> Ken Hughes wrote:
> > Campbell Barton wrote:
> >
> >>   Log:
> >>   an error in Scene.c - scn.Layers disallowd all layer bits to be set.
> >
> > This does a comparison for which checks for more than 21 bits being 
> > set (2097151 = 2^21 - 1).  Is that right?
> >
> > Ken
> Yep, anything over 2097151 will raise an error. the previous limit was 
> 1048575
> so scn.Layers= scn.Layers would raise an error if all layers were set.

<rant type="improve while fixing">
Why not use a more clear value?  Something like 0x0F if you want the
last 4 bits set (2097151 = 0x1FFFFF, 1048575 = 0xFFFFF) or (1 << 3)
for only the fourth from right side. Also, the comment in Scene.c has
not changed. And that without entering in why not just something with
a name (define, enum...) that can be reused everywhere keeping in sync
all the places.
</rant>

20 layers, 20 set bits... if I understood what is the required test,
code could be:

/* Blender's 20 layers -> last 20 bits in bitfield */
#define LAYERBITS 0xFFFFF
/* One or more bits in layers and no bits outside of layer fields */
if (!((laymask & LAYERBITS) && !(laymask & ~LAYERBITS))) { /* Error */ }

I tested the above via Python's interactive interpreter:
not ((laymask & LAYERBITS) and not (laymask & ~LAYERBITS))
returns 0 for laymask 0x400
returns 1 for laymask 0x4000000, 0x0 and 0x4000004
always with LAYERBITS 0xFFFFF

If you do not care about 21st and bigger bits, just the last 20, the
check is easier, of course.

GSR
 


More information about the Bf-committers mailing list