Skip to content

Commit 306878e

Browse files
committed
Update README+example for inheritance-free change.
1 parent 312fe6d commit 306878e

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ To that end Components are typically [POD types](http://en.wikipedia.org/wiki/Pl
116116
As an example, position and direction information might be represented as:
117117

118118
```c++
119-
struct Position : entityx::Component<Position> {
119+
struct Position {
120120
Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
121121

122122
float x, y;
123123
};
124124

125-
struct Direction : entityx::Component<Direction> {
125+
struct Direction {
126126
Direction(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
127127

128128
float x, y;
@@ -208,7 +208,7 @@ As an example, we might want to implement a very basic collision system using ou
208208
First, we define the event type, which for our example is simply the two entities that collided:
209209
210210
```c++
211-
struct Collision : public Event<Collision> {
211+
struct Collision {
212212
Collision(entityx::Entity left, entityx::Entity right) : left(left), right(right) {}
213213
214214
entityx::Entity left, right;

examples/example.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Compile with:
1515
*
16-
* c++ -O3 -std=c++11 -Wall -lsfml-system -lsfml-window -lsfml-graphics -lentityx example.cc -o example
16+
* c++ -I.. -O3 -std=c++11 -Wall -lsfml-system -lsfml-window -lsfml-graphics -lentityx example.cc -o example
1717
*/
1818
#include <cmath>
1919
#include <unordered_set>
@@ -46,7 +46,7 @@ float r(int a, float b = 0) {
4646
}
4747

4848

49-
struct Body : ex::Component<Body> {
49+
struct Body {
5050
Body(const sf::Vector2f &position, const sf::Vector2f &direction, float rotationd = 0.0)
5151
: position(position), direction(direction), rotationd(rotationd) {}
5252

@@ -56,29 +56,29 @@ struct Body : ex::Component<Body> {
5656
};
5757

5858

59-
struct Renderable : ex::Component<Renderable> {
59+
struct Renderable {
6060
explicit Renderable(std::unique_ptr<sf::Shape> shape) : shape(std::move(shape)) {}
6161

6262
std::unique_ptr<sf::Shape> shape;
6363
};
6464

6565

66-
struct Fadeable : ex::Component<Fadeable> {
66+
struct Fadeable {
6767
explicit Fadeable(sf::Uint8 alpha, float duration) : alpha(alpha), d(alpha / duration) {}
6868

6969
float alpha, d;
7070
};
7171

7272

73-
struct Collideable : ex::Component<Collideable> {
73+
struct Collideable {
7474
explicit Collideable(float radius) : radius(radius) {}
7575

7676
float radius;
7777
};
7878

7979

8080
// Emitted when two entities collide.
81-
struct CollisionEvent : public ex::Event<CollisionEvent> {
81+
struct CollisionEvent {
8282
CollisionEvent(ex::Entity left, ex::Entity right) : left(left), right(right) {}
8383

8484
ex::Entity left, right;
@@ -88,7 +88,7 @@ struct CollisionEvent : public ex::Event<CollisionEvent> {
8888
// Updates a body's position and rotation.
8989
struct BodySystem : public ex::System<BodySystem> {
9090
void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
91-
Body::Handle body;
91+
ex::ComponentHandle<Body> body;
9292
for (ex::Entity entity : es.entities_with_components(body)) {
9393
body->position += body->direction * static_cast<float>(dt);
9494
body->rotation += body->rotationd * dt;
@@ -101,8 +101,8 @@ struct BodySystem : public ex::System<BodySystem> {
101101
// object has completely faded out it is destroyed.
102102
struct FadeOutSystem : public ex::System<FadeOutSystem> {
103103
void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
104-
Fadeable::Handle fade;
105-
Renderable::Handle renderable;
104+
ex::ComponentHandle<Fadeable> fade;
105+
ex::ComponentHandle<Renderable> renderable;
106106
for (ex::Entity entity : es.entities_with_components(fade, renderable)) {
107107
fade->alpha -= fade->d * dt;
108108
if (fade->alpha <= 0) {
@@ -123,7 +123,7 @@ class BounceSystem : public ex::System<BounceSystem> {
123123
explicit BounceSystem(sf::RenderTarget &target) : size(target.getSize()) {}
124124

125125
void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
126-
Body::Handle body;
126+
ex::ComponentHandle<Body> body;
127127
for (ex::Entity entity : es.entities_with_components(body)) {
128128
if (body->position.x + body->direction.x < 0 ||
129129
body->position.x + body->direction.x >= size.x)
@@ -176,8 +176,8 @@ class CollisionSystem : public ex::System<CollisionSystem> {
176176
}
177177

178178
void collect(ex::EntityManager &entities) {
179-
Body::Handle body;
180-
Collideable::Handle collideable;
179+
ex::ComponentHandle<Body> body;
180+
ex::ComponentHandle<Collideable> collideable;
181181
for (ex::Entity entity : entities.entities_with_components(body, collideable)) {
182182
unsigned int
183183
left = static_cast<int>(body->position.x - collideable->radius) / PARTITIONS,
@@ -236,9 +236,9 @@ class ExplosionSystem : public ex::System<ExplosionSystem>, public ex::Receiver<
236236
}
237237

238238
void emit_particles(ex::EntityManager &es, ex::Entity entity) {
239-
Body::Handle body = entity.component<Body>();
240-
Renderable::Handle renderable = entity.component<Renderable>();
241-
Collideable::Handle collideable = entity.component<Collideable>();
239+
ex::ComponentHandle<Body> body = entity.component<Body>();
240+
ex::ComponentHandle<Renderable> renderable = entity.component<Renderable>();
241+
ex::ComponentHandle<Collideable> collideable = entity.component<Collideable>();
242242
sf::Color colour = renderable->shape->getFillColor();
243243
colour.a = 200;
244244

@@ -287,8 +287,8 @@ class RenderSystem :public ex::System<RenderSystem> {
287287
}
288288

289289
void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
290-
Body::Handle body;
291-
Renderable::Handle renderable;
290+
ex::ComponentHandle<Body> body;
291+
ex::ComponentHandle<Renderable> renderable;
292292
for (ex::Entity entity : es.entities_with_components(body, renderable)) {
293293
renderable->shape->setPosition(body->position);
294294
renderable->shape->setRotation(body->rotation);
@@ -327,7 +327,7 @@ class Application : public ex::EntityX {
327327
ex::Entity entity = entities.create();
328328

329329
// Mark as collideable (explosion particles will not be collideable).
330-
Collideable::Handle collideable = entity.assign<Collideable>(r(10, 5));
330+
ex::ComponentHandle<Collideable> collideable = entity.assign<Collideable>(r(10, 5));
331331

332332
// "Physical" attributes.
333333
entity.assign<Body>(

0 commit comments

Comments
 (0)