|
| 1 | +#pragma once |
| 2 | +#pragma once |
| 3 | + |
| 4 | +#include <memory> |
| 5 | +#include <utility> |
| 6 | +#include <iosfwd> |
| 7 | + |
| 8 | +#include "util/vec2.h" |
| 9 | + |
| 10 | +class polygon; |
| 11 | +class aabb; |
| 12 | + |
| 13 | +class entity |
| 14 | +{ |
| 15 | +public: |
| 16 | + enum entity_type |
| 17 | + { |
| 18 | + AABB, |
| 19 | + Circle, |
| 20 | + Polygon |
| 21 | + }; |
| 22 | +protected: |
| 23 | + entity(entity_type type, vec2 velocity = vec2()) |
| 24 | + : type(type), velocity(velocity) {} |
| 25 | + |
| 26 | + entity(const entity& other) = default; |
| 27 | + entity& operator=(const entity& other) = default; |
| 28 | + |
| 29 | +public: |
| 30 | + entity_type type; |
| 31 | + vec2 velocity; |
| 32 | + |
| 33 | + virtual ~entity() = default; |
| 34 | + |
| 35 | + friend void swap(entity& lhs, entity& rhs) noexcept; |
| 36 | + |
| 37 | + friend std::ostream& operator<<(std::ostream& os, const entity& o); |
| 38 | + virtual std::ostream& serialize(std::ostream& os) const = 0; |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * \brief Center of mass function |
| 43 | + * \return Center of mass of entity |
| 44 | + */ |
| 45 | + virtual vec2 com() const = 0; |
| 46 | + |
| 47 | + virtual std::shared_ptr<aabb> boundingBox() const = 0; |
| 48 | + |
| 49 | + /** |
| 50 | + * \brief Get translated entity |
| 51 | + * \param delta Translation delta |
| 52 | + * \return Entity translated by delta |
| 53 | + */ |
| 54 | + virtual std::shared_ptr<entity> translate(vec2 delta) const = 0; |
| 55 | + /** |
| 56 | + * \brief Get entity with new velocity |
| 57 | + * \param newVelocity The new velocity |
| 58 | + * \return Entity with new velocity |
| 59 | + */ |
| 60 | + virtual std::shared_ptr<entity> withVelocity(vec2 newVelocity) const = 0; |
| 61 | + |
| 62 | + /** |
| 63 | + * \brief Predict time until collision between this entity and another |
| 64 | + * \param o The other entity |
| 65 | + * \return Result of the vector collision predictor (frames until collision) |
| 66 | + */ |
| 67 | + virtual float willCollideWith(const entity& o) const = 0; |
| 68 | + /** |
| 69 | + * \brief Predict time until entity leaves another's bounds |
| 70 | + * \param o The other entity |
| 71 | + * \return Result of the vector exit predictor (frames until exit) |
| 72 | + */ |
| 73 | + virtual float willExit(const entity& o) const = 0; |
| 74 | + |
| 75 | + std::shared_ptr<entity> entityAtCollision(const entity& o) const; |
| 76 | + |
| 77 | +}; |
0 commit comments