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

mlange-42 / ark / 13606110826

01 Mar 2025 03:14PM CUT coverage: 96.581% (-0.7%) from 97.241%
13606110826

Pull #89

github

web-flow
Merge ec05f42c9 into 22c26835c
Pull Request #89: Implement World.Reset

0 of 27 new or added lines in 3 files covered. (0.0%)

3842 of 3978 relevant lines covered (96.58%)

47559.84 hits per line

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

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

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

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

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

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

38
// IsLocked returns whether the world is locked by any queries.
39
func (w *World) IsLocked() bool {
1,014,937✔
40
        return w.locks.IsLocked()
1,014,937✔
41
}
1,014,937✔
42

43
// Resources of the world.
44
//
45
// Resources are component-like data that is not associated to an entity, but unique to the world.
46
func (w *World) Resources() *Resources {
12✔
47
        return &w.resources
12✔
48
}
12✔
49

50
// Unsafe provides access to Ark's unsafe, ID-based API.
51
func (w *World) Unsafe() Unsafe {
17✔
52
        return Unsafe{
17✔
53
                world: w,
17✔
54
        }
17✔
55
}
17✔
56

57
// Reset removes all entities and resources from the world.
58
//
59
// Does NOT free reserved memory, remove archetypes, clear the registry, clear cached filters, etc.
60
// However, it removes archetypes with a relation component that is not zero.
61
//
62
// Can be used to run systematic simulations without the need to re-allocate memory for each run.
63
// Accelerates re-populating the world by a factor of 2-3.
NEW
64
func (w *World) Reset() {
×
NEW
65
        w.checkLocked()
×
NEW
66

×
NEW
67
        w.storage.Reset()
×
NEW
68
        w.locks.Reset()
×
NEW
69
        w.resources.reset()
×
NEW
70
}
×
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