31 lines
1.5 KiB
GDScript
31 lines
1.5 KiB
GDScript
extends SceneTree
|
|
|
|
func _init() -> void:
|
|
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))")
|
|
|
|
quit()
|