Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // See also https://pastebin.com/kLcr1sik
- #include <bn_core.h>
- #include <bn_generic_pool.h>
- struct Entity {
- int x, y;
- virtual ~Entity() = default;
- Entity(int x_, int y_) : x(x_), y(y_){};
- };
- struct CircularBullet : public Entity {
- CircularBullet(int x_, int y_) : Entity(x_, y_){};
- };
- struct SquareBullet : public Entity {
- SquareBullet(int x_, int y_) : Entity(x_, y_){};
- };
- int main() {
- bn::core::init();
- constexpr int MaxElementSize = 64; // max size of type in bytes
- constexpr int MaxSize = 4; // max elements count
- bn::generic_pool<MaxElementSize, MaxSize> pool;
- // Store childs as parent `Entity` type
- Entity* bullet1 = &pool.create<CircularBullet>(11, 11);
- Entity* bullet2 = &pool.create<SquareBullet>(22, 22);
- // Destory them. don't need to know child's concrete type.
- pool.destroy(*bullet1);
- pool.destroy(*bullet2);
- while (true)
- bn::core::update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement