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

mlange-42 / ark / 13620752776

03 Mar 2025 12:17AM CUT coverage: 97.759%. Remained the same
13620752776

push

github

web-flow
Set up user guide (#106)

5192 of 5311 relevant lines covered (97.76%)

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

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

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

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

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

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

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

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

72
// IsLocked returns whether the world is locked by any queries.
73
func (w *World) IsLocked() bool {
1,008,681✔
74
        return w.locks.IsLocked()
1,008,681✔
75
}
1,008,681✔
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