[DISCLAIMER: THIS POST CONTAINS BASIC, SIMPLIFIED EXPLANATIONS OF BITWISE OPERATIONS FOR NEWBIES SUCH AS MYSELF, AND WILL POSSIBLY BE VERY BORING TO GURUS!]
[EDIT: Disclaimer 2 (Aug 2011): Over the last year, I've edited the following explanation multiple times, as I (slowly) became less newbie. The explanation is still valid, and I hope useful, but it may still contain inaccuracies. Make sure you read the following posts for yet more corrections.]
Thanks to Spike for the "bitwise truths" example/demo/calculations. I looked at them over and over, and am pleased to say that (finally) there's been a BREAKTHROUGH in my grasp of the topic. Hopefully.
Ok, I had two major misunderstandings:
Misunderstanding 1.
I was thinking of the 'dimensions' as 'channels', and assumed things on the same channel were visible to each other, and things on different channels were not. WRONG. The dimension 'channels' only have to produce the result '0' as a result of Spikes formula:
Code: Select all
if (see&seen == 0), the ent is not visible
Misunderstanding 2.
I also thought, from looking at typical qc code such as:
that (in this example) 'thing.flags & #FL_MONSTER' asks the question: "Are the bits set to '1' in #FL_MONSTER, also set to '1' in thing.flags?", and expecting a yes (1) or a no (0). But in fact (for the benefit of anyone reading this more newbie than I) the '&' outputs a new number, compiled by all the bits that the two numbers have in common. If the new number is > 0 [EDIT: WRONG, that should be "if the new number is !=0", negative numbers produce a 'TRUE' result in 'if' statements], the if statement (such as above) is TRUE. The typical bitwise explanation diagrams always show the two values/ bytes directly above the other and this makes it much easier to grasp. We look at columns, and make a new number, by putting a '1' in every box where both numbers have a '1'. This is why the values in defs.qc for flags are (usually) 1,2,4,8,16 etc, because those numbers produce usable results for boolean checks using '&'. Yes this is old news to the Gurus here, but to a newbie like me suddenly a whole bunch of things have fallen into place.
Anyway, although the bodyque error (as per my previous post) is still being analysed, I believe I (finally!) DO grasp the .dimension see concept
So I thought I'd do walkthrough of my understanding, both for the benefit of any other newbies interested in using .dimension, and for my own benefit to make things clearer, to provide a 'reference guide' in case I forget all this in a few months, and (of course) to give the Gurus a chance to step in and correct anything I've said which is incorrect.
So without further ado:
WALKTHROUGH: ACHIEVING 'DEAFNESS' VIA .DIMENSION_SEE AND BITWISE OPERATIONS:
1. We give every entity in the game a default .dimension_see and .dimension_seen value of '3'. [EDIT: this step isn't necessary, as explained in the next post. Also the figures below were arrived at simply by looking at the two bytes on top of each other, and figuring out where the '1's needed to be so that they lined up to produce a '0' as the result of a '&' operation]
2. We spawn 2 players, Tom and Dick both with the (default) .dimension_see of 3 (00000011)
3. We make Dick deaf by changing his .dimension_see to '2' (00000010).
4. Tom throws a grenade with the (default) .dimension_seen of 3 (00000011).
Now, remembering Spike's formula:
Code: Select all
if (see&seen == 0), the ent is not visible
we process the numbers:
if (Dick.dimension_see & grenade.dimension_seen) != 0, Dick (who is now deaf, remember) will see the grenade (which is what we want).
if (2&3 != 0) //Dick sees the grenade
00000010 (2)
&
00000011 (3)
=
00000010 (2)
So, 2&3 == 2 != 0 // therefore Dick will see the grenade
Now, to make sure Dick doesn't hear the grenade, just before the sound function, we change its' grenade.dimension_seen to '1' (00000001). Dick is still deaf and has .dimension_see = 2.
The formula again:
Code: Select all
if (see&seen == 0), the ent is not visible
if (Dick.dimension_see & grenade.dimension_seen == 0) //Dick will NOT hear the grenade
2&1
00000010 (2)
&
00000001 (1)
=
00000000 (0)
None of the bits match, so the final number gets NO bits, which means 2&1 == 0 ... so Dick doesn't hear anything (good!).
But what happened to Tom? He still has the .dimension_see of 3 - did he get to hear the grenade (w a .dimension_seen of 1?)? Let's find out:
if (see&seen == 0), the ent is not visible.
tom.dimension_see & grenade.dimension_seen
3&1
00000011 (3)
&
00000001 (1)
=
00000001 (1)
3&1 == 1 != 0 so the ent is NOT invisible to Tom, and he did in fact hear the grenade!
Hope this helps!
OneManClan