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

mlange-42 / ark / 13621078758

03 Mar 2025 12:48AM CUT coverage: 97.771%. Remained the same
13621078758

push

github

web-flow
Remove initial capacity from examples (#110)

5219 of 5338 relevant lines covered (97.77%)

38138.6 hits per line

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

92.19
/ecs/world.go
1
package ecs
2

3
// World is the central type holding entity and component data, as well as resources.
4
type World struct {
5
        storage   storage
6
        resources Resources
7
        locks     lock
8
}
9

10
// NewWorld creates a new [World].
11
//
12
// Accepts zero, one or two arguments.
13
// The first argument is the initial capacity of the world.
14
// The second argument is the initial capacity of relation archetypes.
15
// If only one argument is provided, it is used for both capacities.
16
// If no arguments are provided, the defaults are 1024 and 128, respectively.
17
func NewWorld(initialCapacity ...int) World {
179✔
18
        return World{
179✔
19
                storage:   newStorage(initialCapacity...),
179✔
20
                resources: newResources(),
179✔
21
                locks:     lock{},
179✔
22
        }
179✔
23
}
179✔
24

25
// NewEntity creates a new [Entity].
26
func (w *World) NewEntity() Entity {
359✔
27
        w.checkLocked()
359✔
28

359✔
29
        entity, _ := w.storage.createEntity(0)
359✔
30
        return entity
359✔
31
}
359✔
32

33
// Alive return whether the given entity is alive.
34
func (w *World) Alive(entity Entity) bool {
508,782✔
35
        return w.storage.entityPool.Alive(entity)
508,782✔
36
}
508,782✔
37

38
// RemoveEntity removes the given entity from the world.
39
func (w *World) RemoveEntity(entity Entity) {
505,069✔
40
        w.checkLocked()
505,069✔
41
        w.storage.RemoveEntity(entity)
505,069✔
42
}
505,069✔
43

44
// RemoveEntities removes all entities matching the given batch filter,
45
// running the given function on each. The function can be nil.
46
func (w *World) RemoveEntities(batch *Batch, fn func(entity Entity)) {
1✔
47
        w.checkLocked()
1✔
48

1✔
49
        tables := w.getTables(batch)
1✔
50
        cleanup := []Entity{}
1✔
51
        for _, table := range tables {
3✔
52
                len := uintptr(table.Len())
2✔
53
                var i uintptr
2✔
54
                if fn != nil {
4✔
55
                        l := w.lock()
2✔
56
                        for i = range len {
26✔
57
                                fn(table.GetEntity(i))
24✔
58
                        }
24✔
59
                        w.unlock(l)
2✔
60
                }
61
                for i = range len {
26✔
62
                        entity := table.GetEntity(i)
24✔
63
                        if w.storage.isTarget[entity.id] {
24✔
64
                                cleanup = append(cleanup, entity)
×
65
                        }
×
66
                        w.storage.entities[entity.id].table = maxTableID
24✔
67
                        w.storage.entityPool.Recycle(entity)
24✔
68
                }
69
                table.Reset()
2✔
70
        }
71

72
        for _, entity := range cleanup {
1✔
73
                w.storage.cleanupArchetypes(entity)
×
74
                w.storage.isTarget[entity.id] = false
×
75
        }
×
76
}
77

78
// IsLocked returns whether the world is locked by any queries.
79
func (w *World) IsLocked() bool {
1,013,557✔
80
        return w.locks.IsLocked()
1,013,557✔
81
}
1,013,557✔
82

83
// Resources of the world.
84
//
85
// Resources are component-like data that is not associated to an entity, but unique to the world.
86
func (w *World) Resources() *Resources {
12✔
87
        return &w.resources
12✔
88
}
12✔
89

90
// Unsafe provides access to Ark's unsafe, ID-based API.
91
// For details, see [Unsafe].
92
func (w *World) Unsafe() Unsafe {
18✔
93
        return Unsafe{
18✔
94
                world: w,
18✔
95
        }
18✔
96
}
18✔
97

98
// Reset removes all entities and resources from the world.
99
//
100
// Does NOT free reserved memory, remove archetypes, clear the registry, clear cached filters, etc.
101
// However, it removes archetypes with a relation component that is not zero.
102
//
103
// Can be used to run systematic simulations without the need to re-allocate memory for each run.
104
// Accelerates re-populating the world by a factor of 2-3.
105
func (w *World) Reset() {
1✔
106
        w.checkLocked()
1✔
107

1✔
108
        w.storage.Reset()
1✔
109
        w.locks.Reset()
1✔
110
        w.resources.reset()
1✔
111
}
1✔
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