DISQUS

Building Browsergames: Saving Database Space through Bit-masking

  • Blair Beckwith · 1 year ago
    These tutorials are simply amazing! Thank you do much for writing them! You definately have a new fan.
  • Mattias · 1 year ago
    Might want to note that in order to take off one of the researches (for some unknown reason) you need to AND with the complement of the bit.
    For example, if you had picked the g_shield_research and want to degrade it or something you use:

    $newPlayerResearch = $element->research &~$g_shield_research;
  • gostyloj · 1 year ago
    Good point Mattias. Just to explain a bit further what the operator notation is, the '&' will do a bit comparison where both members in the comparison need to have that bit set to 1. Because you are doing the AND operator all the bit places you don't care about need to be set to 1 so they maintain their value. The '~' operator inverts all the bits in the value so where a variable might look like 00010000, the inverse of that would look like 11101111.
  • Jorge · 1 year ago
    I am using the same logic on a project, a very quick way to get around using reference tables. Good article, great ammunition in the tech group for my idea!