-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
188 lines (162 loc) · 3.86 KB
/
Copy pathmodel.go
File metadata and controls
188 lines (162 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package animation
import (
"encoding/json"
"github.com/TeamNorCal/animation/model"
)
// List of channels in the portal - 1-8 are resonators, and 9-24 are tower windows
const (
_ model.OpcChannel = iota // OPC channels are 1 based, with 0 being broadcast
Reso1
Reso2
Reso3
Reso4
Reso5
Reso6
Reso7
Reso8
Level1_1 // 9
Level1_2
Level2_1
Level2_2
Level3_1
Level3_2
Level4_1
Level4_2
Level5_1
Level5_2
Level6_1
Level6_2
Level7_1
Level7_2
Level8_1
Level8_2
)
// Faction represents an Ingress fasction
type Faction int
const (
// NEU means Neutral
NEU Faction = iota
// ENL means Enlightened!
ENL
// RES means Resistance :(
RES
)
// Universe defines a universe from the perspective of the animation engine.
// It consists of an index in the array of returned frame data, and a size
type Universe struct {
Index int
Size int
}
// Universes defines universe data for the model. It's indexed by logical name,
// with values containing size of the universe and index into the array of
// frame data
var Universes map[string]Universe
// ResonatorStatus is the status of a resonator, you'll be surprised to hear
type ResonatorStatus struct {
Level int // Resonator level, 0-8
Health float32 // Resonator health, 0-100
}
func (msg *PortalStatus) deepCopy() (cpy *PortalStatus) {
cpy = &PortalStatus{}
byt, _ := json.Marshal(msg)
json.Unmarshal(byt, cpy)
return cpy
}
// PortalStatus encapsulates the status of the portal
type PortalStatus struct {
Faction Faction // Owning faction
Level float32 // Portal level, 0-8 (floating point, because average of resonator levels)
Health float32
Resonators []ResonatorStatus // Array of 8 resonators, level 0 (undeployed) - 8
}
type animCircBuf struct {
buf []Animation
head int
tail int
}
func newAnimCircBuf() animCircBuf {
return animCircBuf{
buf: make([]Animation, 5),
head: 0,
tail: 0,
}
}
func (cb *animCircBuf) enqueue(effect Animation) {
cb.buf[cb.tail] = effect
cb.tail = (cb.tail + 1) % len(cb.buf)
}
func (cb *animCircBuf) dequeue() Animation {
if cb.head == cb.tail {
return nil
}
ret := cb.buf[cb.head]
cb.buf[cb.head] = nil
cb.head = (cb.head + 1) % len(cb.buf)
return ret
}
func (cb *animCircBuf) clear() {
for cb.head != cb.tail {
cb.buf[cb.head] = nil
cb.head = (cb.head + 1) % len(cb.buf)
}
}
func (cb *animCircBuf) peek() Animation {
if cb.head == cb.tail {
return nil
}
return cb.buf[cb.head]
}
func (cb *animCircBuf) size() int {
bufLen := len(cb.buf)
return (cb.tail + bufLen - cb.head) % bufLen
}
type seqCircBuf struct {
buf []*Sequence
head int
tail int
}
func newSeqCircBuf() seqCircBuf {
return seqCircBuf{
buf: make([]*Sequence, 5),
head: 0,
tail: 0,
}
}
func (cb *seqCircBuf) enqueue(seq *Sequence) {
cb.buf[cb.tail] = seq
cb.tail = (cb.tail + 1) % len(cb.buf)
}
func (cb *seqCircBuf) dequeue() *Sequence {
if cb.head == cb.tail {
return nil
}
ret := cb.buf[cb.head]
cb.buf[cb.head] = nil
cb.head = (cb.head + 1) % len(cb.buf)
return ret
}
func (cb *seqCircBuf) clear() {
for cb.head != cb.tail {
cb.buf[cb.head] = nil
cb.head = (cb.head + 1) % len(cb.buf)
}
}
func (cb *seqCircBuf) peek() *Sequence {
if cb.head == cb.tail {
return nil
}
return cb.buf[cb.head]
}
func (cb *seqCircBuf) size() int {
bufLen := len(cb.buf)
return (cb.tail + bufLen - cb.head) % bufLen
}
// Portal encapsulates the animation status of the entire portal. This will probably be a singleton
// object, but the fields are encapsulated into a struct to allow for something different
type Portal struct {
currentStatus *PortalStatus // The cached current status of the portal
sr *SequenceRunner // SequenceRunner for portal portion
seqBuf seqCircBuf // Queue of sequences to run on SequenceRunner
resonators []animCircBuf // Animations for resonators
frameBuf []model.ChannelData // Frame buffers by universe
}