[Galactigov-devel] Bitmasks
Status: Planning
Brought to you by:
erlendd
From: Alastair M. <a.g...@sm...> - 2006-07-09 16:37:29
|
The bitmask is just a convienient way of representing all the boolean values for if a player can see a system. It can be coded both in PHP and directly in MySQL queries. The visibleTo field is an integer and only means something when expressed in its binary form. So, if only player three should be able to see a system, you'd need the bitmask 00100000 For players two, five and seven to see a system, you'd have bitmask 01001010 To avoid dealing with the decimal integers (which is unwieldy and defeats the point of having them) the bitwise operators |, ^ and & need to be used. Now, I'll probably make a hash of explaining this, so refer to PHP or mySQL docs for a better explanation of how these operators work: The | operator - bitwise OR: The result is the equivalent of an OR operation between each bit. 0010010 | 0110001 = 0110011 This would probably be what you would use to register that a system had been explored by someone - you would just OR the visibleTo field with the integer 2 to the power of the player's id. This can be done directly with a MySQL query. The & operator - bitwise AND The ^ operator - bitwise XOR The beauty is that several masks can be easily OR'd or AND'ed or XOR'ed together, for example when determining which systems can be seen due to map sharing treaties. |