DISQUS

DISQUS Hello! Building Browsergames is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Saving Database Space through Bit-masking

Started by Luke · 8 months ago

This is a trick you can use to increase the efficiency and readability of your project. It is an argument for good up front design as utilizing this is only plausible when you take the time and effort at the beginning. The following is a real world example from my game TerraTanks.
The problem %5 ... Continue reading »

4 comments

  • These tutorials are simply amazing! Thank you do much for writing them! You definately have a new fan.
  • 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;
  • 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.
  • 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!

Add New Comment

Returning? Login