]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/rigidbody.h
Convert components to buffered where appropriate
[libs/game.git] / examples / bassteroids / source / rigidbody.h
index aaffdc03c19eec0f18d131d88dd773d6aa8633d6..b75d034ab98e03b42a4beb81cb08d21532d1f4b4 100644 (file)
@@ -11,17 +11,21 @@ struct RigidBodySetup
        float moment_of_inertia = 0.5f;
 };
 
-class RigidBody: public Msp::Game::Component
+struct RigidBodyData
+{
+       Msp::LinAl::Vector<float, 2> velocity;
+       Msp::Geometry::Angle<float> angular_velocity;
+       Msp::LinAl::Vector<float, 2> force;
+       float torque = 0.0f;
+};
+
+class RigidBody: public Msp::Game::BufferedComponent<RigidBodyData>
 {
 public:
        using Setup = RigidBodySetup;
 
 private:
        const Setup &setup;
-       Msp::LinAl::Vector<float, 2> velocity;
-       Msp::Geometry::Angle<float> angular_velocity;
-       Msp::LinAl::Vector<float, 2> force;
-       float torque = 0.0f;
 
 public:
        RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
@@ -34,10 +38,10 @@ public:
        void add_force(const Msp::LinAl::Vector<float, 2> &, const Msp::LinAl::Vector<float, 2> &);
        void add_torque(float);
        void clear_forces();
-       const Msp::LinAl::Vector<float, 2> &get_velocity() const { return velocity; }
-       Msp::Geometry::Angle<float> get_angular_velocity() const { return angular_velocity; }
-       const Msp::LinAl::Vector<float, 2> &get_force() const { return force; }
-       float get_torque() const { return torque; }
+       const Msp::LinAl::Vector<float, 2> &get_velocity() const { return read().velocity; }
+       Msp::Geometry::Angle<float> get_angular_velocity() const { return read().angular_velocity; }
+       const Msp::LinAl::Vector<float, 2> &get_force() const { return read().force; }
+       float get_torque() const { return read().torque; }
 };
 
 #endif