Compare commits
6 commits
3b03f0af32
...
1f69ccd417
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 1f69ccd417 | ||
Bruno BELANYI | 2f2681bac8 | ||
Bruno BELANYI | 4e7651d91b | ||
Bruno BELANYI | 03c427534d | ||
Bruno BELANYI | 0522fb6b88 | ||
Bruno BELANYI | 3528bc7f37 |
|
@ -122,8 +122,6 @@ struct Asteroid;
|
||||||
struct Spaceship;
|
struct Spaceship;
|
||||||
|
|
||||||
struct SpaceObject {
|
struct SpaceObject {
|
||||||
virtual ~SpaceObject() = default;
|
|
||||||
|
|
||||||
// Only used to kick-start the double-dispatch process
|
// Only used to kick-start the double-dispatch process
|
||||||
virtual void collide_with(SpaceObject& other) = 0;
|
virtual void collide_with(SpaceObject& other) = 0;
|
||||||
|
|
||||||
|
@ -132,24 +130,32 @@ struct SpaceObject {
|
||||||
virtual void collide_with(Spaceship& other) = 0;
|
virtual void collide_with(Spaceship& other) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Asteroid : SpaceObject {
|
struct Asteroid {
|
||||||
void collide_with(SpaceObject& other) override {
|
void collide_with(SpaceObject& other) override {
|
||||||
// `*this` is an `Asteroid&` which kick-starts the double-dispatch
|
// `*this` is an `Asteroid&` which kick-starts the double-dispatch
|
||||||
other.collide_with(*this);
|
other.collide_with(*this);
|
||||||
};
|
};
|
||||||
|
|
||||||
void collide_with(Asteroid& other) override { /* Asteroid/Asteroid */ };
|
void collide_with(Asteroid& other) override {
|
||||||
void collide_with(Spaceship& other) override { /* Asteroid/Spaceship */ };
|
// Asteroid/Asteroid
|
||||||
|
};
|
||||||
|
void collide_with(Spaceship& other) override {
|
||||||
|
// Asteroid/Spaceship
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Spaceship : SpaceObject {
|
struct Spaceship {
|
||||||
void collide_with(SpaceObject& other) override {
|
void collide_with(SpaceObject& other) override {
|
||||||
// `*this` is a `Spaceship&` which kick-starts the double-dispatch
|
// `*this` is a `Spaceship&` which kick-starts the double-dispatch
|
||||||
other.collide_with(*this);
|
other.collide_with(*this);
|
||||||
};
|
};
|
||||||
|
|
||||||
void collide_with(Asteroid& other) override { /* Spaceship/Asteroid */ };
|
void collide_with(Asteroid& other) override {
|
||||||
void collide_with(Spaceship& other) override { /* Spaceship/Spaceship */ };
|
// Spaceship/Asteroid
|
||||||
|
};
|
||||||
|
void collide_with(Spaceship& other) override {
|
||||||
|
// Spaceship/Spaceship
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
void collide(SpaceObject& first, SpaceObject& second) {
|
void collide(SpaceObject& first, SpaceObject& second) {
|
||||||
|
|
Loading…
Reference in a new issue