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

mlange-42 / ark / 13932290840

18 Mar 2025 07:54PM CUT coverage: 99.831% (+0.05%) from 99.782%
13932290840

push

github

web-flow
Fix removing relationship components (#212)

It was not possible to remove relationship components, as Ark complained "relations must be fully specified".
Further, it is checked whether entities actually have the relation component to set a target for.

15 of 17 new or added lines in 3 files covered. (88.24%)

8258 of 8272 relevant lines covered (99.83%)

20520.71 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
        pointer    unsafe.Pointer // pointer to the first element
11
        data       reflect.Value  // data buffer
12
        itemSize   uintptr        // memory size of items
13
        target     Entity         // target entity if for a relation component
14
        index      uint32         // index of the column in the containing table
15
        isRelation bool           // whether this column is for a relation component
16
}
17

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

3,199✔
24
        return column{
3,199✔
25
                index:      index,
3,199✔
26
                data:       data,
3,199✔
27
                pointer:    pointer,
3,199✔
28
                itemSize:   itemSize,
3,199✔
29
                isRelation: isRelation,
3,199✔
30
                target:     target,
3,199✔
31
        }
3,199✔
32
}
3,199✔
33

34
// Get returns a pointer to the component at the given index.
35
func (c *column) Get(index uintptr) unsafe.Pointer {
5,145,376✔
36
        return unsafe.Add(c.pointer, index*c.itemSize)
5,145,376✔
37
}
5,145,376✔
38

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

46
// Set overwrites the component at the given index.
47
func (c *column) Set(index uint32, comp unsafe.Pointer) unsafe.Pointer {
509,215✔
48
        dst := c.Get(uintptr(index))
509,215✔
49
        if c.itemSize == 0 {
509,271✔
50
                return dst
56✔
51
        }
56✔
52

53
        copyPtr(comp, dst, uintptr(c.itemSize))
509,159✔
54
        return dst
509,159✔
55
}
56

57
// Zero resets the memory at the given index.
58
func (c *column) Zero(index uintptr, zero unsafe.Pointer) {
506,869✔
59
        if c.itemSize == 0 {
507,098✔
60
                return
229✔
61
        }
229✔
62
        dst := unsafe.Add(c.pointer, index*c.itemSize)
506,640✔
63
        copyPtr(zero, dst, uintptr(c.itemSize))
506,640✔
64
}
65

66
// Zero resets a block of storage in one buffer.
67
func (c *column) ZeroRange(start, len uint32, zero unsafe.Pointer) {
876✔
68
        size := uint32(c.itemSize)
876✔
69
        if size == 0 {
907✔
70
                return
31✔
71
        }
31✔
72
        var i uint32
845✔
73
        for i = 0; i < len; i++ {
11,934✔
74
                dst := unsafe.Add(c.pointer, (i+start)*size)
11,089✔
75
                copyPtr(zero, dst, c.itemSize)
11,089✔
76
        }
11,089✔
77
}
78

79
func (c *column) Reset(ownLen uint32, zero unsafe.Pointer) {
1,129✔
80
        if ownLen == 0 {
1,133✔
81
                return
4✔
82
        }
4✔
83
        if zero == nil {
1,364✔
84
                return
239✔
85
        }
239✔
86
        if ownLen <= 64 { // A coarse estimate where manually zeroing is faster
1,762✔
87
                c.ZeroRange(0, ownLen, zero)
876✔
88
        } else {
886✔
89
                c.data.SetZero()
10✔
90
        }
10✔
91
}
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