collision.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // collision.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 02/18/97 JMI Started.
  23. //
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Collision functions for postal.
  27. //
  28. //////////////////////////////////////////////////////////////////////////////
  29. #ifndef COLLISION_H
  30. #define COLLISION_H
  31. //////////////////////////////////////////////////////////////////////////////
  32. // C Headers -- Must be included before RSPiX.h b/c RSPiX utilizes SHMalloc.
  33. //////////////////////////////////////////////////////////////////////////////
  34. ///////////////////////////////////////////////////////////////////////////////
  35. // RSPiX Headers.
  36. // If PATHS_IN_INCLUDES macro is defined, we can utilize relative
  37. // paths to a header file. In this case we generally go off of our
  38. // RSPiX root directory. System.h MUST be included before this macro
  39. // is evaluated. System.h is the header that, based on the current
  40. // platform (or more so in this case on the compiler), defines
  41. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  42. // instead.
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #include "System.h"
  45. #ifdef PATHS_IN_INCLUDES
  46. #else
  47. #endif
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // Postal includes.
  50. ///////////////////////////////////////////////////////////////////////////////
  51. #include "thing.h"
  52. //////////////////////////////////////////////////////////////////////////////
  53. // Macros.
  54. //////////////////////////////////////////////////////////////////////////////
  55. //////////////////////////////////////////////////////////////////////////////
  56. // Typedefs.
  57. //////////////////////////////////////////////////////////////////////////////
  58. //////////////////////////////////////////////////////////////////////////////
  59. // Protos.
  60. //////////////////////////////////////////////////////////////////////////////
  61. //////////////////////////////////////////////////////////////////////////////
  62. // Inlines/Templates.
  63. //////////////////////////////////////////////////////////////////////////////
  64. ////////////////////////////////////////////////////////////////////////////////
  65. // Gets then next thing from the specified list that collides with the specified
  66. // region.
  67. ////////////////////////////////////////////////////////////////////////////////
  68. template <class Region> // Must be a type supported by CThing::IsColliding(...)!
  69. bool GetNextCollision( // Returns true if a collision is found, false otherwise.
  70. CThing::Things* pthings, // In: List of CThings to search within.
  71. Region* pregion, // In: Region OR shape to collide with.
  72. CThing** ppthing) // In: CThing to start with or NULL to start at beginning.
  73. // Out: CThing collided with or NULL.
  74. {
  75. bool bCollision = false; // Assume no collision.
  76. CThing::Things::iterator i = pthings->begin();
  77. // If a beginning was specified . . .
  78. if (*ppthing != NULL)
  79. {
  80. while (i != pthings->end() && *i != *ppthing)
  81. {
  82. i++;
  83. }
  84. if (i == pthings->end())
  85. {
  86. TRACE("GetNextCollision(): Specified CThing is not in specified list.\n");
  87. }
  88. else
  89. {
  90. // Move to next after *ppthing.
  91. i++;
  92. }
  93. }
  94. while (i != pthings->end())
  95. {
  96. // If there is a collision . . .
  97. if ((*i)->IsColliding(pregion) == true)
  98. {
  99. // Remember who it was with.
  100. *ppthing = *i;
  101. // Set return value.
  102. bCollision = true;
  103. // Exit loop.
  104. break;
  105. }
  106. // Next.
  107. i++;
  108. }
  109. return bCollision;
  110. }
  111. #endif // COLLISION_H
  112. //////////////////////////////////////////////////////////////////////////////
  113. // EOF
  114. //////////////////////////////////////////////////////////////////////////////