Skip to content

Commit 34067c3

Browse files
wolfenrainspydon
andauthored
Improvements (#7)
* Improved benchmarks * Made entity list unmodifiable, and finalised priority on systems * Improved assertion on getting an Component from an Entity * Updated example to showcase Oxygen's power beter * Update lib/src/entity/entity.dart Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
1 parent 8e3672d commit 34067c3

30 files changed

Lines changed: 594 additions & 108 deletions

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"console": "terminal",
9+
"name": "example",
10+
"cwd": "example",
11+
"request": "launch",
12+
"type": "dart",
13+
"args": [
14+
"--enable-asserts"
15+
]
16+
}
17+
]
18+
}

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## [next]
2+
- Made assertion for getting/checking/removing a `Component` stricter
3+
- **BREAKING**: Made the `priority` field on `System` final
4+
- **BREAKING**: Components will now be marked for removal. This fixes the concurrent modification error
25

36
## 0.1.0
47
- Stable null-safety release

analysis_options.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ linter:
1616
- non_constant_identifier_names
1717
- cancel_subscriptions
1818

19-
# analyzer:
20-
# exclude:
21-
# - path/to/excluded/files/**
19+
analyzer:
20+
exclude:
21+
- example/** # Needed for CI/CD..

benchmark/object_pool_benchmark.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,12 @@ void main() {
2727
benchmark('new ObjectPool with 100000 instances', () {
2828
TestPool(initialSize: 100000);
2929
});
30+
31+
benchmark('new ObjectPool with 0 instances that grows to 100000', () {
32+
final pool = TestPool(initialSize: 0);
33+
for (var i = 0; i < 100000; i++) {
34+
pool.acquire();
35+
}
36+
});
3037
});
3138
}

benchmark/query_benchmark.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:oxygen/oxygen.dart';
2+
import 'package:benchmark/benchmark.dart';
3+
4+
class Test100Component extends Component<void> {
5+
@override
6+
void init([void data]) {}
7+
8+
@override
9+
void reset() {}
10+
}
11+
12+
class Test50Component extends Component<void> {
13+
@override
14+
void init([void data]) {}
15+
16+
@override
17+
void reset() {}
18+
}
19+
20+
void main() {
21+
group('Query', () {
22+
group('With 100000 entities', () {
23+
World? world;
24+
25+
QueryManager? queryManager;
26+
27+
setUp(() {
28+
world = World();
29+
world!.registerComponent(() => Test100Component());
30+
world!.registerComponent(() => Test50Component());
31+
for (var i = 0; i < 100000; i++) {
32+
final entity = world!.createEntity();
33+
34+
entity.add<Test100Component, void>();
35+
if (i % 2 == 0) {
36+
entity.add<Test50Component, void>();
37+
}
38+
}
39+
queryManager = QueryManager(world!.entityManager);
40+
});
41+
42+
tearDown(() {
43+
world = null;
44+
queryManager = null;
45+
});
46+
47+
benchmark('creating a Query that matches 100% of all the entities', () {
48+
queryManager?.createQuery([Has<Test100Component>()]);
49+
});
50+
51+
benchmark('creating a Query that matches 50% of all the entities', () {
52+
queryManager?.createQuery([Has<Test50Component>()]);
53+
});
54+
});
55+
});
56+
}

doc/entity.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ You can create an entity by using the [World](./world.md):
99
final entity = world.createEntity('Optional name');
1010
```
1111

12+
## Removing an Entity
13+
```dart
14+
entity.dispose();
15+
```
16+
17+
This will mark the Entity for removal but won't be immediately disposed until the end of the last update cycle. This allows systems to react to the Entity.
18+
1219
## Adding Components
1320

1421
After you have created an entity you can easily add new components:
@@ -38,7 +45,7 @@ if (entity.has<YourComponent>()) {
3845

3946
## Removing Components
4047
```dart
41-
entity.removeComponent<YourComponent>();
48+
entity.remove<YourComponent>();
4249
```
4350

4451
This will mark the Component for removal but won't be immediately disposed until the end of the last update cycle. This allows systems to react to the data inside the Component.

example/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
# A simple Oxygen example
2+
3+
## Run
4+
5+
```
6+
dart --enable-asserts lib/main.dart
7+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'package:example/utils/color.dart';
2+
import 'package:oxygen/oxygen.dart';
3+
4+
class ColorComponent extends ValueComponent<Color> {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:oxygen/oxygen.dart';
2+
3+
enum Direction {
4+
up,
5+
down,
6+
left,
7+
right,
8+
}
9+
10+
class DirectionComponent extends ValueComponent<Direction> {}

0 commit comments

Comments
 (0)