re-use selectionReader

master
Jordan Orelli 8 years ago
parent 372d236fe7
commit dbc7bf36c3

@ -38,6 +38,7 @@ type Dict struct {
*Namespace
entities []Entity
br *bit.BufReader
sr *selectionReader
// a reference to our string table of entity baseline data. For whatever
// reason, the first set of baselines sometimes come in before the classes
@ -50,6 +51,7 @@ func NewDict(sd *stbl.Dict) *Dict {
Namespace: new(Namespace),
entities: make([]Entity, e_limit),
br: new(bit.BufReader),
sr: new(selectionReader),
base: sd.TableForName("instancebaseline"),
}
sd.WatchTable("instancebaseline", d.updateBaselines)
@ -72,7 +74,7 @@ func (d *Dict) createEntity(id int) error {
}
Debug.Printf("create entity id: %d classId: %d className: %v class: %v\n", id, classId, className, class)
e := class.New()
e.Read(d.br)
e.Read(d.br, d.sr)
return nil
}
@ -90,7 +92,7 @@ func (d *Dict) updateEntity(id int) error {
if e == nil {
return fmt.Errorf("update entity %d refused: no such entity", id)
}
e.Read(d.br)
e.Read(d.br, d.sr)
return nil
}
@ -198,7 +200,7 @@ func (d *Dict) syncBaselines() {
d.br.SetSource(e.Value)
Debug.Printf("syncBaselines has new baseline for class %v", c)
if err := c.baseline.Read(d.br); err != nil {
if err := c.baseline.Read(d.br, d.sr); err != nil {
Debug.Printf("syncBaselines failed to read a baseline: %v", err)
continue
}

@ -10,18 +10,17 @@ type Entity struct {
*Class
}
func (e *Entity) Read(br bit.Reader) error {
func (e *Entity) Read(br bit.Reader, sr *selectionReader) error {
if e.Class == nil {
return fmt.Errorf("unable to read entity: entity has no class")
}
Debug.Printf("entity %v read", e)
r := newSelectionReader()
if err := r.read(br, htree); err != nil {
if err := sr.read(br, htree); err != nil {
return fmt.Errorf("unable to read entity: %v", err)
}
for _, s := range r.selections() {
for _, s := range sr.selections() {
switch s.count {
case 0:
Debug.Printf("FUCK!")

@ -33,14 +33,10 @@ type selectionReader struct {
all [1024]selection
}
func newSelectionReader() *selectionReader {
r := new(selectionReader)
func (r *selectionReader) read(br bit.Reader, n node) error {
r.cur.count = 1
r.cur.vals[0] = -1
return r
}
func (r *selectionReader) read(br bit.Reader, n node) error {
r.count = 0
for fn := walk(n, br); fn != nil; fn = walk(n, br) {
if err := br.Err(); err != nil {
return fmt.Errorf("unable to read selection: bit reader error: %v", err)

Loading…
Cancel
Save