0 votes

I want to save a data like : 010010010101000001000111111100011101100110101...

what if find to achive this is to use PoolByteArray.but it's an array which means more expensive than a simple binary type.
another way is to save the data in an image,but it's also expensive.

and the PoolByteArray's interface is not design for binary.for example,no interface to init a size of binary with default value.(PoolByteArray can use resize,but the default value is random because it's only resize). what's more ,if I want to set 4~99 bit to 1,the only way is to loop and set each index,no interface like setbit(4,1,(99-4)).and so on.

so what is the right way to do this,anyone can help me,thanks a lot!

in Engine by (30 points)

Hi,
i dont get it what you want. But there is no bitsized storage type. Bits allways come in Bytes (early computers got nibbles but thats long ago). So the PoolByteArray is the way to go.

Gd Script has binary operators:
~ Bitwise NOT
<< >> Bit shifting
& Bitwise AND
^ Bitwise XOR
| Bitwise OR

with them you can manipulate the bytes on binary level

func setBit( position, value):
    var offset = floor(position / 8)
    var bitOffset = position - offset
    var byte = byteArray[offset]
    if value:
        byte = byte | (1 << bitOffset )
    else:
        byte = byte & ~(1 << bitOffset )
    byteArray[offset] = byte.

What does your setbit function should do? What are those attributes?

thank u~but what's the type of "byte" in your code? a PoolByteArray ?

but a PoolByteArray can't use | or & operateor

if the byte in your code is a int ,it will limit to 32bit. i want to write a large amount of bits data,a int is not enough.

i use this in my marchingcube project,to save the space points data,which is only 0 and 1.

Oh, im sorry i got distrected ans forgot half off the code. Byte is the byte in the array at the offset.
I would extend poolbytearray(if its possible) and add the functionality.

I have edited my answer.

thanks for your answer,I've got your point

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.