From ee09904289c5a8b70f710e236f84310ae2ad0b21 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 25 Sep 2016 00:25:45 -0400 Subject: [PATCH] this seems suspicious --- ent/atoms.go | 3 +++ ent/float.go | 1 + ent/type.go | 3 ++- ent/vector.go | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ent/atoms.go b/ent/atoms.go index 6436886..af3e921 100644 --- a/ent/atoms.go +++ b/ent/atoms.go @@ -16,6 +16,9 @@ var atom_types = map[string]typeFn{ // TODO: bounds check here return uint16(bit.ReadVarInt(r)), r.Err() }, + "uint32": func(r bit.Reader) (value, error) { + return bit.ReadVarInt32(r), r.Err() + }, "uint64": func(r bit.Reader) (value, error) { return bit.ReadVarInt(r), r.Err() }, diff --git a/ent/float.go b/ent/float.go index 1e4e579..530a4d7 100644 --- a/ent/float.go +++ b/ent/float.go @@ -17,6 +17,7 @@ func floatType(spec *typeSpec, env *Env) tÿpe { case "CNetworkedQuantizedFloat": return qFloatType(spec, env) case "float32": + case "Vector": default: return nil } diff --git a/ent/type.go b/ent/type.go index fe91389..58c5386 100644 --- a/ent/type.go +++ b/ent/type.go @@ -32,7 +32,8 @@ func parseTypeSpec(spec *typeSpec, env *Env) tÿpe { } return nil } - return coalesce(arrayType, atomType, floatType, handleType, qAngleType, hSeqType, genericType, classType) + return coalesce(arrayType, atomType, floatType, handleType, qAngleType, + hSeqType, genericType, vectorType, classType) } // a type error is both an error and a type. It represents a type that we were diff --git a/ent/vector.go b/ent/vector.go index 5dcd82e..2bdebca 100644 --- a/ent/vector.go +++ b/ent/vector.go @@ -1,3 +1,35 @@ package ent +import ( + "github.com/jordanorelli/hyperstone/bit" +) + type vector struct{ x, y, z float32 } + +func vectorType(spec *typeSpec, env *Env) tÿpe { + if spec.encoder != "" { + return nil + } + return vector_t{elem: floatType(spec, env)} +} + +type vector_t struct { + elem tÿpe +} + +func (t vector_t) read(r bit.Reader) (value, error) { + var err error + var v interface{} + read := func(f *float32) { + if err != nil { + return + } + v, err = t.elem.read(r) + *f = v.(float32) + } + var out vector + read(&out.x) + read(&out.y) + read(&out.z) + return out, err +}