From b2e89f84ec4f2088b2ff1d674e614ccd3e0e3e0a Mon Sep 17 00:00:00 2001 From: Markus Walther Date: Sat, 11 Apr 2020 10:50:13 +0100 Subject: [PATCH] add angleY, rename angle to angleX (breaking change) see #24 --- README.md | 2 +- csminify.go | 3 +- examples/minimal.json | 268 +++++----- examples/minimal.mp | Bin 4576 -> 4717 bytes examples/minimal.pb | Bin 1815 -> 1848 bytes protobuf/gen/proto/replay.proto | 3 +- protobuf/gen/replay.pb.go | 713 ++++++++++++++----------- protobuf/marshal.go | 3 +- protobuf/unmarshal.go | 3 +- replay/nondefault/nondefault_replay.go | 3 +- replay/replay.go | 3 +- schema.json | 5 +- 12 files changed, 550 insertions(+), 456 deletions(-) diff --git a/README.md b/README.md index 7bf98fa..bef2c8f 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ To run tests [Git LFS](https://git-lfs.github.com) is required. ```sh git submodule init git submodule update -pushd test/cs-demos && git lfs pull && popd +pushd test/cs-demos && git lfs pull -I '*' && popd go test ./... ``` diff --git a/csminify.go b/csminify.go index d76d9ed..35810bf 100644 --- a/csminify.go +++ b/csminify.go @@ -159,7 +159,8 @@ func (m *minifier) snapshot() rep.Snapshot { Armor: pl.Armor, FlashDuration: float32(roundTo(float64(pl.FlashDuration), 0.1)), // Round to nearest 0.1 sec - saves space in JSON Positions: []rep.Point{r3VectorToPoint(pl.Position)}, - Angle: int(pl.ViewDirectionX), + AngleX: int(pl.ViewDirectionX), + AngleY: int(pl.ViewDirectionY), } // FIXME: Smoothify Positions diff --git a/examples/minimal.json b/examples/minimal.json index bec4592..aa65f27 100644 --- a/examples/minimal.json +++ b/examples/minimal.json @@ -5,21 +5,6 @@ "snapshotRate": 51 }, "entities": [ - { - "id": 8, - "name": "eswc.com | Samy", - "team": 1 - }, - { - "id": 12, - "name": "Ptikrazy", - "team": 1 - }, - { - "id": 13, - "name": "keev", - "team": 3 - }, { "id": 2, "name": "xms*ASUS ♥ /F/", @@ -30,11 +15,6 @@ "name": "to1nou * Seagate", "team": 2 }, - { - "id": 4, - "name": "tiziaN", - "team": 3 - }, { "id": 5, "name": "ALEX * Intel", @@ -46,10 +26,9 @@ "team": 2 }, { - "id": 1, - "name": "ESWC TV - By VeryGames.net", - "team": 0, - "isNpc": true + "id": 8, + "name": "eswc.com | Samy", + "team": 1 }, { "id": 9, @@ -61,14 +40,35 @@ "name": "syrsoNR", "team": 3 }, + { + "id": 1, + "name": "ESWC TV - By VeryGames.net", + "team": 0, + "isNpc": true + }, + { + "id": 12, + "name": "Ptikrazy", + "team": 1 + }, + { + "id": 13, + "name": "keev", + "team": 3 + }, + { + "id": 14, + "name": "kzy LJ∼", + "team": 3 + }, { "id": 11, "name": "mistou * Cooler Master", "team": 2 }, { - "id": 14, - "name": "kzy LJ∼", + "id": 4, + "name": "tiziaN", "team": 3 }, { @@ -90,33 +90,22 @@ "z": 1613 } ], - "angle": 182, - "hp": 100 - }, - { - "entityId": 13, - "positions": [ - { - "x": -1572, - "y": 722, - "z": 1614 - } - ], - "angle": 270, + "angleX": 182, "hp": 100 }, { - "entityId": 3, + "entityId": 2, "positions": [ { - "x": 555, - "y": 186, - "z": 1613 + "x": 513, + "y": -85, + "z": 1744 } ], - "angle": 187, - "hp": 100, - "armor": 100 + "angleX": 170, + "angleY": 4, + "hp": 24, + "armor": 83 }, { "entityId": 14, @@ -127,22 +116,11 @@ "z": 1636 } ], - "angle": 86, + "angleX": 86, + "angleY": 8, "hp": 8, "armor": 86 }, - { - "entityId": 4, - "positions": [ - { - "x": -817, - "y": -451, - "z": 1614 - } - ], - "angle": 92, - "hp": 97 - }, { "entityId": 5, "positions": [ @@ -152,34 +130,36 @@ "z": 1613 } ], - "angle": 195, + "angleX": 195, + "angleY": 357, "hp": 11, "armor": 86 }, { - "entityId": 2, + "entityId": 10, "positions": [ { - "x": 513, - "y": -85, - "z": 1744 + "x": -1382, + "y": 815, + "z": 1614 } ], - "angle": 170, - "hp": 24, - "armor": 83 + "angleX": 270, + "hp": 100 }, { - "entityId": 10, + "entityId": 3, "positions": [ { - "x": -1382, - "y": 815, - "z": 1614 + "x": 555, + "y": 186, + "z": 1613 } ], - "angle": 270, - "hp": 100 + "angleX": 187, + "angleY": 357, + "hp": 100, + "armor": 100 }, { "entityId": 11, @@ -190,9 +170,36 @@ "z": 1748 } ], - "angle": 195, + "angleX": 195, + "angleY": 6, "hp": 16, "armor": 98 + }, + { + "entityId": 13, + "positions": [ + { + "x": -1572, + "y": 722, + "z": 1614 + } + ], + "angleX": 270, + "angleY": 359, + "hp": 100 + }, + { + "entityId": 4, + "positions": [ + { + "x": -817, + "y": -451, + "z": 1614 + } + ], + "angleX": 92, + "angleY": 12, + "hp": 97 } ] }, @@ -200,55 +207,59 @@ "tick": 102, "entityUpdates": [ { - "entityId": 3, + "entityId": 2, "positions": [ { - "x": 374, - "y": 167, - "z": 1613 + "x": 336, + "y": -127, + "z": 1790 } ], - "angle": 150, - "hp": 100, - "armor": 100 + "angleX": 163, + "angleY": 8, + "hp": 24, + "armor": 83 }, { - "entityId": 4, + "entityId": 14, "positions": [ { - "x": -840, - "y": 37, - "z": 1614 + "x": -825, + "y": 606, + "z": 1636 } ], - "angle": 87, - "hp": 97 + "angleX": 86, + "angleY": 8, + "hp": 8, + "armor": 86 }, { - "entityId": 5, + "entityId": 3, "positions": [ { - "x": -29, - "y": 368, + "x": 374, + "y": 167, "z": 1613 } ], - "angle": 101, - "hp": 11, - "armor": 86 + "angleX": 150, + "hp": 100, + "armor": 100 }, { - "entityId": 2, + "entityId": 5, "positions": [ { - "x": 336, - "y": -127, - "z": 1790 + "x": -29, + "y": 368, + "z": 1613 } ], - "angle": 163, - "hp": 24, - "armor": 83 + "angleX": 101, + "angleY": 353, + "hp": 11, + "armor": 86 }, { "entityId": 9, @@ -259,46 +270,46 @@ "z": 1614 } ], - "angle": 281, + "angleX": 281, + "angleY": 2, "hp": 100 }, { - "entityId": 10, + "entityId": 4, "positions": [ { - "x": -1382, - "y": 815, + "x": -840, + "y": 37, "z": 1614 } ], - "angle": 270, - "hp": 100 + "angleX": 87, + "angleY": 11, + "hp": 97 }, { - "entityId": 11, + "entityId": 7, "positions": [ { - "x": 112, - "y": -366, - "z": 1614 + "x": 2973, + "y": 250, + "z": 1613 } ], - "angle": 201, - "hp": 16, - "armor": 98 + "angleX": 182, + "hp": 100 }, { - "entityId": 14, + "entityId": 10, "positions": [ { - "x": -825, - "y": 606, - "z": 1636 + "x": -1382, + "y": 815, + "z": 1614 } ], - "angle": 86, - "hp": 8, - "armor": 86 + "angleX": 270, + "hp": 100 }, { "entityId": 13, @@ -309,20 +320,23 @@ "z": 1614 } ], - "angle": 270, + "angleX": 270, + "angleY": 359, "hp": 100 }, { - "entityId": 7, + "entityId": 11, "positions": [ { - "x": 2973, - "y": 250, - "z": 1613 + "x": 112, + "y": -366, + "z": 1614 } ], - "angle": 182, - "hp": 100 + "angleX": 201, + "angleY": 1, + "hp": 16, + "armor": 98 } ] } diff --git a/examples/minimal.mp b/examples/minimal.mp index b6661a8081a78f426472c6a326eb3b7fdd165dc4..7acc446f94d5757070004d1df59be139bf6641d0 100644 GIT binary patch delta 643 zcmaE${8nXx%fv}e6JJ|TbWoWb!>B!3jnQmkir(Z+j8c=k8Pz9V5ubd9F^O+kVqSVq zYQ&jsi!usQ+9uCqk(`{s%qjYU-)YQR}WsLvvqKqi5FBPF|IVWlc4 z`23)X!lCAH1C=CBzRRl03zdMxIhKgPA7-F%SB6FZnUhe{8G)w5!hACy+a+!Q0{sL+ delta 482 zcmaE>@<4fl%fzD!lie8gCb~FH-pVLGvCVq20HfK&r`nUd7_}#tFiK56!MHvMtEtBQgRQVtxXBqiGLamccnN>ufigtrUmL?YE<`)4aYME4pArfIgaSn)h zSj*%FRw?oG3o9@Fvt3wqmdy{MBnGG?v32r3Cb(gTfg;>cO|6q{m{g#KommBxkbp=8 zPhwU>cTWtP#N-LgyfD=uV+0_olO`Loh)q7pq6%~GG@u;Jy&!if^FSOE4ipDFMq;uw zD>u}nRG=WTdnDx<0~S_ZXasrUA2a|K1J%Hs)-u_JRTUb1XBj0yR$+CmGR!q6fl6R5 c#T|OU7=RlJj)BRXOsY_KLt<(3Y_?0>0FZpb+W-In diff --git a/examples/minimal.pb b/examples/minimal.pb index d6417408a23f1be842a9dfbdf3b690471d41a85b..ac63e18a76017a33375bc1b79c472853789038cf 100644 GIT binary patch delta 542 zcmbQvw}Wqj#6)j{iJiJ)q8uDT{Hev|$$H88xe7H3!HKz*63i2?%T3&-G*Ms1il2i| zh%>vYQo+aTQO6z$CLtLPZXvPU%;J*#QUxsq=luMf)FK7n#Nv|FA_+zz9u5{Ewvx=M z%tXJ*ii{Fc?MxiTLP8wuLYy3P#RYybN}T19*v6=kA|yBYHlvJ{2aAv_&;mh@<3ImH z0HeS?7KtZ35@8A)8etwBLgE~(K)s8Y1zv*n9%fYF28usrn!J}uwqBfr87R4$MPL_L zayQUmjTE4ykQ~sFf*ccB1ls<=%$2ypD*@CkppoRk2DFqHD1YZOOj6(ytHe1Ti9RNU z6p!ajLdrm2NOGJ~@qAonu~Nlo@+l3?=So@~n~KKTHXlmY?o%1*w`B+cZ(xY?Qc3NrxU1H6F% delta 335 zcmdnNH=S>SgqSD?hY){iae1;{a(=EtjY4o@ZlwhC#8a{pB@B3ZI9P<(N;0c56a6HZ zCc5iQT&Xm%M|R>5IX-?4J|WKRs!9bPuSXqwCMz;ZNPT1EFcuQxU>D-#m@6*ui&5e% zkHj`cg%lyFNla1_LLwZ@K$+Dn0=vL6yMZzqDMHedGnu5BgcK*sGbx$?)vyB9EMgXT z308BMQGr_{Oh|@` 0 { - for _, msg := range m.Entities { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + if len(m.Ticks) > 0 { + for iNdEx := len(m.Ticks) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Ticks[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) } - i += n + i-- + dAtA[i] = 0x22 } } if len(m.Snapshots) > 0 { - for _, msg := range m.Snapshots { + for iNdEx := len(m.Snapshots) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Snapshots[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0x1a - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + } + } + if len(m.Entities) > 0 { + for iNdEx := len(m.Entities) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Entities[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) } - i += n + i-- + dAtA[i] = 0x12 } } - if len(m.Ticks) > 0 { - for _, msg := range m.Ticks { - dAtA[i] = 0x22 - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } - i += n + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func (m *Replay_Header) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -903,34 +931,40 @@ func (m *Replay_Header) Marshal() (dAtA []byte, err error) { } func (m *Replay_Header) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if len(m.Map) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintReplay(dAtA, i, uint64(len(m.Map))) - i += copy(dAtA[i:], m.Map) + if m.SnapshotRate != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.SnapshotRate)) + i-- + dAtA[i] = 0x18 } if m.TickRate != 0 { - dAtA[i] = 0x11 - i++ + i -= 8 encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.TickRate)))) - i += 8 + i-- + dAtA[i] = 0x11 } - if m.SnapshotRate != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.SnapshotRate)) + if len(m.Map) > 0 { + i -= len(m.Map) + copy(dAtA[i:], m.Map) + i = encodeVarintReplay(dAtA, i, uint64(len(m.Map))) + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func (m *Replay_Entity) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -938,43 +972,49 @@ func (m *Replay_Entity) Marshal() (dAtA []byte, err error) { } func (m *Replay_Entity) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Entity) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Id != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Id)) - } - if len(m.Name) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(len(m.Name))) - i += copy(dAtA[i:], m.Name) - } - if m.Team != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Team)) - } if m.IsNpc { - dAtA[i] = 0x20 - i++ + i-- if m.IsNpc { dAtA[i] = 1 } else { dAtA[i] = 0 } - i++ + i-- + dAtA[i] = 0x20 } - return i, nil + if m.Team != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Team)) + i-- + dAtA[i] = 0x18 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintReplay(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.Id != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Replay_Snapshot) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -982,34 +1022,41 @@ func (m *Replay_Snapshot) Marshal() (dAtA []byte, err error) { } func (m *Replay_Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Tick != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Tick)) - } if len(m.EntityUpdates) > 0 { - for _, msg := range m.EntityUpdates { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + for iNdEx := len(m.EntityUpdates) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.EntityUpdates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) } - i += n + i-- + dAtA[i] = 0x12 } } - return i, nil + if m.Tick != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Tick)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Replay_Snapshot_EntityUpdate) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -1017,70 +1064,82 @@ func (m *Replay_Snapshot_EntityUpdate) Marshal() (dAtA []byte, err error) { } func (m *Replay_Snapshot_EntityUpdate) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Snapshot_EntityUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.EntityId != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.EntityId)) + if m.AngleY != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.AngleY)) + i-- + dAtA[i] = 0x48 } - if len(m.Positions) > 0 { - for _, msg := range m.Positions { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n + if m.IsNpc { + i-- + if m.IsNpc { + dAtA[i] = 1 + } else { + dAtA[i] = 0 } + i-- + dAtA[i] = 0x40 } - if m.Angle != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Angle)) + if m.Team != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Team)) + i-- + dAtA[i] = 0x38 } - if m.Hp != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Hp)) + if m.FlashDuration != 0 { + i -= 4 + encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(m.FlashDuration)))) + i-- + dAtA[i] = 0x35 } if m.Armor != 0 { - dAtA[i] = 0x28 - i++ i = encodeVarintReplay(dAtA, i, uint64(m.Armor)) + i-- + dAtA[i] = 0x28 } - if m.FlashDuration != 0 { - dAtA[i] = 0x35 - i++ - encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(m.FlashDuration)))) - i += 4 + if m.Hp != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Hp)) + i-- + dAtA[i] = 0x20 } - if m.Team != 0 { - dAtA[i] = 0x38 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Team)) + if m.AngleX != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.AngleX)) + i-- + dAtA[i] = 0x18 } - if m.IsNpc { - dAtA[i] = 0x40 - i++ - if m.IsNpc { - dAtA[i] = 1 - } else { - dAtA[i] = 0 + if len(m.Positions) > 0 { + for iNdEx := len(m.Positions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Positions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - i++ } - return i, nil + if m.EntityId != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.EntityId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Replay_Tick) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -1088,34 +1147,41 @@ func (m *Replay_Tick) Marshal() (dAtA []byte, err error) { } func (m *Replay_Tick) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Tick) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Nr != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Nr)) - } if len(m.Events) > 0 { - for _, msg := range m.Events { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Events[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) } - i += n + i-- + dAtA[i] = 0x12 } } - return i, nil + if m.Nr != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Nr)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Replay_Tick_Event) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -1123,34 +1189,41 @@ func (m *Replay_Tick_Event) Marshal() (dAtA []byte, err error) { } func (m *Replay_Tick_Event) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Tick_Event) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Kind != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Kind)) - } if len(m.Attributes) > 0 { - for _, msg := range m.Attributes { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + for iNdEx := len(m.Attributes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Attributes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReplay(dAtA, i, uint64(size)) } - i += n + i-- + dAtA[i] = 0x12 } } - return i, nil + if m.Kind != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Kind)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Replay_Tick_Event_Attribute) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -1158,44 +1231,53 @@ func (m *Replay_Tick_Event_Attribute) Marshal() (dAtA []byte, err error) { } func (m *Replay_Tick_Event_Attribute) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Replay_Tick_Event_Attribute) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Kind != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintReplay(dAtA, i, uint64(m.Kind)) - } - if len(m.StringValue) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintReplay(dAtA, i, uint64(len(m.StringValue))) - i += copy(dAtA[i:], m.StringValue) + if len(m.CustomName) > 0 { + i -= len(m.CustomName) + copy(dAtA[i:], m.CustomName) + i = encodeVarintReplay(dAtA, i, uint64(len(m.CustomName))) + i-- + dAtA[i] = 0x22 } if m.NumberValue != 0 { - dAtA[i] = 0x19 - i++ + i -= 8 encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.NumberValue)))) - i += 8 + i-- + dAtA[i] = 0x19 } - if len(m.CustomName) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintReplay(dAtA, i, uint64(len(m.CustomName))) - i += copy(dAtA[i:], m.CustomName) + if len(m.StringValue) > 0 { + i -= len(m.StringValue) + copy(dAtA[i:], m.StringValue) + i = encodeVarintReplay(dAtA, i, uint64(len(m.StringValue))) + i-- + dAtA[i] = 0x12 } - return i, nil + if m.Kind != 0 { + i = encodeVarintReplay(dAtA, i, uint64(m.Kind)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func encodeVarintReplay(dAtA []byte, offset int, v uint64) int { + offset -= sovReplay(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Point) Size() (n int) { if m == nil { @@ -1320,8 +1402,8 @@ func (m *Replay_Snapshot_EntityUpdate) Size() (n int) { n += 1 + l + sovReplay(uint64(l)) } } - if m.Angle != 0 { - n += 1 + sovReplay(uint64(m.Angle)) + if m.AngleX != 0 { + n += 1 + sovReplay(uint64(m.AngleX)) } if m.Hp != 0 { n += 1 + sovReplay(uint64(m.Hp)) @@ -1338,6 +1420,9 @@ func (m *Replay_Snapshot_EntityUpdate) Size() (n int) { if m.IsNpc { n += 2 } + if m.AngleY != 0 { + n += 1 + sovReplay(uint64(m.AngleY)) + } return n } @@ -1401,14 +1486,7 @@ func (m *Replay_Tick_Event_Attribute) Size() (n int) { } func sovReplay(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozReplay(x uint64) (n int) { return sovReplay(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -2162,9 +2240,9 @@ func (m *Replay_Snapshot_EntityUpdate) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Angle", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AngleX", wireType) } - m.Angle = 0 + m.AngleX = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowReplay @@ -2174,7 +2252,7 @@ func (m *Replay_Snapshot_EntityUpdate) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Angle |= int32(b&0x7F) << shift + m.AngleX |= int32(b&0x7F) << shift if b < 0x80 { break } @@ -2267,6 +2345,25 @@ func (m *Replay_Snapshot_EntityUpdate) Unmarshal(dAtA []byte) error { } } m.IsNpc = bool(v != 0) + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AngleY", wireType) + } + m.AngleY = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReplay + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AngleY |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipReplay(dAtA[iNdEx:]) @@ -2653,6 +2750,7 @@ func (m *Replay_Tick_Event_Attribute) Unmarshal(dAtA []byte) error { func skipReplay(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -2684,10 +2782,8 @@ func skipReplay(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -2708,55 +2804,30 @@ func skipReplay(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthReplay } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthReplay - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowReplay - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipReplay(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthReplay - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupReplay + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthReplay + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthReplay = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowReplay = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthReplay = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowReplay = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupReplay = fmt.Errorf("proto: unexpected end of group") ) diff --git a/protobuf/marshal.go b/protobuf/marshal.go index 5c1bc42..0ddf0e5 100644 --- a/protobuf/marshal.go +++ b/protobuf/marshal.go @@ -73,7 +73,8 @@ func mapToEntityUpdates(entityUpdates []rep.EntityUpdate) []*gen.Replay_Snapshot result := make([]*gen.Replay_Snapshot_EntityUpdate, 0) for _, u := range entityUpdates { result = append(result, &gen.Replay_Snapshot_EntityUpdate{ - Angle: int32(u.Angle), + AngleX: int32(u.AngleX), + AngleY: int32(u.AngleY), Armor: int32(u.Armor), EntityId: int32(u.EntityID), FlashDuration: u.FlashDuration, diff --git a/protobuf/unmarshal.go b/protobuf/unmarshal.go index 2e7fb40..623a5e7 100644 --- a/protobuf/unmarshal.go +++ b/protobuf/unmarshal.go @@ -97,7 +97,8 @@ func mapFromEntityUpdates(entityUpdates []*gen.Replay_Snapshot_EntityUpdate) []r result := make([]rep.EntityUpdate, len(entityUpdates)) for i, u := range entityUpdates { result[i] = rep.EntityUpdate{ - Angle: int(u.Angle), + AngleX: int(u.AngleX), + AngleY: int(u.AngleY), Armor: int(u.Armor), EntityID: int(u.EntityId), FlashDuration: u.FlashDuration, diff --git a/replay/nondefault/nondefault_replay.go b/replay/nondefault/nondefault_replay.go index e41d567..4d20c5d 100644 --- a/replay/nondefault/nondefault_replay.go +++ b/replay/nondefault/nondefault_replay.go @@ -36,7 +36,8 @@ func init() { var entUpd []rep.EntityUpdate entUpd = append(entUpd, rep.EntityUpdate{ - Angle: 90, + AngleX: 90, + AngleY: 45, Armor: 80, EntityID: 5, FlashDuration: 2.35, diff --git a/replay/replay.go b/replay/replay.go index 8f6f18d..c9132af 100644 --- a/replay/replay.go +++ b/replay/replay.go @@ -62,7 +62,8 @@ type EntityUpdate struct { Team int `json:"team,omitempty" msgpack:"team,omitempty"` IsNpc bool `json:"isNpc,omitempty" msgpack:"isNpc,omitempty"` Positions []Point `json:"positions,omitempty" msgpack:"positions,omitempty"` // This allows us smoother replay with less overhead compared to higher snapshot rate - Angle int `json:"angle,omitempty" msgpack:"angle,omitempty"` + AngleX int `json:"angleX,omitempty" msgpack:"angleX,omitempty"` + AngleY int `json:"angleY,omitempty" msgpack:"angleY,omitempty"` Hp int `json:"hp,omitempty" msgpack:"hp,omitempty"` Armor int `json:"armor,omitempty" msgpack:"armor,omitempty"` FlashDuration float32 `json:"flashDuration,omitempty" msgpack:"flashDuration,omitempty"` diff --git a/schema.json b/schema.json index 58229d9..118f851 100644 --- a/schema.json +++ b/schema.json @@ -30,7 +30,10 @@ "entityId" ], "properties": { - "angle": { + "angleX": { + "type": "integer" + }, + "angleY": { "type": "integer" }, "armor": {