Description

This library allows you to read/write "bits" into file streams - via buffers. This means you can pack date into files like never before. Just as buffers allow you to read and write bytes, shorts, integers with ease, now you can add to that and write individual bits while not having to lose the space in between.

Only need to write a true/false? then writing a boolean will write a single bit rather than a whole byte. a number under 16? then write 4 bits - halving the storage required. But by far the best, is that you can mix and match - write a bit, then 5 bits (0 to 31) then a floating point number (32 bits), then 2 bits (0-3) then 7 bits (0 to 128).

What this means is you can write a sequence of bits - as shown below, and take up ONLY what you require, possibly compressing your file data down to tiny amounts.

bit_stream_write_boolean( handle, active_flag);
bit_stream_write( handle, 2, object_state);
bit_stream_write_boolean( handle, object_damaged);
bit_stream_write( handle, 3, player_direction);
bit_stream_write_boolean( handle, player_sleeping);

All this data would take up just 1 byte of storage, where as using a standard buffer it could take as much as 11 bytes!

End User Licence Agreement (EULA).

Version 1.0.1. Published September 10, 2015

Created with GameMaker: Studio v1.4.1629

Age Rating: 4+

Average Rating

This asset hasn't received enough reviews yet.

Your review

You can only review assets you've bought.


Gravatar

deciia w 13 September 2015

usefull scripts

I want to write the data and save the data id,and read the data from id.
bit_stream_new(bs, 1024*1024); // Create a new buffer with enough space for demo
bit_stream_write( bs, 24,2 ); // data 1
bit_stream_write_double( bs,3.14159265359 ); // data 2
bit_stream_write( bs, 15,13 ); // data 3
var buffer = bit_stream_close(bs);

// read demo
bit_stream_open(bs, buffer); // open the buffer
var v1 = bit_stream_read_ext( bs, 1); // read data 1 auto to seek 0
var v2 = bit_stream_read_ext( bs, 2); // read data 2 auto to seek 24
var v3 = bit_stream_read_ext( bs, 3); // read data 3 auto to seek 88
buffer = bit_stream_close(bs); // close the stream

show_debug_message(v3) //13

Logo

Ogre Games (Publisher) 12 September 2015

On read, you tell it how many BITs to read, not which variable to read. This is because there is no metadata stored with the data you write, to do so would massively increase the size of the file (for most users). If you want that, then write your own type/size before writing the data, read that first, then read the correct data size....

// write...
bit_stream_write( bs, 7, 24 ); // meta data saying size of the data
bit_stream_write( bs, 24, 2 ); // 24 bits of data, value 2
bit_stream_write( bs, 7, 64 ); // meta data saying size of the data
bit_stream_write_double( bs, 3.14159265359 ); // 64 bits of data, value PI

I'll add another demo showing this....

Package contents

Loading, please wait

What is the issue?

Back to Top