mbool is a small helper class that acts like a bool, but keeps track of the number of its state changes.
More...
|
constexpr | mbool (bool value=false) |
| Constructor: Creates the mbool and initializes the boolean value (default to false). More...
|
|
constexpr | mbool (const mbool &value) |
| Copy-constructor, copies state and memory. More...
|
|
| ~mbool ()=default |
| Destructor does nothing but not defining it might create a symbol (class is header only) More...
|
|
unsigned char & | getMemory () |
| Returns the memory value. More...
|
|
constexpr | operator bool () const |
| Implicitly converts the mbool to a bool. More...
|
|
constexpr bool | operator! () const |
| Returns the inverted state of the bool (doesn't change the internal state). More...
|
|
constexpr bool | operator!= (bool other) const |
| Compares the mbool to a bool, returns true if the bool has a different value than the state of the mbool. More...
|
|
constexpr bool | operator!= (const mbool &other) const |
| Compares two mbools, returns true if they have a different memory value. More...
|
|
mbool & | operator++ () |
| Increases the memory which also inverts it's state (++mbool). More...
|
|
mbool | operator++ (int) |
| Increases the memory which also inverts it's state (mbool++). More...
|
|
mbool & | operator= (bool value) |
| Assigns a boolean value (and increases the memory value if the value is different to the old value). More...
|
|
mbool & | operator= (const mbool &value) |
| Assigns another mbool, copies state and memory. More...
|
|
constexpr bool | operator== (bool other) const |
| Compares the mbool to a bool, returns true if the bool has the same value as the state of the mbool. More...
|
|
constexpr bool | operator== (const mbool &other) const |
| Compares two mbools, returns true if their memory matches. More...
|
|
mbool is a small helper class that acts like a bool, but keeps track of the number of its state changes.
The mbool class acts like a bool, but it has an internal counter that counts the number state changes (i.e. when the bool changes from true to false or back). This is used in the network if a boolean value is synchronized, because if a value changes quickly from false to true and back in the same tick, the clients will never be notified of this action. By using mbool however this behaviour is fixed, which is important for triggers and other objects.
- Note
- This is efficiently solved by using a union that combines a counter and a boolean bitfield of size 1. The boolean value corresponds always to the first bit of the counter - this means, if the counter is incremented, the boolean state changes. On the other hand, if you want to change the state, you can simply increase the counter.