Recovered orphaned WIP before switching to a new task
This commit is contained in:
+13
-21
@@ -1,30 +1,22 @@
|
||||
extends SceneTree
|
||||
|
||||
func _init() -> void:
|
||||
# 1. float32 encode/decode
|
||||
var b: PackedByteArray = ChunkDataDecoder._write_float32(0.5)
|
||||
print("float32(0.5) bytes = ", b, " (expected 00 00 00 3f)")
|
||||
var decoded_f: float = ChunkDataDecoder._read_float32(PackedByteArray([0x00, 0x00, 0x00, 0x3f]), 0)
|
||||
print("read_float32 of 0x3f000000 = ", decoded_f, " (expected 0.5)")
|
||||
|
||||
# 2. metadata section wrapping: inspect first bytes of encoded payload
|
||||
var payload: ChunkDataDecoder.ChunkPayload = ChunkDataDecoder.ChunkPayload.new()
|
||||
payload.world_id = "w"
|
||||
payload.room_id = "r"
|
||||
payload.coord = Vector3i(1, 2, 3)
|
||||
payload.bounds = AABB(Vector3(0.5, 1.5, 2.5), Vector3(32, 32, 1))
|
||||
|
||||
var bytes: PackedByteArray = ChunkDataDecoder.encode_binary(payload)
|
||||
var decoded: ChunkDataDecoder.ChunkPayload = ChunkDataDecoder.decode_binary(bytes)
|
||||
|
||||
print("roundtrip bounds.position = ", decoded.bounds.position, " (expected (0.5, 1.5, 2.5))")
|
||||
print("roundtrip coord = ", decoded.coord, " (expected (1, 2, 3))")
|
||||
print("format_version present? -> ", decoded.get("format_version"))
|
||||
print("version field -> ", decoded.version)
|
||||
|
||||
# Test an object with a fractional rotation quaternion component.
|
||||
var obj: ChunkDataDecoder.WorldObjectData = ChunkDataDecoder.WorldObjectData.new()
|
||||
obj.position = Vector3(10.5, -3.25, 0.0)
|
||||
obj.rotation = Vector4(0.707, 0.0, 0.0, 0.707)
|
||||
var obj_bytes: PackedByteArray = ChunkDataDecoder._build_object_section(obj)
|
||||
# build_object_section wraps in a section header; parse it back
|
||||
var p2: ChunkDataDecoder.ChunkPayload = ChunkDataDecoder.ChunkPayload.new()
|
||||
ChunkDataDecoder._parse_object_section(obj_bytes.slice(5), p2)
|
||||
var parsed: ChunkDataDecoder.WorldObjectData = p2.objects[0]
|
||||
print("object position roundtrip = ", parsed.position, " (expected (10.5, -3.25, 0))")
|
||||
print("object rotation roundtrip = ", parsed.rotation, " (expected (0.707, 0, 0, 0.707))")
|
||||
var meta: PackedByteArray = ChunkDataDecoder._build_metadata_section(payload)
|
||||
print("metadata section first 12 bytes = ", meta.slice(0, 12))
|
||||
|
||||
# 3. properties parse with empty-ish string
|
||||
var props_str := "{}"
|
||||
var val = JSON.parse_string(props_str) or {}
|
||||
print("'JSON.parse_string(props_str) or {{}}' type = ", typeof(val), " value = ", val)
|
||||
quit()
|
||||
|
||||
Reference in New Issue
Block a user