• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.
Bitshift Encoding

Bitshift Encoding

Nice, thanks for the info. I somes times use bitshift in Mugen but I haven't tried to play with it in OpenBOR.
I will give it a try once I can.
 
O Ilusionista said:
Nice, thanks for the info. I somes times use bitshift in Mugen but I haven't tried to play with it in OpenBOR.
I will give it a try once I can.

I used to hate bitmasks because they were impossible for me to keep up with in my head (still are), but it's amazing what you can do with them. 32 flags in one integer? Yes please! They're also blazing fast. OpenBOR uses them for all kinds of work internally.

It now only requires one mask and has two compression methods included.

DC
 
Updated with some better formatting and use of the C coding tag (colorizes output).

DC
 
I really need to learn bitwise it was so confusing i just skipped it maybe some practical learning is needed.
 
I really need to learn bitwise it was so confusing i just skipped it maybe some practical learning is needed.

I wish I could tell you some learning trick, but there's really nothing to it other than practice. Every value you see on any device is made from a combination of 0s or 1s. When you do bitwork, you're just acting on those 0 or 1 switches instead of the total value they are encoded to represent.

In OpenBOR, the numbers in script are all 32bit. That means you have 32 true or false values to play with. All values are encoded identically, regardless of bitsize. So, that means a 32bit integer has enough bits for any combination of values or numbers that require 32 bits or less to encode. In practice, it gets pretty messy if you combine different bit sizes though, so most of the time you write your code to make a uniform split. In my example above, I'm encoding three numbers with a range of 0-255 (8bit).

All the stuff that goes with it is just math. It's nothing more than a glorified abacus.

@Roel is a master of optimization and wrote a lot of bitwise code. If he ever happens by he could explain it much better than I can.

DC
 
@DCurrent

If a int is 4 bytes this method saves 8 bytes maybe it will add up if using hundreds of int values. There is the extra overhead with encoding and decoding the data. I know you said bitwise operations are fast but is decoding faster then just referencing a int ?
 
@DCurrent

If a int is 4 bytes this method saves 8 bytes maybe it will add up if using hundreds of int values. There is the extra overhead with encoding and decoding the data. I know you said bitwise operations are fast but is decoding faster then just referencing a int ?

No offense, but I didn't write this tutorial to have a debate about the benefits. I could cite at least a dozen examples in script or the engine, but then it's another TLDR I wasted my time on. Bit techniques are an inarguable net reduction in overhead and memory usage, because they're the fundamental basis of computing. The only thing a CPU actually does do is bitshifting. Everything else is just a coat of paint.

Bitwise encoding can also reduce coding complexity (like for keyscripts). The drawback is difficulty for humans and increased complexity if overused. That's something only experience can teach. You'll just have to decide for yourself.

DC
 
Back
Top Bottom