From 75c3ac466b52f3de29eb20006867fe74cdc90ca3 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 29 Sep 2016 11:18:52 -0400 Subject: [PATCH] we got a mem overflow now --- ent/array.go | 5 ++++- ent/atoms.go | 2 +- ent/class.go | 12 ++---------- ent/entity.go | 23 +++++++++-------------- ent/env.go | 16 +++++++++++++--- ent/generic.go | 9 ++++++--- ent/handle.go | 2 +- ent/huff.go | 3 ++- ent/selection.go | 4 ++-- ent/vector.go | 2 +- 10 files changed, 41 insertions(+), 37 deletions(-) diff --git a/ent/array.go b/ent/array.go index 9e332cb..1d6684a 100644 --- a/ent/array.go +++ b/ent/array.go @@ -72,5 +72,8 @@ func (a array) read(r bit.Reader) error { } func (a array) String() string { - return fmt.Sprintf("%s%v", a.t.typeName(), a.slots) + if len(a.slots) > 8 { + return fmt.Sprintf("%s(%d)%v...", a.t.typeName(), len(a.slots), a.slots[:8]) + } + return fmt.Sprintf("%s(%d)%v", a.t.typeName(), len(a.slots), a.slots) } diff --git a/ent/atoms.go b/ent/atoms.go index 2eaf83f..c5ec09e 100644 --- a/ent/atoms.go +++ b/ent/atoms.go @@ -111,7 +111,7 @@ func (v *uint32_v) read(r bit.Reader) error { } func (v uint32_v) String() string { - return strconv.FormatUint(uint64(v), 0) + return strconv.FormatUint(uint64(v), 10) } // ------------------------------------------------------------------------------ diff --git a/ent/class.go b/ent/class.go index 6ac14fc..201ccf9 100644 --- a/ent/class.go +++ b/ent/class.go @@ -2,7 +2,6 @@ package ent import ( "fmt" - "github.com/jordanorelli/hyperstone/bit" ) type class struct { @@ -11,17 +10,10 @@ type class struct { fields []field } -func (c class) String() string { - return fmt.Sprintf("<%s.%d>", c.name, c.version) -} +func (c class) String() string { return c.typeName() } func (c class) typeName() string { - return fmt.Sprintf("class:%s", c.name) -} - -func (c *class) read(r bit.Reader) (value, error) { - bit.ReadBool(r) // ??? - return c.nü(), nil + return fmt.Sprintf("%s.%d", c.name, c.version) } func (c *class) nü() value { diff --git a/ent/entity.go b/ent/entity.go index d93ea20..a4142dc 100644 --- a/ent/entity.go +++ b/ent/entity.go @@ -11,17 +11,7 @@ type entity struct { } func (e *entity) read(r bit.Reader) error { - Debug.Printf("entity %s read", e.className()) - sr := new(selectionReader) - selections, err := sr.readSelections(r, htree) - if err != nil { - return wrap(err, "entity of type %s failed to read selections", e.className()) - } - for _, s := range selections { - if err := s.fillSlots(e, r); err != nil { - return err - } - } + bit.ReadBool(r) // ??? return nil } @@ -33,11 +23,16 @@ func (e *entity) className() string { } func (e *entity) String() string { - return fmt.Sprintf("%s{%v}", e.class.typeName(), e.slots) + return fmt.Sprintf("%s{id: ?}", e.class.typeName()) } -func (e *entity) tÿpe() tÿpe { return e.class } -func (e *entity) slotType(i int) tÿpe { return e.class.fields[i].tÿpe } +func (e *entity) tÿpe() tÿpe { return e.class } +func (e *entity) slotType(i int) tÿpe { + if i >= len(e.class.fields) { + return typeError("index out of range in slotType: %d is beyond capacity %d", i, len(e.class.fields)) + } + return e.class.fields[i].tÿpe +} func (e *entity) slotName(i int) string { return e.class.fields[i].name } func (e *entity) setSlotValue(i int, v value) { e.slots[i] = v } func (e *entity) getSlotValue(i int) value { return e.slots[i] } diff --git a/ent/env.go b/ent/env.go index 180fd30..676120b 100644 --- a/ent/env.go +++ b/ent/env.go @@ -113,6 +113,7 @@ func (e *Env) fillClasses(flat *dota.CSVCMsg_FlattenedSerializer) { class.fields = make([]field, len(s.GetFieldsIndex())) for i, id := range s.GetFieldsIndex() { + Debug.Printf("class %s has field %s (%s)", name, e.fields[id].name, e.fields[id].typeName()) class.fields[i] = e.fields[id] } } @@ -149,6 +150,7 @@ func (e *Env) syncBaselineTable(t *stbl.Table) { } r := new(bit.BufReader) + sr := new(selectionReader) for _, entry := range t.Entries() { netId, err := strconv.Atoi(entry.Key) if err != nil { @@ -166,10 +168,18 @@ func (e *Env) syncBaselineTable(t *stbl.Table) { continue } Debug.Printf("syncBaselines key: %s className: %s", entry.Key, c.name) - ent := c.nü() + ent := c.nü().(*entity) r.SetSource(entry.Value) - if err := ent.read(r); err != nil { - Debug.Printf("syncBaselines failed to fill an entity: %v", err) + selections, err := sr.readSelections(r) + if err != nil { + Debug.Printf("unable to read selections for %s: %v", className, err) + continue + } + Debug.Printf("selections: %v", selections) + for _, s := range selections { + if err := s.fillSlots(ent, r); err != nil { + Debug.Printf("unable to fill slots for %s: %v", className, err) + } } } } diff --git a/ent/generic.go b/ent/generic.go index 9a44ff0..b1aa170 100644 --- a/ent/generic.go +++ b/ent/generic.go @@ -24,7 +24,7 @@ func genericType(spec *typeSpec, env *Env) tÿpe { switch genericName { case "CHandle", "CStrongHandle": - t := handle_t(spec.typeName) + t := handle_t(fmt.Sprintf("%s<%s>", genericName, spec.typeName)) return &t case "CUtlVector": return &cutl_vector_t{elem} @@ -76,7 +76,7 @@ func (t *cutl_vector_t) nü() value { } func (t cutl_vector_t) typeName() string { - return fmt.Sprintf("vector:%s", t.elem.typeName()) + return fmt.Sprintf("CUtlVector<%s>", t.elem.typeName()) } type cutl_vector struct { @@ -93,5 +93,8 @@ func (v *cutl_vector) read(r bit.Reader) error { } func (v cutl_vector) String() string { - return fmt.Sprintf("%s<%v>", v.t.typeName(), v.slots) + if len(v.slots) > 8 { + return fmt.Sprintf("%s(%d)%v...", v.t.typeName(), len(v.slots), v.slots[:8]) + } + return fmt.Sprintf("%s(%d)%v", v.t.typeName(), len(v.slots), v.slots) } diff --git a/ent/handle.go b/ent/handle.go index 3ea0f10..167a53a 100644 --- a/ent/handle.go +++ b/ent/handle.go @@ -25,7 +25,7 @@ func (h *handle) read(r bit.Reader) error { } func (h handle) String() string { - return fmt.Sprintf("handle<%s>: %d", h.t.typeName(), h.id) + return fmt.Sprintf("%s:%d", h.t.typeName(), h.id) } func handleType(spec *typeSpec, env *Env) tÿpe { diff --git a/ent/huff.go b/ent/huff.go index f64ee06..6d24ab6 100644 --- a/ent/huff.go +++ b/ent/huff.go @@ -134,6 +134,7 @@ var hlist = nodeList{ r.add(int(bit.ReadUBitVarFP(br)) + 5) }}, lNode{"PushOneLeftDeltaOneRightNonZero", 8, 2942, func(r *selectionReader, br bit.Reader) { + Debug.Printf("PushOneLeftDeltaOneRightNonZero") r.add(1) r.push(int(bit.ReadUBitVarFP(br))) }}, @@ -267,4 +268,4 @@ var hlist = nodeList{ }}, } -var htree = makeTree(hlist) +var huffRoot = makeTree(hlist) diff --git a/ent/selection.go b/ent/selection.go index 7f77eb6..594aa68 100644 --- a/ent/selection.go +++ b/ent/selection.go @@ -67,11 +67,11 @@ type selectionReader struct { all [1024]selection } -func (r *selectionReader) readSelections(br bit.Reader, n node) ([]selection, error) { +func (r *selectionReader) readSelections(br bit.Reader) ([]selection, error) { r.cur.count = 1 r.cur.vals[0] = -1 r.count = 0 - for fn := walk(n, br); fn != nil; fn = walk(n, br) { + for fn := walk(huffRoot, br); fn != nil; fn = walk(huffRoot, br) { if err := br.Err(); err != nil { return nil, fmt.Errorf("unable to read selection: bit reader error: %v", err) } diff --git a/ent/vector.go b/ent/vector.go index 37bfc5b..52b8964 100644 --- a/ent/vector.go +++ b/ent/vector.go @@ -24,7 +24,7 @@ type vector_t struct { } func (t vector_t) typeName() string { - return fmt.Sprintf("vector:%s", t.elem.typeName()) + return fmt.Sprintf("vector<%s>", t.elem.typeName()) } func (t *vector_t) nü() value {