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

mlange-42 / ark / 13618572525

02 Mar 2025 07:23PM CUT coverage: 96.93% (-0.5%) from 97.422%
13618572525

Pull #91

github

web-flow
Merge a19dd6549 into a609eb208
Pull Request #91: Batch operations

511 of 550 new or added lines in 6 files covered. (92.91%)

14 existing lines in 1 file now uncovered.

4389 of 4528 relevant lines covered (96.93%)

40787.75 hits per line

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

59.38
/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
func NewWorld(initialCapacity uint32) World {
137✔
12
        return World{
137✔
13
                storage:   newStorage(initialCapacity),
137✔
14
                resources: newResources(),
137✔
15
                locks:     lock{},
137✔
16
        }
137✔
17
}
137✔
18

19
// NewEntity creates a new [Entity].
20
func (w *World) NewEntity() Entity {
332✔
21
        w.checkLocked()
332✔
22

332✔
23
        entity, _ := w.storage.createEntity(0)
332✔
24
        return entity
332✔
25
}
332✔
26

27
// Alive return whether the given entity is alive.
28
func (w *World) Alive(entity Entity) bool {
494,272✔
29
        return w.storage.entityPool.Alive(entity)
494,272✔
30
}
494,272✔
31

32
// RemoveEntity removes the given entity from the world.
33
func (w *World) RemoveEntity(entity Entity) {
491,714✔
34
        w.checkLocked()
491,714✔
35
        w.storage.RemoveEntity(entity)
491,714✔
36
}
491,714✔
37

38
// RemoveEntities removes all entities matching the given batch filter,
39
// running the given function on each. The function can be nil.
NEW
40
func (w *World) RemoveEntities(batch *Batch, fn func(entity Entity)) {
×
NEW
41
        w.checkLocked()
×
NEW
42

×
NEW
43
        tables := w.getTables(batch)
×
NEW
44
        cleanup := []Entity{}
×
NEW
45
        for _, table := range tables {
×
NEW
46
                len := uintptr(table.Len())
×
NEW
47
                var i uintptr
×
NEW
48
                if fn != nil {
×
NEW
49
                        l := w.lock()
×
NEW
50
                        for i = range len {
×
NEW
51
                                fn(table.GetEntity(i))
×
NEW
52
                        }
×
NEW
53
                        w.unlock(l)
×
54
                }
NEW
55
                for i = range len {
×
NEW
56
                        entity := table.GetEntity(i)
×
NEW
57
                        if w.storage.isTarget[entity.id] {
×
NEW
58
                                cleanup = append(cleanup, entity)
×
NEW
59
                        }
×
NEW
60
                        w.storage.entities[entity.id].table = maxTableID
×
NEW
61
                        w.storage.entityPool.Recycle(entity)
×
62
                }
NEW
63
                table.Reset()
×
64
        }
65

NEW
66
        for _, entity := range cleanup {
×
NEW
67
                w.storage.cleanupArchetypes(entity)
×
NEW
68
                w.storage.isTarget[entity.id] = false
×
NEW
69
        }
×
70
}
71

72
// IsLocked returns whether the world is locked by any queries.
73
func (w *World) IsLocked() bool {
986,105✔
74
        return w.locks.IsLocked()
986,105✔
75
}
986,105✔
76

77
// Resources of the world.
78
//
79
// Resources are component-like data that is not associated to an entity, but unique to the world.
80
func (w *World) Resources() *Resources {
12✔
81
        return &w.resources
12✔
82
}
12✔
83

84
// Unsafe provides access to Ark's unsafe, ID-based API.
85
// For details, see [Unsafe].
86
func (w *World) Unsafe() Unsafe {
18✔
87
        return Unsafe{
18✔
88
                world: w,
18✔
89
        }
18✔
90
}
18✔
91

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

1✔
102
        w.storage.Reset()
1✔
103
        w.locks.Reset()
1✔
104
        w.resources.reset()
1✔
105
}
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