1 | /*! |
---|
2 | * @file collision_handle.h |
---|
3 | * @brief Definition of a collision handle: used for accessing per world entity collision events and reactions |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _COLLISION_HANDLE_H |
---|
7 | #define _COLLISION_HANDLE_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "cr_engine.h" |
---|
11 | |
---|
12 | #include <vector> |
---|
13 | #include <list> |
---|
14 | |
---|
15 | |
---|
16 | class Collision; |
---|
17 | class WorldEntity; |
---|
18 | |
---|
19 | namespace CoRe |
---|
20 | { |
---|
21 | |
---|
22 | class CollisionReaction; |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | //! A class for defining collision reactions and storing events |
---|
27 | class CollisionHandle : public BaseObject |
---|
28 | { |
---|
29 | ObjectListDeclaration(CollisionHandle); |
---|
30 | public: |
---|
31 | CollisionHandle(WorldEntity* owner, CREngine::CRType type); |
---|
32 | virtual ~CollisionHandle(); |
---|
33 | |
---|
34 | void reset(); |
---|
35 | |
---|
36 | void addTarget(const ClassID& target); |
---|
37 | Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB); |
---|
38 | void registerSharedCollision(Collision* collision); |
---|
39 | void registerCollisionEvent(CollisionEvent* collisionEvent); |
---|
40 | |
---|
41 | /** @returns true if regiestered some new collision events in this tick frame */ |
---|
42 | inline bool isCollided() const { return this->bCollided; } |
---|
43 | /** @returns true if this collision handle has already been dispatched */ |
---|
44 | inline bool isDispatched() const { return this->bDispatched; } |
---|
45 | /** @returns true if this handle should be pulled also if there are no collisions */ |
---|
46 | inline bool isContinuousPoll() const { return this->bContinuousPoll; } |
---|
47 | /** @returns the type */ |
---|
48 | inline CREngine::CRType getType() const { return this->type; } |
---|
49 | |
---|
50 | void handleCollisions(); |
---|
51 | |
---|
52 | |
---|
53 | private: |
---|
54 | void flushCollisions(); |
---|
55 | bool filterCollisionEvent(CollisionEvent* collisionEvent); |
---|
56 | bool filterCollision(Collision* collision); |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | private: |
---|
61 | WorldEntity* owner; //!< the worldenity this reaction will be applied on |
---|
62 | CREngine::CRType type; //!< the reaction type |
---|
63 | |
---|
64 | bool bContinuousPoll; //!< if this is true |
---|
65 | bool bDispatched; //!< true if this handle has already been dispatched |
---|
66 | bool bStopOnFirstCollision; //!< true if the cd of this object should be terminated after one match |
---|
67 | bool bCollided; //!< true if the CollsionHandle has registered some new collisions |
---|
68 | |
---|
69 | std::vector<Collision*> collisionList; //!< a list full of collisions |
---|
70 | std::vector<ClassID> targetList; //!< a list of target classes for filtering @TODO TAKE SET INSTEAD OF VECTOR HERE |
---|
71 | |
---|
72 | CollisionReaction* collisionReaction; //!< reference to the collision reaction object |
---|
73 | |
---|
74 | }; |
---|
75 | |
---|
76 | } |
---|
77 | #endif /* _COLLISION_HANDLE_H */ |
---|