]> git.tdb.fi Git - libs/game.git/commitdiff
Cosmetic tweaks
authorMikko Rasa <tdb@tdb.fi>
Sat, 12 Nov 2022 15:40:28 +0000 (17:40 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 12 Nov 2022 15:40:39 +0000 (17:40 +0200)
examples/bassteroids/source/gamecontroller.cpp
examples/bassteroids/source/physics.cpp
source/game/eventbus.h
source/game/eventsource.h

index 05586b0a4618732b4a418cbaa8164c9dca6aaa16..eae5e2d3cf27e8560c187c38cb227cd773f24d2c 100644 (file)
@@ -8,8 +8,8 @@ using namespace Msp;
 
 GameController::GameController(Game::Stage &s):
        System(s),
-       asteroid_setup{ .physical = { .body = { .mass = 200 }, .collider = { .type = ColliderType::CIRCLE, .radius = 3.0f } },
-               .mesh = { .object_name = "Asteroid 1.object" }}
+       asteroid_setup{ .physical={ .body={ .mass=200 }, .collider={ .type=ColliderType::CIRCLE, .radius=3.0f } },
+               .mesh={ .object_name="Asteroid 1.object" }}
 { }
 
 void GameController::tick(Time::TimeDelta)
index 429715aa99b5d365e26f436e170bd468119f6403..89feeed47eebb6a5beb6f4b5ba1c4eb09e2db364 100644 (file)
@@ -193,9 +193,8 @@ void Physics::collide_circle_circle(unsigned i, unsigned j)
        if(d_sq<r_sum*r_sum)
        {
                Collision &collision = get_collision(i, j);
-               float d = sqrt(d_sq);
                collision.normal = normalize(delta);
-               collision.depth = r1+r2-d;
+               collision.depth = r1+r2-sqrt(d_sq);
                collision.point = pos1-collision.normal*(r1-collision.depth/2);
                if(collision.body1!=i)
                        collision.normal = -collision.normal;
index c78cb0d6562bfec062317b6915510daa08916f56..7da047ed1851b76b8bd79b6d903aa8b20c64b47e 100644 (file)
@@ -52,12 +52,12 @@ public:
 
 private:
        template<typename T>
-       EventDispatcher<T> &get_emitter();
+       EventDispatcher<T> &get_dispatcher();
 
 public:
        template<typename T>
        void add_observer(EventObserver &obs, std::function<void(const T &)> cb)
-       { get_emitter<T>().add_observer(&obs, std::move(cb)); }
+       { get_dispatcher<T>().add_observer(&obs, std::move(cb)); }
 
        void replace_observer(EventObserver &, EventObserver &);
        void remove_observer(EventObserver &);
@@ -83,7 +83,7 @@ inline unsigned EventBus::get_event_id()
 }
 
 template<typename T>
-inline EventDispatcher<T> &EventBus::get_emitter()
+inline EventDispatcher<T> &EventBus::get_dispatcher()
 {
        unsigned id = get_event_id<T>();
        if(dispatchers.size()<=id)
index 5dacbeeed71603ec0418f3245a7fc82c39e449c5..0856e08c452a7abd48b263db1bcb54092e4c75bb 100644 (file)
@@ -44,6 +44,14 @@ public:
 };
 
 
+template<typename... E>
+template<typename T>
+inline void EventSource<E...>::cancel_observation()
+{
+       for(const auto &h: static_cast<EventDispatcher<T> &>(*this).handlers)
+               h.observer->remove_source(*this);
+}
+
 template<typename... E>
 template<typename T, typename... Args>
 inline void EventSource<E...>::emit(Args &&... args) const
@@ -53,14 +61,6 @@ inline void EventSource<E...>::emit(Args &&... args) const
        bus.dispatch(event);
 }
 
-template<typename... E>
-template<typename T>
-inline void EventSource<E...>::cancel_observation()
-{
-       for(const auto &h: static_cast<EventDispatcher<T> &>(*this).handlers)
-               h.observer->remove_source(*this);
-}
-
 } // namespace Msp::Game
 
 #endif