-
Notifications
You must be signed in to change notification settings - Fork 9
/
component_operate_task.go
91 lines (77 loc) · 1.21 KB
/
component_operate_task.go
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
package ecs
import (
"sync"
)
type opTask struct {
target Entity
com IComponent
op CollectionOperate
next *opTask
}
func (o *opTask) Reset() {
o.target = 0
o.com = nil
o.op = CollectionOperateNone
o.next = nil
}
type opTaskList struct {
len int
head *opTask
tail *opTask
}
func (o *opTaskList) Clone() *opTaskList {
clone := *o
return &clone
}
func (o *opTaskList) Len() int {
return o.len
}
func (o *opTaskList) Combine(list *opTaskList) {
if o.head == nil {
o.head = list.head
o.tail = list.tail
} else {
o.tail.next = list.head
o.tail = list.tail
}
o.len += list.len
}
func (o *opTaskList) Append(task *opTask) {
if o.head == nil {
o.head = task
o.tail = task
} else {
o.tail.next = task
o.tail = task
}
o.len++
}
func (o *opTaskList) Reset() {
o.len = 0
o.head = nil
o.tail = nil
}
var opTaskPool = newTaskPool()
type taskPool struct {
pool sync.Pool
}
func newTaskPool() *taskPool {
return &taskPool{
pool: sync.Pool{
New: func() interface{} {
return new(opTask)
},
},
}
}
func (p *taskPool) Get() *opTask {
v := p.pool.Get()
if v == nil {
return &opTask{}
}
return v.(*opTask)
}
func (p *taskPool) Put(t *opTask) {
t.Reset()
p.pool.Put(t)
}