• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark / 13730551907

07 Mar 2025 10:34PM CUT coverage: 99.424% (+0.001%) from 99.423%
13730551907

push

github

web-flow
Component IDs of entities are returned immutable (#156)

13 of 13 new or added lines in 2 files covered. (100.0%)

6387 of 6424 relevant lines covered (99.42%)

27582.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/column.go
1
package ecs
2

3
import (
4
        "reflect"
5
        "unsafe"
6
)
7

8
// column storage for components in an archetype.
9
type column struct {
10
        data       reflect.Value  // data buffer
11
        pointer    unsafe.Pointer // pointer to the first element
12
        isRelation bool           // whether this column is for a relation component
13
        target     Entity         // target entity if for a relation component
14
        itemSize   uintptr        // memory size of items
15
}
16

17
// newColumn creates a new column for a given type and capacity.
18
func newColumn(tp reflect.Type, isRelation bool, target Entity, capacity uint32) column {
2,419✔
19
        // TODO: should be use a slice instead of an array here?
2,419✔
20
        data := reflect.New(reflect.ArrayOf(int(capacity), tp)).Elem()
2,419✔
21
        pointer := data.Addr().UnsafePointer()
2,419✔
22

2,419✔
23
        return column{
2,419✔
24
                data:       data,
2,419✔
25
                pointer:    pointer,
2,419✔
26
                itemSize:   sizeOf(tp),
2,419✔
27
                isRelation: isRelation,
2,419✔
28
                target:     target,
2,419✔
29
        }
2,419✔
30
}
2,419✔
31

32
// Get returns a pointer to the component at the given index.
33
func (c *column) Get(index uintptr) unsafe.Pointer {
4,906,495✔
34
        return unsafe.Add(c.pointer, index*c.itemSize)
4,906,495✔
35
}
4,906,495✔
36

37
func (c *column) SetLast(other *column, ownLen uint32, count uint32) {
532✔
38
        start := ownLen - count
532✔
39
        src := other.Get(0)
532✔
40
        dst := c.Get(uintptr(start))
532✔
41
        copyPtr(src, dst, c.itemSize*uintptr(count))
532✔
42
}
532✔
43

44
// Set overwrites the component at the given index.
45
func (c *column) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
987,711✔
46
        dst := c.Get(uintptr(index))
987,711✔
47
        if c.itemSize == 0 {
988,837✔
48
                return dst
1,126✔
49
        }
1,126✔
50

51
        copyPtr(comp, dst, uintptr(c.itemSize))
986,585✔
52
        return dst
986,585✔
53
}
54

55
// Zero resets the memory at the given index.
56
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
488,217✔
57
        if c.itemSize == 0 {
488,438✔
58
                return
221✔
59
        }
221✔
60
        dst := unsafe.Add(c.pointer, index*c.itemSize)
487,996✔
61
        copyPtr(zero, dst, uintptr(c.itemSize))
487,996✔
62
}
63

64
// Zero resets a block of storage in one buffer.
65
func (c *column) ZeroRange(start, len uint32, zero unsafe.Pointer) {
596✔
66
        size := uint32(c.itemSize)
596✔
67
        if size == 0 {
619✔
68
                return
23✔
69
        }
23✔
70
        var i uint32
573✔
71
        for i = 0; i < len; i++ {
7,866✔
72
                dst := unsafe.Add(c.pointer, (i+start)*size)
7,293✔
73
                copyPtr(zero, dst, c.itemSize)
7,293✔
74
        }
7,293✔
75
}
76

77
func (c *column) Reset(ownLen uint32, zero unsafe.Pointer) {
799✔
78
        if ownLen == 0 {
803✔
79
                return
4✔
80
        }
4✔
81
        if zero == nil {
986✔
82
                return
191✔
83
        }
191✔
84
        if ownLen <= 64 { // A coarse estimate where manually zeroing is faster
1,200✔
85
                c.ZeroRange(0, ownLen, zero)
596✔
86
        } else {
604✔
87
                c.data.SetZero()
8✔
88
        }
8✔
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc