[ioquake3] g_client.c weapon init question
Patrick Baggett
baggett.patrick at gmail.com
Thu May 29 08:25:50 PDT 2008
If WP_XXXXXXX constants are bit flags (i.e. 0x01, 0x02, 0x04, 0x08, 0x10,
0x20, ...) then doing a bitwise OR will select multiple, and
client->ps.stats[STAT_WEAPONS] = WP_PLASMAGUN | WP_BFG; //With bitflags
would be correct. However, if they are enumerations (i.e. sequential values
such as 0x00, 0x01, 0x02, 0x03, ....) then ORing them will give improper
results. You have to think of each enumerant's value as the BIT position it
covers. To set that bit however, you need to do a left-shift with 1, so that
the single bit is set.
client->ps.stats[STAT_WEAPONS] = (1<<WP_PLASMAGUN)| (1<<WP_BFG); //With
enumeration
Can someone just please go to the definition of the code and look it up?
On Thu, May 29, 2008 at 8:49 AM, Edson Alves Pereira <lottalava at gmail.com>
wrote:
> Wouldn´t be correct do that fashion?
>
> client->ps.stats[STAT_WEAPONS] = WP_PLASMAGUN | WP_BFG;
>
>
>
> On Thu, May 29, 2008 at 10:37 AM, Matt Turner <mattst88 at gmail.com> wrote:
>
>> On Thu, May 29, 2008 at 9:07 AM, Tyler Schwend <tylerschwend at gmail.com>
>> wrote:
>> > Likely, you could change:
>> >
>> > client->ps.stats[STAT_WEAPONS] = ( 1 << WP_PLASMAGUN );
>> >
>> > to
>> >
>> > client->ps.stats[STAT_WEAPONS] = ( 1 << WP_PLASMAGUN << WP_BFG);
>> >
>> > The << is a bit shifter, and you should be able to stack on whatever you
>> > want there...
>>
>> No. It would rather be
>>
>> client->ps.stats[STAT_WEAPONS] = (1 << WP_PLASMAGUN) | (1 << WP_BFG);
>>
>> Matt
>> _______________________________________________
>> ioquake3 mailing list
>> ioquake3 at lists.ioquake.org
>> http://lists.ioquake.org/listinfo.cgi/ioquake3-ioquake.org
>> By sending this message I agree to love ioquake3 and libsdl.
>>
>
>
> _______________________________________________
> ioquake3 mailing list
> ioquake3 at lists.ioquake.org
> http://lists.ioquake.org/listinfo.cgi/ioquake3-ioquake.org
> By sending this message I agree to love ioquake3 and libsdl.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ioquake.org/pipermail/ioquake3-ioquake.org/attachments/20080529/f5099c21/attachment.htm>
More information about the ioquake3
mailing list