From 78b07284ca9fb551b413538b701cafa89b71cb2e Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 24 Sep 2016 21:21:57 -0400 Subject: [PATCH] typeSpec type ahhhhhh this feels good. --- ent/atoms.go | 6 ++---- ent/field.go | 2 +- ent/float.go | 34 +++++++++++++--------------------- ent/handle.go | 5 ++--- ent/hseq.go | 5 ++--- ent/qangle.go | 7 +++---- ent/type.go | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 68 insertions(+), 39 deletions(-) diff --git a/ent/atoms.go b/ent/atoms.go index c530a99..34417e9 100644 --- a/ent/atoms.go +++ b/ent/atoms.go @@ -2,7 +2,6 @@ package ent import ( "github.com/jordanorelli/hyperstone/bit" - "github.com/jordanorelli/hyperstone/dota" ) var atom_types = map[string]typeFn{ @@ -15,9 +14,8 @@ var atom_types = map[string]typeFn{ }, } -func atomType(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) tÿpe { - var_type := env.symbol(int(flat.GetVarTypeSym())) - if t, ok := atom_types[var_type]; ok { +func atomType(spec *typeSpec, env *Env) tÿpe { + if t, ok := atom_types[spec.typeName]; ok { Debug.Printf(" atom type") return t } diff --git a/ent/field.go b/ent/field.go index c9a7604..b2b7e8c 100644 --- a/ent/field.go +++ b/ent/field.go @@ -12,7 +12,7 @@ type field struct { func (f *field) fromProto(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) error { Debug.Printf("parse flat field: %s", prettyFlatField(flat, env)) - t := parseType(flat, env) + t := parseFieldType(flat, env) if t == nil { return fmt.Errorf("unable to parse type %s", prettyFlatField(flat, env)) } diff --git a/ent/float.go b/ent/float.go index 9a52b7a..1e4e579 100644 --- a/ent/float.go +++ b/ent/float.go @@ -4,7 +4,6 @@ import ( "math" "github.com/jordanorelli/hyperstone/bit" - "github.com/jordanorelli/hyperstone/dota" ) const ( @@ -13,42 +12,38 @@ const ( f_center ) -func floatType(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) tÿpe { - switch env.symbol(int(flat.GetVarTypeSym())) { +func floatType(spec *typeSpec, env *Env) tÿpe { + switch spec.typeName { case "CNetworkedQuantizedFloat": - return qFloatType(flat, env) + return qFloatType(spec, env) case "float32": default: return nil } - if env.symbol(int(flat.GetVarEncoderSym())) == "coord" { + if spec.encoder == "coord" { return nil } - if env.symbol(int(flat.GetFieldSerializerNameSym())) == "simulationtime" { + if spec.serializer == "simulationtime" { return nil } - switch flat.GetBitCount() { + switch spec.bits { case 0, 32: Debug.Printf(" std float type") return typeFn(float_t) default: - return qFloatType(flat, env) + return qFloatType(spec, env) } } -func qFloatType(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) tÿpe { - if flat.GetBitCount() < 0 { +func qFloatType(spec *typeSpec, env *Env) tÿpe { + if spec.bits < 0 { return typeError("quantized float has invalid negative bit count specifier") } - if flat.GetHighValue()-flat.GetLowValue() < 0 { + if spec.high-spec.low < 0 { return typeError("quantized float has invalid negative range") } - t := qfloat_t{ - bits: uint(flat.GetBitCount()), - low: flat.GetLowValue(), - high: flat.GetHighValue(), - flags: int(flat.GetEncodeFlags()) & 0x7, - } + + t := qfloat_t{typeSpec: *spec} t.span = t.high - t.low t.intervals = uint(1<