Skip to content

Commit

Permalink
switching from entity to int
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskaselow committed Aug 28, 2019
1 parent 8c8bc14 commit 47aba59
Show file tree
Hide file tree
Showing 36 changed files with 539 additions and 942 deletions.
27 changes: 14 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
# Changelog
##0.8.0 (Dart 2.0+ required)
## 0.8.0 (Dart 2.0+ required)
### Breaking API Changes
* removed deprecated code
* replaced `Entity` with `int`, methods previously on `Entity` need to be called on `World`, with the `int` value of the entity as the first parameter
* removed `world.processEntityChanges`, it's now done by default after every system
* `Aspect` no longer uses static methods, uses named constructors instead
(migration: replace `Aspect.getAspectF` with `Aspect.f`)
* methods in `Aspect` no longer return the aspect, use cascading operator to chain calls
* improved type safety for `world.getManager` and `world.getSystem`, no longer takes a `Type` as parameter and uses
generic methods instead (e.g. `world.getManager<TagManager>()` instead of `world.getManager(TagManager)`)
* removed `Type` parameter in constructor of `Mapper`, change code from `Mapper<Position>(Position, world)` to `Mapper<Position>(world)`
* removed `uniqueId` from `Entity`

### Enhancements
* `world.destroy()` for cleaning up `EntitySystem`s and `Manager`s

### Internal
* existing entities are processed first, addition of new entities is processed last, makes more sense now that the
processing is done after every system

##0.7.3
## 0.7.3
### Bugfixes
* adding an entity to a dirty EntityBag could lead to an inconsistency between the bitset and the list of entities

##0.7.2
## 0.7.2
### Bugfixes
* removing an entity multiple times caused it to be added to the entity pool multiple times

##0.7.1
## 0.7.1
### Internal
* upgraded dependencies

##0.7.0
## 0.7.0
### Breaking API Changes
* renamed `Poolable` to `Pooled`
* renamed `ComponentPoolable` to `PooledComponent`
Expand All @@ -48,12 +49,12 @@ processing is done after every system
### Internal
* upgraded dependencies

##0.6.0
## 0.6.0
### API Changes
* `Bag` is `Iterable`
* removed `ReadOnlyBag`, when upgrading to 0.6.0 replace every occurence of `ReadOnlyBag` with `Iterable`

##0.5.2
## 0.5.2
### Enhancements
* injection works for `Manager`s
* `initialize()` in the `Manager` is no longer abstract (same as in `EntitySystem`)
Expand All @@ -64,29 +65,29 @@ processing is done after every system
* added getter for the `World` in `Manager`
* the uniqueId of an `Entity` was always 0, not very unique

##0.5.1
## 0.5.1
### Internal
* added version constraint for release of Dart

##0.5.0
## 0.5.0
### Enhancements
* more injection, less boilerplate (when using dartemis_mirrors)
* Instances of `ComponentMapper` no longer need to be created in the `initialize`-method of a system, they will be injected
* `Manager`s and `EntitySystem`s no longer need to be requested from the `World` in the `initialize`-method of a system, they will be injected

##0.4.2
## 0.4.2
### Bugfixes
* `EntityManager.isEnabled()` no longer fails if the bag of disabled entities is smaller than the id of the checked entity

### Enhancements
* added getters for current `time` and `frame` to `World`

##0.4.1
## 0.4.1
### Bugfixes
* `World.deleteAllEntites()` did not work if there was already a deleted entity
* writing to the `Bag` by index doesn't make it smaller anymore

##0.4.0
## 0.4.0
### API Changes
* swapped parameters of `Tagmanager.register`
* replaced `ImmutableBag` with `ReadOnlyBag`, added getter for `ReadOnlyBag` to `Bag`
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ Getting started
4. Create entities, add components to them and finally add those entities to the world. Entities with different components will be processed by different systems:

```dart
Entity entity = world.createEntity()
..addComponent(Position(0, 0))
..addComponent(Velocity(1, 1))
..addToWorld();
final player = world.createEntity();
world
..addComponent(player, Position(0, 0))
..addComponent(player, Velocity(1, 1));
```
A `Component` is a pretty simple structure and should not contain any logic:

Expand Down Expand Up @@ -97,7 +97,7 @@ Getting started
velocityMapper = Mapper<Velocity>(world);
}
void processEntity(Entity entity) {
void processEntity(int entity) {
Position position = positionMapper[entity];
Velocity vel = velocityMapper[entity];
position.x += vel.x;
Expand Down
43 changes: 20 additions & 23 deletions example/web/darteroids/gamelogic_systems.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MovementSystem extends EntityProcessingSystem {
}

@override
void processEntity(Entity entity) {
void processEntity(int entity) {
final pos = positionMapper[entity];
final vel = velocityMapper[entity];

Expand All @@ -40,7 +40,7 @@ class BulletSpawningSystem extends EntityProcessingSystem {
}

@override
void processEntity(Entity entity) {
void processEntity(int entity) {
final cannon = cannonMapper[entity];

if (cannon.canShoot) {
Expand All @@ -54,19 +54,17 @@ class BulletSpawningSystem extends EntityProcessingSystem {

void fireBullet(Position shooterPos, Velocity shooterVel, Cannon cannon) {
cannon.cooldown = 1000;
final bullet = world.createEntity()
..addComponent(Position(shooterPos.x, shooterPos.y));
final bullet = world.createEntity();
addComponent(bullet, Position(shooterPos.x, shooterPos.y));
final dirX = cannon.targetX - shooterPos.x;
final dirY = cannon.targetY - shooterPos.y;
final distance = sqrt(pow(dirX, 2) + pow(dirY, 2));
final velX = shooterVel.x + bulletSpeed * (dirX / distance);
final velY = shooterVel.y + bulletSpeed * (dirY / distance);
bullet
..addComponent(Velocity(velX, velY))
..addComponent(CircularBody.down(2, 'red'))
..addComponent(Decay(5000))
..addComponent(AsteroidDestroyer())
..addToWorld();
addComponent(bullet, Velocity(velX, velY));
addComponent(bullet, CircularBody.down(2, 'red'));
addComponent(bullet, Decay(5000));
addComponent(bullet, AsteroidDestroyer());
}
}

Expand All @@ -81,11 +79,11 @@ class DecaySystem extends EntityProcessingSystem {
}

@override
void processEntity(Entity entity) {
void processEntity(int entity) {
final decay = decayMapper[entity];

if (decay.timer < 0) {
entity.deleteFromWorld();
world.deleteEntity(entity);
} else {
decay.timer -= world.delta;
}
Expand All @@ -109,7 +107,7 @@ class AsteroidDestructionSystem extends EntityProcessingSystem {
}

@override
void processEntity(Entity entity) {
void processEntity(int entity) {
final destroyerPos = positionMapper[entity];

for (final asteroid in groupManager.getEntities(groupAsteroids)) {
Expand All @@ -118,8 +116,8 @@ class AsteroidDestructionSystem extends EntityProcessingSystem {

if (doCirclesCollide(destroyerPos.x, destroyerPos.y, 0, asteroidPos.x,
asteroidPos.y, asteroidBody.radius)) {
asteroid.deleteFromWorld();
entity.deleteFromWorld();
deleteFromWorld(asteroid);
deleteFromWorld(entity);
if (asteroidBody.radius > 10) {
createNewAsteroids(asteroidPos, asteroidBody);
createNewAsteroids(asteroidPos, asteroidBody);
Expand All @@ -129,16 +127,15 @@ class AsteroidDestructionSystem extends EntityProcessingSystem {
}

void createNewAsteroids(Position asteroidPos, CircularBody asteroidBody) {
final asteroid = world.createEntity()
..addComponent(Position(asteroidPos.x, asteroidPos.y));
final asteroid = world.createEntity();
addComponent(asteroid, Position(asteroidPos.x, asteroidPos.y));
final vx = generateRandomVelocity();
final vy = generateRandomVelocity();
asteroid.addComponent(Velocity(vx, vy));
addComponent(asteroid, Velocity(vx, vy));
final radius = asteroidBody.radius / sqrtOf2;
asteroid
..addComponent(CircularBody.down(radius, asteroidColor))
..addComponent(PlayerDestroyer())
..addToWorld();

addComponent(asteroid, CircularBody.down(radius, asteroidColor));
addComponent(asteroid, PlayerDestroyer());
groupManager.add(asteroid, groupAsteroids);
}
}
Expand All @@ -161,7 +158,7 @@ class PlayerCollisionDetectionSystem extends EntitySystem {
}

@override
void processEntities(Iterable<Entity> entities) {
void processEntities(Iterable<int> entities) {
final player = tagManager.getEntity(tagPlayer);
final playerPos = positionMapper[player];
final playerStatus = statusMapper[player];
Expand Down
2 changes: 1 addition & 1 deletion example/web/darteroids/input_systems.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PlayerControlSystem extends IntervalEntitySystem {
}

@override
void processEntities(Iterable<Entity> entities) {
void processEntities(Iterable<int> entities) {
final player = tagManager.getEntity(tagPlayer);
final velocity = velocityMapper[player];
final cannon = cannonMapper[player];
Expand Down
2 changes: 1 addition & 1 deletion example/web/darteroids/render_systems.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CircleRenderingSystem extends EntityProcessingSystem {
}

@override
void processEntity(Entity entity) {
void processEntity(int entity) {
final pos = positionMapper[entity];
final body = bodyMapper[entity];
final status = statusMapper.getSafe(entity);
Expand Down
31 changes: 16 additions & 15 deletions example/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class Darteroids {
void start() {
world = World();

final player = world.createEntity()
..addComponent(Position(maxWidth ~/ 2, maxHeight ~/ 2))
..addComponent(Velocity())
..addComponent(CircularBody.down(20, playerColor))
..addComponent(Cannon())
..addComponent(Status(lifes: 3, invisiblityTimer: 5000))
..addToWorld();
final player = world.createEntity();
world
..addComponent(player, Position(maxWidth ~/ 2, maxHeight ~/ 2))
..addComponent(player, Velocity())
..addComponent(player, CircularBody.down(20, playerColor))
..addComponent(player, Cannon())
..addComponent(player, Status(lifes: 3, invisiblityTimer: 5000));

final tagManager = TagManager()..register(player, tagPlayer);
world.addManager(tagManager);
Expand All @@ -75,17 +75,18 @@ class Darteroids {

void addAsteroids(GroupManager groupManager) {
for (var i = 0; i < 10; i++) {
final asteroid = world.createEntity()
..addComponent(Position(
maxWidth * random.nextDouble(), maxHeight * random.nextDouble()));
final asteroid = world.createEntity();
world.addComponent(
asteroid,
Position(
maxWidth * random.nextDouble(), maxHeight * random.nextDouble()));
final vx = generateRandomVelocity();
final vy = generateRandomVelocity();
asteroid
..addComponent(Velocity(vx, vy))
..addComponent(
world
..addComponent(asteroid, Velocity(vx, vy))
..addComponent(asteroid,
CircularBody.down(10 + 20 * random.nextDouble(), asteroidColor))
..addComponent(PlayerDestroyer())
..addToWorld();
..addComponent(asteroid, PlayerDestroyer());
groupManager.add(asteroid, groupAsteroids);
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/dartemis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ part 'src/core/component_type_manager.dart';

part 'src/core/aspect.dart';

part 'src/core/entity.dart';
part 'src/core/entity_manager.dart';
part 'src/core/entity_observer.dart';

part 'src/core/entity_system.dart';
part 'src/core/systems/entity_processing_system.dart';
part 'src/core/systems/delayed_entity_processing_system.dart';
part 'src/core/systems/interval_entity_system.dart';
part 'src/core/systems/interval_entity_processing_system.dart';
part 'src/core/systems/void_entity_system.dart';
Expand Down

0 comments on commit 47aba59

Please sign in to comment.