store net ids

types
Jordan Orelli 8 years ago
parent bc32e7ac5b
commit 6b2371a940

@ -5,19 +5,41 @@ import (
"github.com/jordanorelli/hyperstone/bit"
"github.com/jordanorelli/hyperstone/dota"
"github.com/jordanorelli/hyperstone/stbl"
)
type Env struct {
symbols symbolTable
source bit.BufReader
classes map[string]classHistory
netIds map[int]string
fields []field
strings *stbl.Dict
}
func NewEnv() *Env {
e := &Env{strings: stbl.NewDict()}
e.strings.WatchTable("instancebaseline", e.syncBaselineTable)
return e
}
func (e *Env) Handle(m proto.Message) error {
switch v := m.(type) {
case *dota.CSVCMsg_CreateStringTable:
_, err := e.strings.Create(v)
return err
case *dota.CSVCMsg_UpdateStringTable:
return e.strings.Update(v)
case *dota.CDemoSendTables:
return e.mergeSendTables(v)
if err := e.mergeSendTables(v); err != nil {
return err
}
e.syncBaseline()
case *dota.CDemoClassInfo:
e.mergeClassInfo(v)
}
return nil
}
@ -26,6 +48,9 @@ func (e *Env) setSource(buf []byte) {
e.source.SetSource(buf)
}
// merges the "sendTables" message. "sendTables" is a deeply misleading name,
// but it's the name the structure is given in the protobufs. sendTables
// contains the type definitions that define our entity type system.
func (e *Env) mergeSendTables(m *dota.CDemoSendTables) error {
Debug.Printf("merge send tables")
@ -88,4 +113,30 @@ func (e *Env) fillClasses(flat *dota.CSVCMsg_FlattenedSerializer) {
}
}
func (e *Env) mergeClassInfo(m *dota.CDemoClassInfo) {
if e.netIds == nil {
e.netIds = make(map[int]string, len(m.GetClasses()))
}
for _, info := range m.GetClasses() {
id := info.GetClassId()
name := info.GetNetworkName()
table := info.GetTableName()
Debug.Printf("class info id: %d name: %s table: %s", id, name, table)
e.netIds[int(id)] = name
}
}
func (e *Env) symbol(id int) string { return e.symbols[id] }
func (e *Env) syncBaseline() {
t := e.strings.TableForName("instancebaseline")
if t != nil {
e.syncBaselineTable(t)
}
}
func (e *Env) syncBaselineTable(t *stbl.Table) {
if e.classes == nil {
Debug.Printf("syncBaselines skipped: classes are nil")
}
}

@ -142,10 +142,8 @@ func main() {
handle = dumpClasses
case "entities":
ent.Debug = log.New(os.Stdout, "", 0)
sd := stbl.NewDict()
env := new(ent.Env)
env := ent.NewEnv()
handle = func(m proto.Message) {
sd.Handle(m)
if err := env.Handle(m); err != nil {
bail(1, "%v", err)
}

@ -61,7 +61,7 @@ func (t *Table) createEntries(br *bit.BufReader, n int) error {
}
}
}
return br.Err()
return nil
}
func (t *Table) updateEntries(br *bit.BufReader, n int) error {

Loading…
Cancel
Save