The caveat in our scenario here is that a 4-byte-per-axis Vector3, which takes up 12 bytes total, would take up the same 12 bytes with string.pack. In addition, string.pack is capable of converting 8-byte floats into 4-byte floats for the sake of space, same as how Vector3s are stored. Given the options, string.pack is both faster and more space efficient. string.pack essentially uses base-256 and stores a full byte per letter. If you do want to store something using strings, base-64 is the equivalent of 0.75 bytes per letter. Local x, y, z = some_vector3.X, some_vector3.Y, some_vector3.Z only sends 12 bytes, plus 1 or 2 more bytes to specify that this is a Vector3. In other words, if you care about space, the first of these is better. If you try to handle the axes of a Vector3 manually, they become 8 bytes. Vector3s use 4-byte floats to represent the numbers for the sake of space. Here are some numbers if you’re still curious. That’s a respectable amount of research you’ve done on it. I’m going to leave these links here for anyone curious as well since they were helpful to me. Local result = Vector3.new(xUnpacked, yUnpacked, zUnpacked) Local zUnpacked = string.unpack("f", zDecoded) Local yUnpacked = string.unpack("f", yDecoded) Local xUnpacked = string.unpack("f", xDecoded) encodedZįunction module:DecodeVector3(vectorValue) Local packedZ = string.pack("f", vectorValue.Z) Local packedY = string.pack("f", vectorValue.Y) ![]() Local packedX = string.pack("f", vectorValue.X) ![]() Local unpackedString = string.unpack("z", decodedString)įunction module:EncodeVector3(vectorValue) Local encodedString = Encode(packedString) Local packedString = string.pack("z", text) ![]() It definitely isn’t written in the best way, but it’s readable to me so it’s alright. With these I made an encoder and decoder for vector3’s and strings. Local allbytes = SerializeVector(cf.XVector). Don't need to save Z vector as we can calculate it from the other two Local function SerializeVector(vec : Vector3) Local function SerializeCFrame(cf : CFrame) Thanks, I used this to make this other function which stores and loads CFrames from a base64 string compactly: Base64 Encoding and Decoding in Lua Community Resources
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |