by now i need logging and error handling

master
Jordan Orelli 8 years ago
parent 857483bffa
commit b9f254112a

@ -1,36 +1,45 @@
package ent
import (
"fmt"
"github.com/jordanorelli/hyperstone/bit"
)
type Context struct {
Namespace
*Namespace
entities map[int]Entity
}
func NewContext() *Context {
return &Context{entities: make(map[int]Entity)}
return &Context{Namespace: new(Namespace), entities: make(map[int]Entity)}
}
func (c *Context) CreateEntity(id int, r bit.Reader) {
func (c *Context) CreateEntity(id int, r bit.Reader) error {
classId := int(c.readClassId(r))
if len(c.Namespace.classes) == 0 {
return fmt.Errorf("unable to create entity %d: namespace has no classes", id)
}
r.ReadBits(17) // ???
classV := int(bit.ReadVarInt(r))
className := c.classIds[classId]
class := c.Class(className, classV)
if class == nil {
return fmt.Errorf("unable to create entity %d: no class found for class name %s, version %d", className, classV)
}
Debug.Printf("create entity id: %d classId: %d className: %v class: %v\n", id, classId, className, class)
e := class.New()
e.Read(r)
return nil
}
func (c *Context) UpdateEntity(id int, r bit.Reader) {
Debug.Printf("update entity id: %d\n", id)
}
func (c *Context) DeleteEntity(id int) {
Debug.Printf("delete entity id: %d\n", id)
}
func (c *Context) LeaveEntity(id int) {
Debug.Printf("leave entity id: %d\n", id)
}

@ -1,6 +1,8 @@
package ent
import (
"fmt"
"github.com/jordanorelli/hyperstone/bit"
)
@ -9,4 +11,5 @@ type Entity struct {
}
func (e *Entity) Read(br bit.Reader) {
fmt.Printf("Entity %v read\n", e)
}

@ -150,6 +150,7 @@ var hlist = nodeList{
lNode{"PushOneLeftDeltaNRightZero", 9, 560, func() {}},
lNode{"PushOneLeftDeltaOneRightZero", 7, 521, func() {}},
lNode{"PushOneLeftDeltaNRightNonZero", 10, 471, func() {}},
lNode{"PushNAndNonTopological", 26, 310, func() {}},
lNode{"PopAllButOnePlusNPack3Bits", 31, 300, func() {}},
lNode{"NonTopoPenultimatePlusOne", 37, 271, func() {}},
lNode{"PushOneLeftDeltaNRightNonZeroPack8Bits", 12, 251, func() {}},
@ -158,25 +159,27 @@ var hlist = nodeList{
lNode{"NonTopoComplex", 36, 76, func() {}},
lNode{"PushOneLeftDeltaZeroRightZero", 5, 35, func() {}},
lNode{"PushOneLeftDeltaZeroRightNonZero", 6, 3, func() {}},
lNode{"PopNAndNonTopographical", 35, 1, func() {}},
lNode{"PopNPlusN", 34, 0, func() {}},
lNode{"PopNPlusOne", 33, 0, func() {}},
lNode{"PopOnePlusN", 28, 0, func() {}},
lNode{"PopOnePlusOne", 27, 2, func() {}},
lNode{"PushNAndNonTopological", 26, 310, func() {}},
lNode{"PushN", 25, 0, func() {}},
lNode{"PushThreePack5LeftDeltaN", 24, 0, func() {}},
lNode{"PushThreeLeftDeltaN", 23, 0, func() {}},
lNode{"PushTwoPack5LeftDeltaN", 22, 0, func() {}},
lNode{"PushTwoLeftDeltaN", 21, 0, func() {}},
lNode{"PushThreePack5LeftDeltaOne", 20, 0, func() {}},
lNode{"PushThreeLeftDeltaOne", 19, 0, func() {}},
lNode{"PushTwoPack5LeftDeltaOne", 18, 0, func() {}},
lNode{"PushTwoLeftDeltaOne", 17, 0, func() {}},
lNode{"PushThreePack5LeftDeltaZero", 16, 0, func() {}},
lNode{"PushThreeLeftDeltaZero", 15, 0, func() {}},
lNode{"PushTwoPack5LeftDeltaZero", 14, 0, func() {}},
lNode{"PushTwoLeftDeltaZero", 13, 0, func() {}},
lNode{"PopNAndNonTopographical", 35, 1, func() {}},
// all the other operations have weights of 0 in clarity, which makes no
// sense.
lNode{"PopNPlusN", 34, 1, func() {}},
lNode{"PopNPlusOne", 33, 1, func() {}},
lNode{"PopOnePlusN", 28, 1, func() {}},
lNode{"PushN", 25, 1, func() {}},
lNode{"PushThreePack5LeftDeltaN", 24, 1, func() {}},
lNode{"PushThreeLeftDeltaN", 23, 1, func() {}},
lNode{"PushTwoPack5LeftDeltaN", 22, 1, func() {}},
lNode{"PushTwoLeftDeltaN", 21, 1, func() {}},
lNode{"PushThreePack5LeftDeltaOne", 20, 1, func() {}},
lNode{"PushThreeLeftDeltaOne", 19, 1, func() {}},
lNode{"PushTwoPack5LeftDeltaOne", 18, 1, func() {}},
lNode{"PushTwoLeftDeltaOne", 17, 1, func() {}},
lNode{"PushThreePack5LeftDeltaZero", 16, 1, func() {}},
lNode{"PushThreeLeftDeltaZero", 15, 1, func() {}},
lNode{"PushTwoPack5LeftDeltaZero", 14, 1, func() {}},
lNode{"PushTwoLeftDeltaZero", 13, 1, func() {}},
}
var htree = makeTree(hlist)

@ -0,0 +1,12 @@
package ent
import (
"io/ioutil"
"log"
"os"
)
var (
Debug = log.New(ioutil.Discard, "DEBUG ent: ", 0)
Info = log.New(os.Stdout, "INFO end: ", 0)
)

@ -69,6 +69,7 @@ func (n *Namespace) MergeSendTables(st *dota.CDemoSendTables) {
class.fromProto(c, fields)
name := n.Symbol(int(c.GetSerializerNameSym()))
class.Name = name
version := int(c.GetSerializerVersion())
id := classId{name: name, version: version}
n.classes[id] = &class

@ -21,9 +21,9 @@ import (
// MaxSpawngroupCreationsequence *uint32
// }
func dumpEntities(m proto.Message) {
ctx := ent.NewContext()
var ctx = ent.NewContext()
func dumpEntities(m proto.Message) {
switch v := m.(type) {
case *dota.CDemoSendTables:
ctx.MergeSendTables(v)
@ -33,14 +33,18 @@ func dumpEntities(m proto.Message) {
case *dota.CSVCMsg_PacketEntities:
data := v.GetEntityData()
var datap []byte
if len(data) > 32 {
data = data[:32]
datap = data[:32]
} else {
datap = data
}
fmt.Printf("{MaxEntries: %d UpdatedEntries: %v IsDelta: %t UpdateBaseline: %t Baseline: %d DeltaFrom: %d EntityData: %x PendingFullFrame: %t ActiveSpawngroupHandle: %d}\n", v.GetMaxEntries(), v.GetUpdatedEntries(), v.GetIsDelta(), v.GetUpdateBaseline(), v.GetBaseline(), v.GetDeltaFrom(), data, v.GetPendingFullFrame(), v.GetActiveSpawngroupHandle())
fmt.Printf("{MaxEntries: %d UpdatedEntries: %v IsDelta: %t UpdateBaseline: %t Baseline: %d DeltaFrom: %d EntityData: %x PendingFullFrame: %t ActiveSpawngroupHandle: %d}\n", v.GetMaxEntries(), v.GetUpdatedEntries(), v.GetIsDelta(), v.GetUpdateBaseline(), v.GetBaseline(), v.GetDeltaFrom(), datap, v.GetPendingFullFrame(), v.GetActiveSpawngroupHandle())
br := bit.NewBytesReader(data)
id := -1
for i := 0; i < int(v.GetUpdatedEntries()); i++ {
// for i := 0; i < int(v.GetUpdatedEntries()); i++ {
for i := 0; i < 1; i++ {
id++
// there may be a jump indicator, indicating how many id positions
// to skip.

@ -14,6 +14,8 @@ import (
"strings"
"github.com/golang/protobuf/proto"
"github.com/jordanorelli/hyperstone/ent"
)
const (
@ -116,6 +118,10 @@ func main() {
flag.StringVar(&opts.cpuprofile, "cpuprofile", "", "cpu profile destination")
flag.Parse()
if opts.v {
ent.Debug.SetOutput(os.Stdout)
}
var handle func(proto.Message)
switch flag.Arg(0) {
case "":

Loading…
Cancel
Save