1 | /*! |
---|
2 | * @file collision_filter.h |
---|
3 | * @brief Definition of a collision filter: checks if a certain WorldEntity is responsive for another WorldEntity |
---|
4 | * |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _COLLISION_FILTER_H |
---|
8 | #define _COLLISION_FILTER_H |
---|
9 | |
---|
10 | #include "base_object.h" |
---|
11 | #include "cr_engine.h" |
---|
12 | |
---|
13 | #include <vector> |
---|
14 | #include <list> |
---|
15 | |
---|
16 | |
---|
17 | class Collision; |
---|
18 | class WorldEntity; |
---|
19 | |
---|
20 | namespace CoRe |
---|
21 | { |
---|
22 | |
---|
23 | class CollisionReaction; |
---|
24 | |
---|
25 | |
---|
26 | /** |
---|
27 | * A class for defining collision reactions and storing events (functional object) |
---|
28 | * |
---|
29 | * This class basically checks if the owner of this filter (a WorldEntity) is responsive for a certain other WorldEntity. |
---|
30 | * The check is performed via the operator() (therefore it's a functional objects). For each CollisionReaction there is a list |
---|
31 | * of WorldEntities (their ClassIDs) to which it listens to. |
---|
32 | */ |
---|
33 | class CollisionFilter : public BaseObject |
---|
34 | { |
---|
35 | ObjectListDeclaration(CollisionFilter); |
---|
36 | |
---|
37 | |
---|
38 | typedef std::vector<ClassID>::iterator TargetIterator; |
---|
39 | typedef std::vector<ClassID>::const_iterator TargetIteratorConst; |
---|
40 | |
---|
41 | /* Constructor/Deconstructors */ |
---|
42 | public: |
---|
43 | CollisionFilter(WorldEntity* owner); |
---|
44 | virtual ~CollisionFilter(); |
---|
45 | |
---|
46 | private: |
---|
47 | CollisionFilter(const CollisionFilter& collisionFilter) {} |
---|
48 | WorldEntity* _owner; //!< the worldenity this reaction will be applied on |
---|
49 | |
---|
50 | |
---|
51 | public: |
---|
52 | /* Defines Operators */ |
---|
53 | bool operator()(const WorldEntity& entity) const; |
---|
54 | bool operator()(const WorldEntity& entity, const CREngine::ReactionType type) const; |
---|
55 | |
---|
56 | |
---|
57 | /* Collision Reaction subscription unsubscription Block */ |
---|
58 | public: |
---|
59 | void subscribeReaction(CREngine::ReactionType type, const ClassID& target1); |
---|
60 | void subscribeReaction(CREngine::ReactionType type, const ClassID& target1, const ClassID& target2); |
---|
61 | void subscribeReaction(CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3); |
---|
62 | |
---|
63 | void unsubscribeReaction(CREngine::ReactionType type); |
---|
64 | void unsubscribeReactions(); |
---|
65 | |
---|
66 | private: |
---|
67 | std::vector<ClassID> _filters[CREngine::CR_NUMBER]; //!< an array of filter targets: for each collision type a list of filter objects |
---|
68 | |
---|
69 | |
---|
70 | /* Misc State Informations */ |
---|
71 | public: |
---|
72 | /** @returns true if this handle should be pulled also if there are no collisions, can also be set with this function (reference)*/ |
---|
73 | inline bool isContinousPoll() { return this->_bContinuousPoll; } |
---|
74 | /** @returns true if this filter should be pulled always */ |
---|
75 | inline bool isContinousPoll() const { return this->_bContinuousPoll; } |
---|
76 | /** @returns true if this filter is reactive i.e. at least one filter criterion installed */ |
---|
77 | inline bool isReactive() const { return this->_bReactive; } |
---|
78 | |
---|
79 | |
---|
80 | private: |
---|
81 | /** @returns true if this @param type Collision Reaction type is a valid number */ |
---|
82 | inline bool validCRType(const CREngine::ReactionType& type) const {return (type >= 0 && type < CREngine::CR_NUMBER); } |
---|
83 | |
---|
84 | |
---|
85 | private: |
---|
86 | bool _bContinuousPoll; //!< if this is true |
---|
87 | bool _bStopOnFirstCollision; //!< true if the cd of this object should be terminated after one match |
---|
88 | bool _bReactive; //!< true if this class has at least one filter criterion == one target |
---|
89 | |
---|
90 | }; |
---|
91 | |
---|
92 | } |
---|
93 | #endif /* _COLLISION_FILTER_H */ |
---|