]> git.tdb.fi Git - libs/game.git/commitdiff
Change Owned's constructor to take a pointer to the parent
authorMikko Rasa <tdb@tdb.fi>
Sun, 4 Dec 2022 21:25:40 +0000 (23:25 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 Dec 2022 21:25:40 +0000 (23:25 +0200)
This avoids some awkwardness with overload resolution

examples/bassteroids/source/asteroid.cpp
examples/bassteroids/source/bullet.cpp
examples/bassteroids/source/hittable.cpp
examples/bassteroids/source/physicalentity.cpp
examples/bassteroids/source/playfield.cpp
examples/bassteroids/source/ship.cpp
source/game/entity.cpp
source/game/owned.h

index cb7f95490df0addd479d2ae2fa38fb3ecd0e87b2..01b760539f070da0dcad1e9f8f0103962d44a6c2 100644 (file)
@@ -5,5 +5,5 @@ using namespace Msp;
 Asteroid::Asteroid(Game::Handle<Entity> p, const AsteroidSetup &s):
        Hittable(p, s.hittable, s.physical),
        setup(s),
-       mesh(*this, setup.mesh)
+       mesh(this, setup.mesh)
 { }
index e26b4089b05763443a92b694e1a74eb5cb48418a..f1bc56bad41143a2f70c2bc7840c6631a1388912 100644 (file)
@@ -4,5 +4,5 @@ using namespace Msp;
 
 Bullet::Bullet(Game::Handle<Game::Entity> p, const Setup &s, const Game::TransformValues &tv):
        Hittable(p, s.hittable, s.physical, tv),
-       mesh(*this, s.mesh)
+       mesh(this, s.mesh)
 { }
index 08355f1e39d27eaedf72e814520745a6c3d8228f..5ce5eee77ddc875eebf17906e3f012bc548cfe28 100644 (file)
@@ -6,7 +6,7 @@ Hittable::Hittable(Game::Handle<Game::Entity> p, const Setup &setup, const Physi
        PhysicalEntity(p, ps, tv)
 {
        if(!setup.immortal)
-               hits = Game::Owned<HitPoints>(*this, setup.hits);
+               hits = Game::Owned<HitPoints>(this, setup.hits);
        if(setup.damaging)
-               damage = Game::Owned<DamageSource>(*this, setup.damage);
+               damage = Game::Owned<DamageSource>(this, setup.damage);
 }
index 85ff0bdea390ad2f31a0a2ab2e1abdf291097680..83b3ee2d4f6a427bcae6eb22174c4d2d1cba9352 100644 (file)
@@ -4,8 +4,8 @@ using namespace Msp;
 
 PhysicalEntity::PhysicalEntity(Game::Handle<Game::Entity> p, const Setup &s, const Game::TransformValues &tv):
        Entity(p, tv),
-       collider(*this, s.collider)
+       collider(this, s.collider)
 {
        if(!s.fixture)
-               body = Game::Owned<RigidBody>(*this, s.body);
+               body = Game::Owned<RigidBody>(this, s.body);
 }
index 8c6cc6c14009daa9055b36d53b3fd001b78beb17..49eca3bd0f771250677ef173b03f19cc1e15b62e 100644 (file)
@@ -15,5 +15,5 @@ Playfield::Playfield(Game::Handle<Game::Entity> p, const Setup &s):
 
 Playfield::Border::Border(Playfield &f, LinAl::Vector<float, 2> p, LinAl::Vector<float, 2> s):
        setup{ .fixture=true, .body={}, .collider={ .type=ColliderType::BOX, .size=s }},
-       entity(f, setup, compose(p, 0.0f))
+       entity(&f, setup, compose(p, 0.0f))
 { }
index 8a4b71ddff90b53c0ea0352f6df26df28044d4b0..b9db83165ad59c9a1717c325b3bc7cdf394ffdc4 100644 (file)
@@ -5,5 +5,5 @@ using namespace Msp;
 Ship::Ship(Game::Handle<Game::Entity> p, const Setup &s):
        PhysicalEntity(p, s.physical),
        setup(s),
-       mesh(*this, s.mesh)
+       mesh(this, s.mesh)
 { }
index 8f56f670cb50de28c68876c64f12a9405c6c3278..3c507a312bcb3e73d5d3500c246c0ab14c01a79f 100644 (file)
@@ -13,7 +13,7 @@ Entity::Entity(Handle<Entity> p, TransformTag):
 
 Entity::Entity(Handle<Entity> p, const TransformValues &tv):
        parent(p),
-       transform(*this)
+       transform(this)
 {
        transform->set_values(tv);
 }
index d6f9f17a9ce170d7456dbafe08b3e53fe1a29418..76a75521a47a0d04b1d02d0531e065144f026796 100644 (file)
@@ -22,11 +22,7 @@ public:
        Owned(Handle<P>, Args &&...);
 
        template<typename P, typename... Args>
-       Owned(Owned<P> &p, Args &&... a): Owned(static_cast<Handle<P> &>(p), std::forward<Args>(a)...) { }
-
-       template<typename P, typename... Args>
-               requires(!std::is_const_v<P>)
-       Owned(P &parent, Args &&... args): Owned(Handle<P>::from_object(&parent), std::forward<Args>(args)...) { }
+       Owned(P *parent, Args &&... args): Owned(Handle<P>::from_object(parent), std::forward<Args>(args)...) { }
 
        Owned(Owned &&other): Handle<T>(other) { other.ptr = nullptr; }
        Owned &operator=(Owned &&other);