GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Player.hpp
Go to the documentation of this file.
1 #ifndef RADIX_COMPONENT_PLAYER_HPP
2 #define RADIX_COMPONENT_PLAYER_HPP
3 
4 #include <memory>
5 #include <functional>
6 
7 #include <bullet/btBulletDynamicsCommon.h>
8 #include <bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h>
9 #include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h>
10 #include <bullet/BulletDynamics/Character/btKinematicCharacterController.h>
11 
12 #include <radix/PlayerTask.hpp>
13 #include <radix/BaseGame.hpp>
17 #include <radix/Entity.hpp>
18 #include <radix/EntityManager.hpp>
20 
21 namespace radix {
22 
23 class Player : public Component {
24 public:
25  std::map<int, PlayerTask*> tasks;
26  std::shared_ptr<btConvexShape> shape;
27  btPairCachingGhostObject *obj;
30 
33  float speed;
34  float stepCounter;
35 
36  Player(Entity&);
37  ~Player();
38 
39  const char* getName() const {
40  return "Player";
41  }
42 
43  TypeId getTypeId() const {
44  return Component::getTypeId<std::remove_reference<decltype(*this)>::type>();
45  }
46 
47  void serialize(serine::Archiver&);
48 
49  template<typename T>
50  inline T& addTask() {
51  static_assert(std::is_base_of<PlayerTask, T>::value, "T must be a PlayerTask");
52  T *result = new T;
53  if (!tasks.empty()) {
54  int id = tasks.rbegin()->first + 1;
55  result->id = id;
56  tasks.insert(std::make_pair(id, result));
57  } else {
58  result->id = 0;
59  tasks.insert(std::make_pair(0, result));
60  }
61  return *result;
62  }
63  void removeTask(int id);
64 
67 };
68 
69 class ContactPlayerCallback : public btCollisionWorld::ContactResultCallback {
70 public:
71  ContactPlayerCallback(BaseGame* game) : btCollisionWorld::ContactResultCallback(), game(game) { };
72 
73  BaseGame* game;
74 
75  virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,
76  int partId0, int index0,const btCollisionObjectWrapper* colObj1Wrap, int partId1, int index1) {
77  Entity* playerEntity = (Entity*) colObj0Wrap->getCollisionObject()->getUserPointer();
78  Entity* triggerEntity = (Entity*) colObj1Wrap->getCollisionObject()->getUserPointer();
79 
80  if (triggerEntity->hasComponent<Trigger>()) {
81  Trigger &trigger = triggerEntity->getComponent<Trigger>();
82  trigger.onUpdate(game);
83 
84  if (playerEntity->hasComponent<Player>()) {
85  Player &player = playerEntity->getComponent<Player>();
86  player.trigger = &trigger;
87  }
88  }
89  return 0;
90  };
91 };
92 
93 } /* namespace radix */
94 
95 #endif /* RADIX_COMPONENT_PLAYER_HPP */
Trigger * trigger
Definition: Player.hpp:29
float stepCounter
Definition: Player.hpp:34
KinematicCharacterController * controller
Definition: Player.hpp:28
~Player()
Definition: Player.cpp:30
T & addTask()
Definition: Player.hpp:50
Definition: GameController.hpp:7
ContactPlayerCallback(BaseGame *game)
Definition: Player.hpp:71
bool hasComponent() const
Definition: Entity.hpp:134
ECS entity, Component container It is created like this:
Definition: Entity.hpp:23
void onUpdate(BaseGame *game)
Definition: Trigger.hpp:54
T & getComponent() const
Definition: Entity.hpp:140
Definition: Vector4f.hpp:117
TypeId getTypeId() const
Definition: Player.hpp:43
Quaternion getHeadOrientation() const
Definition: Player.cpp:52
Quaternion getBaseHeadOrientation() const
Definition: Player.cpp:48
bool noclip
Definition: Player.hpp:32
void serialize(serine::Archiver &)
Definition: Player.cpp:39
bool flying
Definition: Player.hpp:32
Base class to create entity components.
Definition: Component.hpp:25
btPairCachingGhostObject * obj
Definition: Player.hpp:27
Vector3f headAngle
Definition: Player.hpp:31
std::map< int, PlayerTask * > tasks
Definition: Player.hpp:25
Definition: Player.hpp:23
void removeTask(int id)
Definition: Player.cpp:43
BaseGame * game
Definition: Player.hpp:71
ComponentTypeId TypeId
Definition: Component.hpp:35
std::shared_ptr< btConvexShape > shape
Definition: Player.hpp:26
Player(Entity &)
Definition: Player.cpp:7
float speed
Definition: Player.hpp:33
const char * getName() const
Definition: Player.hpp:39
virtual btScalar addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
Definition: Player.hpp:75
bool frozen
Definition: Player.hpp:32
Definition: BaseGame.hpp:22
Definition: Player.hpp:69
KinematicCharacterController is an object that supports a sliding motion in a world.
Definition: KinematicCharacterController.hpp:46
Vector3f velocity
Definition: Player.hpp:31
3-dimensional float-based vector/point storage and manipulation struct
Definition: Vector3f.hpp:27
Definition: Trigger.hpp:16