broad_phase_basic.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*************************************************************************/
  2. /* broad_phase_basic.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef BROAD_PHASE_BASIC_H
  30. #define BROAD_PHASE_BASIC_H
  31. #include "broad_phase_sw.h"
  32. #include "map.h"
  33. class BroadPhaseBasic : public BroadPhaseSW {
  34. struct Element {
  35. CollisionObjectSW *owner;
  36. bool _static;
  37. AABB aabb;
  38. int subindex;
  39. };
  40. Map<ID,Element> element_map;
  41. ID current;
  42. struct PairKey {
  43. union {
  44. struct {
  45. ID a;
  46. ID b;
  47. };
  48. uint64_t key;
  49. };
  50. _FORCE_INLINE_ bool operator<(const PairKey& p_key) const {
  51. return key < p_key.key;
  52. }
  53. PairKey() { key=0; }
  54. PairKey(ID p_a, ID p_b) { if (p_a>p_b) { a=p_b; b=p_a; } else { a=p_a; b=p_b; }}
  55. };
  56. Map<PairKey,void*> pair_map;
  57. PairCallback pair_callback;
  58. void *pair_userdata;
  59. UnpairCallback unpair_callback;
  60. void *unpair_userdata;
  61. public:
  62. // 0 is an invalid ID
  63. virtual ID create(CollisionObjectSW *p_object_, int p_subindex=0);
  64. virtual void move(ID p_id, const AABB& p_aabb);
  65. virtual void set_static(ID p_id, bool p_static);
  66. virtual void remove(ID p_id);
  67. virtual CollisionObjectSW *get_object(ID p_id) const;
  68. virtual bool is_static(ID p_id) const;
  69. virtual int get_subindex(ID p_id) const;
  70. virtual int cull_segment(const Vector3& p_from, const Vector3& p_to,CollisionObjectSW** p_results,int p_max_results,int *p_result_indices=NULL);
  71. virtual int cull_aabb(const AABB& p_aabb,CollisionObjectSW** p_results,int p_max_results,int *p_result_indices=NULL);
  72. virtual void set_pair_callback(PairCallback p_pair_callback,void *p_userdata);
  73. virtual void set_unpair_callback(UnpairCallback p_unpair_callback,void *p_userdata);
  74. virtual void update();
  75. static BroadPhaseSW *_create();
  76. BroadPhaseBasic();
  77. };
  78. #endif // BROAD_PHASE_BASIC_H