Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CCollisionDetector.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2013 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef CCOLLISION_DETECTOR_H
22 #define CCOLLISION_DETECTOR_H
23 
24 #include "CUpdater.h"
25 #include "CPhysicalObject.h"
26 #include "ICollisionListener.h"
27 
28 #include "../CD_LIB/CDGrid.h"
29 
30 namespace OpenSkyNet {
31  namespace Core {
34  public:
35  struct ColInfo : public Updater::UpdateInfo {
36  bool _doCalculate, _isInGrid, _doSweepTests, _doAllowPostUpdateCollisions;
39  std::set<Object*> _colliders, _prevColliders;
40 
41  ColInfo(Updater::OBJECT_PRIORITY prio_=Updater::OBJ_DISABLED, bool isOneShot_=false) : Updater::UpdateInfo(prio_,isOneShot_),
42  _doCalculate(false), _isInGrid(false), _doSweepTests(false), _doAllowPostUpdateCollisions(false),
43  _secsLeftToCalc(0.f), _numCollisions(0) {}
44  };
45  protected:
47  std::list<CollisionListener*> _registeredListeners;
49 
53 
54  inline bool doCollide(Object* collidee_, Object* collider_);
55  inline bool doCollideWhenSwept(Object* collidee_, Object* collider_, float dt_, CD::HitInfo& hitInfo_);
56 
57  virtual bool addObject(Object* obj_, Updater::OBJECT_PRIORITY prio_, bool isOneShot_);
58  virtual bool removeObject(Object* obj_);
59  public:
60  CollisionDetector() : Updater(Updater::COLLISION_DETECTOR, "COLLISION_DETECTOR", Updater::UPD_3, 0.0f),
61  _grid(32,32,32,0), _maxCollisionsPerVolume(3) {
64  if (!CD::g_initialGrid) CD::Grid::init(32,32,32,0);
65  }
66 
68 
69  virtual bool update(float dt_);
70 
71  virtual bool setPriority(Object* obj_, OBJECT_PRIORITY prio_);
72 
74 
75  virtual bool enableSweepTests(Object* obj_);
76  virtual bool disableSweepTests(Object* obj_);
77 
78  virtual bool allowPostUpdateCollisions(Object* obj_);
79  virtual bool disallowPostUpdateCollisions(Object* obj_);
81 
83  virtual void setCDGrid(const Math::Point<>* corners_, std::set<CD::Volume*>& obstacles_);
84 
85  inline const CD::Grid* getGrid() const { return &_grid; }
86 
87  inline void registerCollisionListener(CollisionListener* listener_) { _registeredListeners.push_back(listener_); }
88  inline void unregisterCollisionListener(CollisionListener* listener_) { _registeredListeners.remove(listener_); }
89 
90  virtual bool getClosestRayIntersection(const Math::Point<>& rayOrigin_, const Math::Point<>& rayDir_,
91  Utils::uint colGroup_, CD::HitInfo& hitInfo_) const;
92  };
93  }
94 }
95 
96 #endif //CCOLLISION_DETECTOR_H
const CD::Grid * getGrid() const
Definition: CCollisionDetector.h:85
Definition: CDVolume.h:36
std::map< const Math::Point< int > *, BinOccupiersList > BinOccupiersMap
Definition: CDGrid.h:143
Grid * g_initialGrid
Definition: CDGrid.cpp:18
CD::Grid::BinOccupiersMap _nonCollidingOccupiers
Definition: CCollisionDetector.h:51
float _secsLeftToCalc
Definition: CCollisionDetector.h:37
std::map< CD::Volume *, OccupiedBinsList > OccupiedBinsMap
Definition: CDGrid.h:144
Definition: CCollisionDetector.h:35
ColInfo(Updater::OBJECT_PRIORITY prio_=Updater::OBJ_DISABLED, bool isOneShot_=false)
Definition: CCollisionDetector.h:41
Utils::uint _maxCollisionsPerVolume
Definition: CCollisionDetector.h:48
void unregisterCollisionListener(CollisionListener *listener_)
Definition: CCollisionDetector.h:88
Definition: CUpdater.h:40
static void shutDown()
Definition: CDGrid.cpp:85
std::set< Object * > _prevColliders
Definition: CCollisionDetector.h:39
virtual ~CollisionDetector()
Definition: CCollisionDetector.h:67
static void init(Utils::uint initGlobalXDivs_, Utils::uint initGlobalYDivs_, Utils::uint initGlobalZDivs_, Utils::uint maxGlobalSubdivs_)
Definition: CDGrid.cpp:70
unsigned int uint
Definition: UTypes.h:39
Definition: CCollisionDetector.h:33
OBJECT_PRIORITY
Definition: CUpdater.h:49
#define CORE_DLL
Definition: CCoreDLL.h:57
Definition: MPoint.h:33
Definition: IObject.h:36
Utils::uint _numCollisions
Definition: CCollisionDetector.h:38
CD::Grid _grid
Definition: CCollisionDetector.h:46
CD::Grid::OccupiedBinsMap _nonCollidingOccupiedBins
Definition: CCollisionDetector.h:52
Definition: ICollisionListener.h:34
std::list< CollisionListener * > _registeredListeners
Definition: CCollisionDetector.h:47
bool _isInGrid
Definition: CCollisionDetector.h:36
Definition: CDGrid.h:92
Definition: CUpdater.h:54
void registerCollisionListener(CollisionListener *listener_)
Definition: CCollisionDetector.h:87
CollisionDetector()
Definition: CCollisionDetector.h:60