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

mlange-42 / ark / 13595480058

28 Feb 2025 07:53PM CUT coverage: 96.821% (-0.06%) from 96.882%
13595480058

Pull #81

github

web-flow
Merge 310e5e240 into 9b17c8beb
Pull Request #81: Unsafe API

19 of 22 new or added lines in 2 files covered. (86.36%)

39 existing lines in 3 files now uncovered.

3594 of 3712 relevant lines covered (96.82%)

49525.14 hits per line

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

83.33
/ecs/unsafe.go
1
package ecs
2

3
import "unsafe"
4

5
// Unsafe provides access to Ark's unsafe ID-based API.
6
// Get an instance via [World.Unsafe].
7
type Unsafe struct {
8
        world *World
9
}
10

11
// NewEntity creates a new entity with the given components.
12
func (u Unsafe) NewEntity(ids ...ID) Entity {
2✔
13
        return u.world.newEntityWith(ids, nil, nil)
2✔
14
}
2✔
15

16
// NewEntityRel creates a new entity with the given components and relation targets.
NEW
17
func (u Unsafe) NewEntityRel(ids []ID, relations ...RelationID) Entity {
×
NEW
18
        return u.world.newEntityWith(ids, nil, relations)
×
NEW
19
}
×
20

21
// Get returns a pointer to the given component of an [Entity].
22
//
23
// ⚠️ Important: The obtained pointer should not be stored persistently!
24
//
25
// Panics if the entity does not have the given component.
26
// Panics when called for a removed (and potentially recycled) entity.
27
func (u Unsafe) Get(entity Entity, comp ID) unsafe.Pointer {
1✔
28
        return u.world.get(entity, comp)
1✔
29
}
1✔
30

31
// GetUnchecked returns a pointer to the given component of an [Entity].
32
// In contrast to [Unsafe.Get], it does not check whether the entity is alive.
33
//
34
// ⚠️ Important: The obtained pointer should not be stored persistently!
35
//
36
// Panics if the entity does not have the given component.
37
func (u Unsafe) GetUnchecked(entity Entity, comp ID) unsafe.Pointer {
1✔
38
        return u.world.getUnchecked(entity, comp)
1✔
39
}
1✔
40

41
// Has returns whether an [Entity] has the given component.
42
//
43
// Panics when called for a removed (and potentially recycled) entity.
44
func (u Unsafe) Has(entity Entity, comp ID) bool {
4✔
45
        return u.world.has(entity, comp)
4✔
46
}
4✔
47

48
// HasUnchecked returns whether an [Entity] has the given component.
49
// In contrast to [Unsafe.Has], it does not check whether the entity is alive.
50
//
51
// Panics when called for a removed (and potentially recycled) entity.
52
func (u Unsafe) HasUnchecked(entity Entity, comp ID) bool {
2✔
53
        return u.world.hasUnchecked(entity, comp)
2✔
54
}
2✔
55

56
// TODO: Unsafe.NewEntity
57
// TODO: Unsafe.Add
58
// TODO: Unsafe.Remove
59
// TODO: Unsafe.Exchange
60
// TODO: Unsafe.GetRelation
61
// TODO: Unsafe.SetRelation
62
// TODO: Queries
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