Physical2D.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <PlayRho/PlayRho.hpp>
4 #include "../Entity2D/Entity2D.hpp"
5 
6 namespace comp
7 {
8 
9 class Physical2D_World;
10 
16 {
17 public:
19 
20  void Register( Physical2D_World * world, playrho::d2::BodyConf const & conf );
21  void Unregister();
22 
24  bool registered();
26 
27  //-------------------------------------------
31 
35  playrho::d2::Body * body;
36 
37 private:
38  iv::ClientMarker * cm;
39  Physical2D_World * _world;
40 };
41 
46 class Physical2D_Listener : public iv::GenericListener< Physical2D_Listener >
47 {
48 public:
51 
52  // PhysicalBody2D_Listener
53  virtual void PhysicalBody2D_BeginContact( Physical2D * a, Physical2D * b ) = 0;
54  virtual void PhysicalBody2D_EndContact( Physical2D * a, Physical2D * b ) = 0;
55 };
56 
60 class Physical2D_World : public iv::World< Physical2D >, public iv::GenericListener_Index< Physical2D_Listener >, protected playrho::d2::ContactListener
61 {
62 public:
64 
66 
67  void Step( float timeStep );
68 
72  playrho::d2::Body * CreateBody( Physical2D * component, playrho::d2::BodyConf const & conf );
73  void DestroyBody( playrho::d2::Body * );
74 
75 protected:
76  // iv::World< Entity2D >
77  virtual void Component_Registered( Physical2D * component ) override;
78  virtual void Component_Unregistered( Physical2D * component ) override;
79 
80  // playrho::d2::ContactListener
81  virtual void BeginContact( playrho::d2::Contact & contact ) override;
82  virtual void EndContact( playrho::d2::Contact & contact ) override;
83 
84 private:
85  playrho::d2::World world;
86 };
87 
88 }