Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: ZH on Wed 30/12/2009 08:39:25

Title: MODULE: bit manips v0.4 - bit manipulation functions
Post by: ZH on Wed 30/12/2009 08:39:25
The bit manips module includes bit manipulation functions (getting bits, changing bits, and copying sequences of bits) for char, short, and int.

This module is written for AGS 3.1.

The only documentation that should be necessary is in the comments of the script header file.

This module does not conform to the Script Module Guidelines; if its deviation bothers you, you can change it.

Quote from: ZH, 2009/Dec/30
I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
In case this is not legally possible:
 I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

Changes:





Download (http://zhags.webs.com/ags_modules/bit_manips_0_4) (Add ".zip" to the end of the filename.)
Title: Re: MODULE: bit manips v0.1 - bit manipulation functions
Post by: Dualnames on Wed 30/12/2009 13:32:08
I'm prolly stupid, but apart from bit manipulation, what does that module REALLY does? I mean where would I need it?
Title: Re: MODULE: bit manips v0.1 - bit manipulation functions
Post by: Khris on Wed 30/12/2009 15:29:18
I've started creating a tile map editor, and the tile map format exported by ProMotion uses bits to store stuff like whether the tile is flipped, etc. so I had to write those functions myself.
That's just one possible use for that module and no, it doesn't seem to do anything except what the description says. Weird.
Title: Re: MODULE: bit manips v0.1 - bit manipulation functions
Post by: ZH on Wed 30/12/2009 20:34:47
Quote from: Dualnames on Wed 30/12/2009 13:32:08I mean where would I need it?
You never really need it, but it makes getting or changing specific bits easier.
Edit: To be more specific, it's useful mostly for
Quote from: Khris on Wed 30/12/2009 15:29:18
I've started creating a tile map editor, and the tile map format exported by ProMotion uses bits to store stuff like whether the tile is flipped, etc. so I had to write those functions myself.
That's just one possible use for that module
Yes.
Quote from: Khris
Weird.
How so?
Title: Re: MODULE: bit manips v0.3 - bit manipulation functions
Post by: Charity on Fri 01/01/2010 09:49:41
Related question: Is using bits in a char or int to store a series of binary values any faster or more space efficient than using multiple bools?

For instance, if one were to use a large array of structs and each stuct needed to hold a large number of binary values (say the presence or not of a plethora of individual status ailments on RPG characters), is there a chance that storing all these values in one int per struct instead of several bools would notably improve performance or filesize?
Title: Re: MODULE: bit manips v0.3 - bit manipulation functions
Post by: ZH on Fri 01/01/2010 10:17:27
Quote from: Lyaer on Fri 01/01/2010 09:49:41Is using bits in a char or int to store a series of binary values any faster

No, it's definitely slower. Additionally, as of version 0.3, certain short and int functions are slower than the corresponding char function, due to slight optimizations I made to the char one but not to the others. I'll probably do the same with those for the next release.

Quote from: Lyaer on Fri 01/01/2010 09:49:41or more space efficient than using multiple bools?

Yes. I don't know the details of AGS's implementation, but boolean types usually take one byte; some compilers (for example, pre-.NET Visual Basic) use two bytes per boolean. You can use as many as eight bits on a char, sixteen bits on a short, or thirty-two bits on an int. If you have to store very many boolean values, storing eight per byte rather than one per byte would reduce memory consumption. The number of boolean values you have to store would have to be very large to overcome the overhead of writing and reading the bits, though.
Edit: I don't remember why I thought the stricken-out part. If you have more than a few status effects, it would reduce memory consumption.

Quote from: Lyaer on Fri 01/01/2010 09:49:41is there a chance that storing all these values in one int per struct instead of several bools would notably improve ... filesize?

Probably, but to be certain I would have to know how the AGS savegame format works.
Title: Re: MODULE: bit manips v0.4.1 - bit manipulation functions
Post by: Charity on Sun 03/01/2010 21:33:30
Awesome.  Good to know.

I went ahead and changed the formatting to fit the AGS module guidelines.  As far as I know I didn't break anything.  Still compiles at any rate.

http://www.mediafire.com/file/z4rnnmznmmy/BitManips_0_4_1.zip